mirror of
https://github.com/thegatesbrowser/thegates.git
synced 2025-08-23 08:17:34 -04:00
search suggestions
This commit is contained in:
parent
88a2992f84
commit
9c637bbe9e
5 changed files with 110 additions and 21 deletions
|
@ -4,9 +4,14 @@ extends VBoxContainer
|
|||
@export var api: ApiSettings
|
||||
@export var result_scene: PackedScene
|
||||
|
||||
@export var header: SearchResultsHeader
|
||||
@export var suggestions_root: Control
|
||||
@export var suggestion_scene: PackedScene
|
||||
|
||||
var result_str: String = "{}"
|
||||
var suggestions_str: String = "{}"
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
search(gate_events.current_search_query)
|
||||
|
||||
|
@ -21,6 +26,9 @@ func search(query: String) -> void:
|
|||
suggestions()
|
||||
return
|
||||
|
||||
header.set_search_header()
|
||||
suggestions_root.visible = false
|
||||
|
||||
for gate in gates:
|
||||
Debug.logr(gate["url"])
|
||||
var result: SearchResult = result_scene.instantiate()
|
||||
|
@ -46,9 +54,14 @@ func suggestions() -> void:
|
|||
if suggs == null or suggs.is_empty():
|
||||
Debug.logclr("No suggestions found", Color.YELLOW)
|
||||
return
|
||||
|
||||
|
||||
for sugg in suggs:
|
||||
Debug.logr(sugg)
|
||||
var suggestion: Suggestion = suggestion_scene.instantiate()
|
||||
suggestion.fill(sugg)
|
||||
suggestions_root.add_child(suggestion)
|
||||
|
||||
header.set_suggestion_header()
|
||||
|
||||
|
||||
func suggestions_request() -> void:
|
||||
|
|
|
@ -1,8 +1,14 @@
|
|||
extends Label
|
||||
class_name SearchResultsHeader
|
||||
|
||||
@export var gate_events: GateEvents
|
||||
@export var header: String
|
||||
@export var search_header: String
|
||||
@export var suggestion_header: String
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
text = "%s \"%s\"" % [header, gate_events.current_search_query]
|
||||
func set_search_header() -> void:
|
||||
text = "%s \"%s\"" % [search_header, gate_events.current_search_query]
|
||||
|
||||
|
||||
func set_suggestion_header() -> void:
|
||||
text = suggestion_header
|
||||
|
|
16
app/scripts/ui/search/suggestion.gd
Normal file
16
app/scripts/ui/search/suggestion.gd
Normal file
|
@ -0,0 +1,16 @@
|
|||
extends Button
|
||||
class_name Suggestion
|
||||
|
||||
@export var gate_events: GateEvents
|
||||
@export var prompt: String
|
||||
|
||||
|
||||
func fill(_prompt: String) -> void:
|
||||
prompt = _prompt
|
||||
text = _prompt
|
||||
|
||||
|
||||
func _on_button_pressed() -> void:
|
||||
if prompt.is_empty(): return
|
||||
|
||||
gate_events.search_emit(prompt)
|
Loading…
Add table
Add a link
Reference in a new issue