Skip to content

Commit

Permalink
Make somethings into resources again
Browse files Browse the repository at this point in the history
  • Loading branch information
akarras committed Jan 25, 2024
1 parent 3eca533 commit 6e3e904
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ pub fn LiveSaleTicker() -> impl IntoView {
if let Some(sale) =
hw_1.map(|h| ultros_api_types::world_helper::AnySelector::World(h.id))
{
log::info!("live sale");
live_sales(sales, sale).await.unwrap();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use ultros_api_types::SaleHistory;
use ultros_charts::draw_sale_history_scatter_plot;
use ultros_charts::ChartOptions;

use crate::components::skeleton::BoxSkeleton;
use crate::{components::toggle::Toggle, global_state::LocalWorldData};

#[component]
Expand Down Expand Up @@ -38,6 +39,9 @@ pub fn PriceHistoryChart(sales: MaybeSignal<Vec<SaleHistory>>) -> impl IntoView
}
});
view! {
<div class="min-w-[750px] min-h-[440px]" class:hidden=move || !hidden()>
<BoxSkeleton />
</div>
<div class="flex flex-col max-h-[480px] mx-auto" class:hidden=hidden>
<canvas width="750" height="440" style="width: 750px; height: 440px" _ref=canvas/>
<Toggle checked=filter_outliers set_checked=set_filter_outliers
Expand Down
27 changes: 18 additions & 9 deletions ultros-frontend/ultros-app/src/routes/analyzer.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::{
api::{get_cheapest_listings, get_recent_sales_for_world},
components::{
ad::Ad, clipboard::*, gil::*, item_icon::*, meta::*, query_button::QueryButton, tooltip::*,
virtual_scroller::*, world_picker::*,
ad::Ad, clipboard::*, gil::*, item_icon::*, meta::*, query_button::QueryButton,
skeleton::BoxSkeleton, tooltip::*, virtual_scroller::*, world_picker::*,
},
error::AppError,
global_state::LocalWorldData,
Expand Down Expand Up @@ -404,14 +404,14 @@ fn AnalyzerTable(
pub fn AnalyzerWorldView() -> impl IntoView {
let params = use_params_map();
let world = create_memo(move |_| params.with(|p| p.get("world").cloned()).unwrap_or_default());
let sales = create_local_resource(
let sales = create_resource(
move || params.with(|p| p.get("world").cloned()),
move |world| async move {
get_recent_sales_for_world(&world.ok_or(AppError::ParamMissing)?).await
},
);

let world_cheapest_listings = create_local_resource(
let world_cheapest_listings = create_resource(
move || params.with(|p| p.get("world").cloned()),
move |world| async move {
let world = world.ok_or(AppError::ParamMissing)?;
Expand All @@ -423,7 +423,7 @@ pub fn AnalyzerWorldView() -> impl IntoView {
.0
.unwrap();
let worlds_value = store_value(worlds);
let global_cheapest_listings = create_local_resource(
let global_cheapest_listings = create_resource(
move || params.with(|p| p.get("world").cloned()),
move |world| async move {
let worlds = worlds_value();
Expand Down Expand Up @@ -460,6 +460,8 @@ pub fn AnalyzerWorldView() -> impl IntoView {
</div>
<Ad class="h-32" />
</div>
<div class="min-h-screen w-full">
<Suspense fallback=BoxSkeleton>
{move || {
let world_cheapest = world_cheapest_listings.get();
let sales = sales.get();
Expand All @@ -469,10 +471,17 @@ pub fn AnalyzerWorldView() -> impl IntoView {
.and_then(|w| w.ok())
.and_then(|r| sales.and_then(|s| s.ok())
.and_then(|s| global_cheapest_listings.and_then(|g| g.ok()).map(|g| (r, s, g))));
values.map(|(world_cheapest_listings, sales, global_cheapest_listings)| {
view!{<AnalyzerTable sales global_cheapest_listings world_cheapest_listings worlds world=world.into() />
} }
)}}
match values {
Some((world_cheapest_listings, sales, global_cheapest_listings)) => {view!{<AnalyzerTable sales global_cheapest_listings world_cheapest_listings worlds world=world.into() />}.into_view()},
None => {view!{
<div class="h3">
"Failed to load analyzer - try again in 30 seconds"
</div>
}.into_view()}
}
}}
</Suspense>
</div>
</div>
</div>}.into_view()
}
Expand Down
10 changes: 5 additions & 5 deletions ultros-frontend/ultros-app/src/routes/item_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,21 @@ fn ListingsContent(item_id: Memo<i32>, world: Memo<String>) -> impl IntoView {
view! {
<div>
<Transition fallback=move || view!{
<div class="h-[35em] grow">
<div class="h-[35em] grow w-screen md:w-[780px]">
<BoxSkeleton />
</div>
}>
{move || {
let sales = create_memo(move |_| listing_resource.with(|l| l.as_ref().and_then(|l| l.as_ref().map(|l| l.sales.clone()).ok())).unwrap_or_default());
view!{ <div class="content-well max-h-[35em] overflow-y-auto">
view!{ <div class="content-well max-h-[35em] overflow-y-auto min-w-[750px] min-h-[440px]">
<PriceHistoryChart sales=MaybeSignal::from(sales) />
</div>}
}}
</Transition>
</div>
<div>
<Transition fallback=move || view !{
<div class="h-[35em] grow">
<div class="h-[35em] grow w-screen md:w-[780px]">
<BoxSkeleton />
</div>
}>
Expand All @@ -135,7 +135,7 @@ fn ListingsContent(item_id: Memo<i32>, world: Memo<String>) -> impl IntoView {
</div>
<div>
<Transition fallback=move || view !{
<div class="h-[35em] grow">
<div class="h-[35em] grow w-screen md:w-[780px]">
<BoxSkeleton />
</div>
}>
Expand All @@ -150,7 +150,7 @@ fn ListingsContent(item_id: Memo<i32>, world: Memo<String>) -> impl IntoView {
</div>
<div>
<Transition fallback=move || view !{
<div class="h-[35em] min-w-[400px] grow">
<div class="h-[35em] grow w-screen md:w-[780px]">
<BoxSkeleton />
</div>
}>
Expand Down
7 changes: 1 addition & 6 deletions ultros-frontend/ultros-app/src/ws/live_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ pub(crate) async fn live_sales(
signal: RwSignal<VecDeque<SaleView>>,
price_zone: AnySelector,
) -> Result<(), AppError> {
use log::info;

log::info!("CONNECTING TO SALES!");
// TODO - better way to switch to wss
#[cfg(debug_assertions)]
let url = "ws://localhost:8080/api/v1/realtime/events";
Expand All @@ -39,7 +36,6 @@ pub(crate) async fn live_sales(
Ok(o) => match o {
Message::Text(o) => {
if let Ok(val) = serde_json::from_str::<ServerClient>(&o) {
info!("{val:?}");
match val {
ServerClient::Sales(sig) => match sig {
EventType::Added(add) => {
Expand All @@ -65,13 +61,12 @@ pub(crate) async fn live_sales(
})
.is_none()
{
info!("Socket closed");
return Ok(());
}
}
_ => {}
},
ServerClient::Listings(l) => log::info!("Listings {l:?}"),
ServerClient::Listings(l) => {}
ServerClient::SubscriptionCreated => {
log::info!("Subscription created");
}
Expand Down

0 comments on commit 6e3e904

Please sign in to comment.