Very basic details (name and hours) work now

This commit is contained in:
2022-12-19 21:08:20 -08:00
parent 976562e8bd
commit 546dbb8911
7 changed files with 95 additions and 21 deletions

View File

@@ -1,7 +1,9 @@
require "json"
require "time"
require "../templates/businessrow.cr"
require "../api/yelp.cr"
require "../utils/utils.cr"
module Wince
@@main_window_id = 0_u32
@@ -36,10 +38,9 @@ module Wince
response["businesses"].as_a.map do |business|
name = business["name"].as_s? || ""
rating = business["rating"].as_f32
open = business["is_closed"].as_bool
distance = business["distance"].as_f32
BusinessRow.new(name, rating, open, distance)
BusinessRow.new(name, rating, distance)
end
end
@@ -81,8 +82,30 @@ module Wince
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
response = Yelp.get_business_info(id)
if response.status_code != 200
puts "api call error"
puts response.body
return #TODO: show a toast here
end
response_json = JSON.parse(response.body)
SEE_DETAILS_TEXT.visible = false
DETAILS_TITLE.text = response_json["name"].as_s? || ""
is_open = response_json["hours"][0]["is_open_now"].as_bool? || false
if is_open
DETAILS_IS_OPEN.markup = "<span foreground=\"green\">open</span>"
else
DETAILS_IS_OPEN.markup = "<span foreground=\"red\">closed</span>"
end
DETAILS_CURRENT_HOURS.text = Utils.hours_for_day(response_json["hours"], Time.local.day_of_week)
DETAILS_BOX.visible = true
end
APP.activate_signal.connect(->activate(Adw::Application))