Starting on the details page
This commit is contained in:
@@ -3,7 +3,7 @@ using Adw 1;
|
||||
|
||||
Adw.ApplicationWindow mainWindow {
|
||||
title: "Wince";
|
||||
default-width: 600;
|
||||
default-width: 700;
|
||||
default-height: 500;
|
||||
|
||||
Gtk.Box {
|
||||
@@ -32,19 +32,30 @@ Adw.ApplicationWindow mainWindow {
|
||||
}
|
||||
}
|
||||
|
||||
Gtk.ScrolledWindow scrollWindow {
|
||||
vexpand: true;
|
||||
visible: false;
|
||||
|
||||
Gtk.ListBox searchResults {}
|
||||
}
|
||||
|
||||
Gtk.Label poweredByText {
|
||||
halign: center;
|
||||
valign: center;
|
||||
vexpand: true;
|
||||
use-markup: true;
|
||||
label: "<span foreground=\"gray\" style=\"italic\">Wince is powered by Yelp</span>";
|
||||
label: "Wince is powered by Yelp";
|
||||
}
|
||||
|
||||
Adw.Leaflet leaflet {
|
||||
visible: false;
|
||||
|
||||
Gtk.ScrolledWindow scrollWindow {
|
||||
vexpand: true;
|
||||
width-request: 300;
|
||||
|
||||
Gtk.ListBox searchResults {}
|
||||
}
|
||||
|
||||
Gtk.Box {
|
||||
Gtk.Label seeDetailsText {
|
||||
label: "Select a result to see details";
|
||||
hexpand: true;
|
||||
halign: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,19 @@ module Wince::Yelp
|
||||
headers = HTTP::Headers{ "Authorization" => "Bearer " + @@token }
|
||||
response = HTTP::Client.get(uri, headers)
|
||||
end
|
||||
|
||||
def get_business_info(id : String)
|
||||
|
||||
uri = URI.new(
|
||||
scheme: "https",
|
||||
host: "api.yelp.com",
|
||||
path: "/v3/businesses/#{id}",
|
||||
query: params
|
||||
)
|
||||
headers = HTTP::Headers{ "Authorization" => "Bearer " + @@token }
|
||||
response = HTTP::Client.get(uri, headers)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
#response = Wince::Yelp.search_businesses("miss saigon", "94610")
|
||||
|
||||
@@ -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
|
||||
@@ -12,6 +12,8 @@ module Wince
|
||||
BUSINESS_LIST = Gtk::ListBox.cast(B_UI["searchResults"])
|
||||
POWERD_BY_TEXT = Gtk::Label.cast(B_UI["poweredByText"])
|
||||
SCROLL_VIEW = Gtk::ScrolledWindow.cast(B_UI["scrollWindow"])
|
||||
LEAFLET = Adw::Leaflet.cast(B_UI["leaflet"])
|
||||
SEE_DETAILS_TEXT = Gtk::Label.cast(B_UI["seeDetailsText"])
|
||||
|
||||
APP = Adw::Application.new("dev.wince", Gio::ApplicationFlags::None)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user