mirror of
https://github.com/thegatesbrowser/thegates.git
synced 2025-08-22 23:17:26 -04:00
suggestions in search request
This commit is contained in:
parent
80f2c6c6c3
commit
5cbdddf519
3 changed files with 12 additions and 27 deletions
|
@ -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"]
|
||||
|
|
|
@ -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="
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue