mirror of
https://github.com/thegatesbrowser/thegates.git
synced 2025-08-24 02:17:27 -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)
|
self_modulate = Color(1, 1, 1, 0)
|
||||||
custom_minimum_size = Vector2(850, 100)
|
custom_minimum_size = Vector2(850, 100)
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
offset_top = 25.0
|
offset_top = 50.0
|
||||||
offset_right = 850.0
|
offset_right = 850.0
|
||||||
offset_bottom = 125.0
|
offset_bottom = 150.0
|
||||||
theme_override_styles/panel = ExtResource("2_cxiqp")
|
theme_override_styles/panel = ExtResource("2_cxiqp")
|
||||||
|
|
||||||
[node name="RichTextLabel" type="RichTextLabel" parent="Panel"]
|
[node name="RichTextLabel" type="RichTextLabel" parent="Panel"]
|
||||||
|
|
|
@ -31,8 +31,5 @@ var search: String :
|
||||||
var prompt: String :
|
var prompt: String :
|
||||||
get: return url + "/api/prompt?query="
|
get: return url + "/api/prompt?query="
|
||||||
|
|
||||||
var search_suggestions: String :
|
|
||||||
get: return url + "/api/search_suggestions"
|
|
||||||
|
|
||||||
var send_logs: String :
|
var send_logs: String :
|
||||||
get: return url + "/api/send_logs?url="
|
get: return url + "/api/send_logs?url="
|
||||||
|
|
|
@ -10,7 +10,6 @@ extends VBoxContainer
|
||||||
@export var no_results_note: PackedScene
|
@export var no_results_note: PackedScene
|
||||||
|
|
||||||
var result_str: String = "{}"
|
var result_str: String = "{}"
|
||||||
var suggestions_str: String = "{}"
|
|
||||||
var cancel_callbacks: Array = []
|
var cancel_callbacks: Array = []
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,10 +21,13 @@ func search(query: String) -> void:
|
||||||
Debug.logclr("======== " + query + " ========", Color.LIGHT_SEA_GREEN)
|
Debug.logclr("======== " + query + " ========", Color.LIGHT_SEA_GREEN)
|
||||||
await search_request(query)
|
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():
|
if gates == null or gates.is_empty():
|
||||||
Debug.logclr("No gates found, request suggestions", Color.YELLOW)
|
Debug.logclr("No gates found, showing suggestions", Color.YELLOW)
|
||||||
suggestions()
|
var suggs = JSON.parse_string(result["suggestions"])
|
||||||
|
suggestions(suggs)
|
||||||
return
|
return
|
||||||
|
|
||||||
header.set_search_header()
|
header.set_search_header()
|
||||||
|
@ -33,9 +35,9 @@ func search(query: String) -> void:
|
||||||
|
|
||||||
for gate in gates:
|
for gate in gates:
|
||||||
Debug.logr(gate["url"])
|
Debug.logr(gate["url"])
|
||||||
var result: SearchResult = result_scene.instantiate()
|
var search_result: SearchResult = result_scene.instantiate()
|
||||||
result.fill(gate)
|
search_result.fill(gate)
|
||||||
add_child(result)
|
add_child(search_result)
|
||||||
|
|
||||||
|
|
||||||
func search_request(query: String) -> void:
|
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)
|
if err != HTTPRequest.RESULT_SUCCESS: Debug.logclr("Cannot send request search", Color.RED)
|
||||||
|
|
||||||
|
|
||||||
func suggestions() -> void:
|
func suggestions(suggs: Array) -> void:
|
||||||
await suggestions_request()
|
|
||||||
|
|
||||||
var suggs = JSON.parse_string(suggestions_str)
|
|
||||||
if suggs == null or suggs.is_empty():
|
if suggs == null or suggs.is_empty():
|
||||||
Debug.logclr("No suggestions found", Color.YELLOW)
|
Debug.logclr("No suggestions found", Color.YELLOW)
|
||||||
return
|
return
|
||||||
|
@ -69,17 +68,6 @@ func suggestions() -> void:
|
||||||
add_child(note)
|
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:
|
func _exit_tree() -> void:
|
||||||
for callback in cancel_callbacks:
|
for callback in cancel_callbacks:
|
||||||
if callback.is_valid(): callback.call()
|
if callback.is_valid(): callback.call()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue