booru: instant feedback on enter

This commit is contained in:
end-4
2025-05-04 00:11:36 +02:00
parent dc0a15e63b
commit 41e82f0693
4 changed files with 17 additions and 22 deletions
@@ -18,7 +18,7 @@ Item {
id: root
property var panelWindow
property var inputField: tagInputField
readonly property list<var> 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://", "")
+1 -1
View File
@@ -9,7 +9,7 @@ Singleton {
readonly property list<DesktopEntry> list: Array.from(DesktopEntries.applications.values)
.sort((a, b) => a.name.localeCompare(b.name))
readonly property list<var> preppedNames: list.map(a => ({
readonly property var preppedNames: list.map(a => ({
name: Fuzzy.prepare(`${a.name} `),
entry: a
}))
+13 -15
View File
@@ -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<var> 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) {
@@ -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<var> tags
property var tags
property var page
property list<var> images
property var images
property string message
}