From 5cbdddf519a2d7bb409509d1c960f0233676ee98 Mon Sep 17 00:00:00 2001 From: Nordup Date: Tue, 19 Aug 2025 14:43:26 +0700 Subject: [PATCH] suggestions in search request --- .../components/search/no_results_note.tscn | 4 +-- app/scripts/resources/api_settings.gd | 3 -- app/scripts/ui/search/search_results.gd | 32 ++++++------------- 3 files changed, 12 insertions(+), 27 deletions(-) diff --git a/app/scenes/components/search/no_results_note.tscn b/app/scenes/components/search/no_results_note.tscn index 56df434..fa05b5d 100644 --- a/app/scenes/components/search/no_results_note.tscn +++ b/app/scenes/components/search/no_results_note.tscn @@ -20,9 +20,9 @@ offset_bottom = 100.0 self_modulate = Color(1, 1, 1, 0) custom_minimum_size = Vector2(850, 100) layout_mode = 1 -offset_top = 25.0 +offset_top = 50.0 offset_right = 850.0 -offset_bottom = 125.0 +offset_bottom = 150.0 theme_override_styles/panel = ExtResource("2_cxiqp") [node name="RichTextLabel" type="RichTextLabel" parent="Panel"] diff --git a/app/scripts/resources/api_settings.gd b/app/scripts/resources/api_settings.gd index 87fb497..37d0862 100644 --- a/app/scripts/resources/api_settings.gd +++ b/app/scripts/resources/api_settings.gd @@ -31,8 +31,5 @@ var search: String : var prompt: String : get: return url + "/api/prompt?query=" -var search_suggestions: String : - get: return url + "/api/search_suggestions" - var send_logs: String : get: return url + "/api/send_logs?url=" diff --git a/app/scripts/ui/search/search_results.gd b/app/scripts/ui/search/search_results.gd index 3ee84a8..552cf1f 100644 --- a/app/scripts/ui/search/search_results.gd +++ b/app/scripts/ui/search/search_results.gd @@ -10,7 +10,6 @@ extends VBoxContainer @export var no_results_note: PackedScene var result_str: String = "{}" -var suggestions_str: String = "{}" var cancel_callbacks: Array = [] @@ -22,10 +21,13 @@ func search(query: String) -> void: Debug.logclr("======== " + query + " ========", Color.LIGHT_SEA_GREEN) await search_request(query) - var gates = JSON.parse_string(result_str) + var result = JSON.parse_string(result_str) + var gates = JSON.parse_string(result["gates"]) + if gates == null or gates.is_empty(): - Debug.logclr("No gates found, request suggestions", Color.YELLOW) - suggestions() + Debug.logclr("No gates found, showing suggestions", Color.YELLOW) + var suggs = JSON.parse_string(result["suggestions"]) + suggestions(suggs) return header.set_search_header() @@ -33,9 +35,9 @@ func search(query: String) -> void: for gate in gates: Debug.logr(gate["url"]) - var result: SearchResult = result_scene.instantiate() - result.fill(gate) - add_child(result) + var search_result: SearchResult = result_scene.instantiate() + search_result.fill(gate) + add_child(search_result) func search_request(query: String) -> void: @@ -49,10 +51,7 @@ func search_request(query: String) -> void: if err != HTTPRequest.RESULT_SUCCESS: Debug.logclr("Cannot send request search", Color.RED) -func suggestions() -> void: - await suggestions_request() - - var suggs = JSON.parse_string(suggestions_str) +func suggestions(suggs: Array) -> void: if suggs == null or suggs.is_empty(): Debug.logclr("No suggestions found", Color.YELLOW) return @@ -69,17 +68,6 @@ func suggestions() -> void: add_child(note) -func suggestions_request() -> void: - var url = api.search_suggestions - var callback = func(_result, code, _headers, body): - if code == 200: - suggestions_str = body.get_string_from_utf8() - else: Debug.logclr("Request search suggestions failed. Code " + str(code), Color.RED) - - var err = await Backend.request(url, callback, {}, HTTPClient.METHOD_GET, cancel_callbacks) - if err != HTTPRequest.RESULT_SUCCESS: Debug.logclr("Cannot send request search suggestions", Color.RED) - - func _exit_tree() -> void: for callback in cancel_callbacks: if callback.is_valid(): callback.call()