From 41e82f06937a6b358d11e0f73eefdf5eb0a2ef39 Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Sun, 4 May 2025 00:11:36 +0200 Subject: [PATCH] booru: instant feedback on enter --- .../quickshell/modules/sidebarLeft/Anime.qml | 2 +- .config/quickshell/services/AppSearch.qml | 2 +- .config/quickshell/services/Booru.qml | 28 +++++++++---------- .../quickshell/services/BooruResponseData.qml | 7 ++--- 4 files changed, 17 insertions(+), 22 deletions(-) diff --git a/.config/quickshell/modules/sidebarLeft/Anime.qml b/.config/quickshell/modules/sidebarLeft/Anime.qml index 06fbeacbd..f126dd3b6 100644 --- a/.config/quickshell/modules/sidebarLeft/Anime.qml +++ b/.config/quickshell/modules/sidebarLeft/Anime.qml @@ -18,7 +18,7 @@ Item { id: root property var panelWindow property var inputField: tagInputField - readonly property list responses: Booru.responses + readonly property var responses: Booru.responses property string previewDownloadPath: `${StandardPaths.standardLocations(StandardPaths.CacheLocation)[0]}/media/waifus`.replace("file://", "") property string downloadPath: (StandardPaths.standardLocations(StandardPaths.PicturesLocation)[0] + "/homework").replace("file://", "") property string nsfwPath: (StandardPaths.standardLocations(StandardPaths.PicturesLocation)[0] + "/homework/🌶️").replace("file://", "") diff --git a/.config/quickshell/services/AppSearch.qml b/.config/quickshell/services/AppSearch.qml index 41f447d26..1ecaa886c 100644 --- a/.config/quickshell/services/AppSearch.qml +++ b/.config/quickshell/services/AppSearch.qml @@ -9,7 +9,7 @@ Singleton { readonly property list list: Array.from(DesktopEntries.applications.values) .sort((a, b) => a.name.localeCompare(b.name)) - readonly property list preppedNames: list.map(a => ({ + readonly property var preppedNames: list.map(a => ({ name: Fuzzy.prepare(`${a.name} `), entry: a })) diff --git a/.config/quickshell/services/Booru.qml b/.config/quickshell/services/Booru.qml index c87c0f86d..3762d6793 100644 --- a/.config/quickshell/services/Booru.qml +++ b/.config/quickshell/services/Booru.qml @@ -21,7 +21,7 @@ Singleton { } property string failMessage: qsTr("That didn't work. Tips:\n- Check your tags and NSFW settings\n- If you don't have a tag in mind, type a page number") - property list responses: [] + property var responses: [] property var getWorkingImageSource: (url) => { if (url.includes('pximg.net')) { return `https://www.pixiv.net/en/artworks/${url.substring(url.lastIndexOf('/') + 1).replace(/_p\d+\.(png|jpg|jpeg|gif)$/, '')}`; @@ -308,6 +308,15 @@ Singleton { var url = constructRequestUrl(tags, nsfw, limit, page) // console.log("[Booru] Making request to " + url) + const newResponse = root.booruResponseDataComponent.createObject(null, { + "provider": currentProvider, + "tags": tags, + "page": page, + "images": [], + "message": "" + }) + root.responses = [...root.responses, newResponse] + var xhr = new XMLHttpRequest() xhr.open("GET", url) xhr.onreadystatechange = function() { @@ -317,23 +326,12 @@ Singleton { var response = JSON.parse(xhr.responseText) response = providers[currentProvider].mapFunc(response) // console.log("[Booru] Mapped response: " + JSON.stringify(response)) - root.responses = [...root.responses, root.booruResponseDataComponent.createObject(null, { - "provider": currentProvider, - "tags": tags, - "page": page, - "images": response, - "message": response.length > 0 ? "" : root.failMessage - })] + newResponse.images = response + newResponse.message = response.length > 0 ? "" : root.failMessage } catch (e) { console.log("[Booru] Failed to parse response: " + e) - root.responses = [...root.responses, root.responseDataComponent.createObject(null, { - "provider": currentProvider, - "tags": tags, - "page": page, - "images": [], - "message": root.failMessage - })] + newResponse.message = root.failMessage } } else if (xhr.readyState === XMLHttpRequest.DONE) { diff --git a/.config/quickshell/services/BooruResponseData.qml b/.config/quickshell/services/BooruResponseData.qml index 775da2568..f0409a1ba 100644 --- a/.config/quickshell/services/BooruResponseData.qml +++ b/.config/quickshell/services/BooruResponseData.qml @@ -1,13 +1,10 @@ import "root:/modules/common" -import Quickshell; -import Quickshell.Io; -import Qt.labs.platform import QtQuick; QtObject { property string provider - property list tags + property var tags property var page - property list images + property var images property string message }