Starting on the details page

This commit is contained in:
2022-12-19 00:55:39 -08:00
parent 9aa5741e1a
commit 976562e8bd
4 changed files with 59 additions and 16 deletions

View File

@@ -6,6 +6,7 @@ require "../api/yelp.cr"
module Wince
@@main_window_id = 0_u32
@@business_rows = [] of BusinessRow
@@business_ids = [] of String
def activate(app : Adw::Application)
main_window = APP.window_by_id(@@main_window_id)
@@ -20,13 +21,19 @@ module Wince
handle_search
end
BUSINESS_LIST.row_selected_signal.connect do
handle_business_select
end
window.present
end
def yelp_response_to_business_rows(response : String)
businesses = JSON.parse(response)["businesses"].as_a
def yelp_response_to_business_ids(response : JSON::Any)
response["businesses"].as_a.map { |b| b["id"].as_s }
end
businesses.map do |business|
def yelp_response_to_business_rows(response : JSON::Any)
response["businesses"].as_a.map do |business|
name = business["name"].as_s? || ""
rating = business["rating"].as_f32
open = business["is_closed"].as_bool
@@ -45,12 +52,12 @@ module Wince
location = LOCATION_ENTRY.buffer.text
if search.blank? || location.blank?
SCROLL_VIEW.visible = false
LEAFLET.visible = false
POWERD_BY_TEXT.visible = true
return
end
SCROLL_VIEW.visible = true
LEAFLET.visible = true
POWERD_BY_TEXT.visible = false
response = Yelp.search_businesses(search, location)
@@ -61,13 +68,23 @@ module Wince
return #TODO: show a toast here
end
response_json = JSON.parse(response.body)
clear_business_rows()
@@business_rows = yelp_response_to_business_rows(response.body)
@@business_ids = yelp_response_to_business_ids(response_json)
@@business_rows = yelp_response_to_business_rows(response_json)
@@business_rows.each do |row|
BUSINESS_LIST.append(row)
end
end
def handle_business_select
index = @@business_rows.index(BUSINESS_LIST.selected_row) || 0
id = @@business_ids[index]
puts id
# TODO call yelp and show the results
end
APP.activate_signal.connect(->activate(Adw::Application))
exit(APP.run(ARGV))
end