Skip to content

Commit

Permalink
feat: show photo deck on qr code page
Browse files Browse the repository at this point in the history
  • Loading branch information
johnbchron committed Mar 1, 2024
1 parent 0ac06b8 commit a13a469
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions crates/site-app/src/pages/qr_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,22 @@ pub fn InnerQrCodePage(
std::env::var("APP_BASE_URL").expect("APP_BASE_URL not set"),
);

// we will display the qr code regardless, but if we can map it to a photo
// group, we will also display the photo deck
let photo_deck_element = match id.parse::<core_types::Ulid>() {
Ok(ulid) => view! {
<PhotoDeckWrapper group_id={core_types::PhotoGroupRecordId(ulid)} />
}
.into_view(),
Err(_) => view! { <p>"Invalid photo group ID"</p> }.into_view(),
};

view! {
<SmallPageWrapper extra_class=class theme_override=theme_override>
<div class="d-card-body gap-4">
<p class="text-2xl font-semibold tracking-tight">"QR Code"</p>
<QrCode data=url class="rounded-box border shadow" />
{photo_deck_element}
<div class="flex flex-row items-center gap-4">
<a href="/dashboard" class="d-btn d-btn-primary d-btn-sm">"Back to Dashboard"</a>
<div class="flex-1" />
Expand Down Expand Up @@ -67,3 +78,36 @@ pub fn QrCode(
</Suspense>
}
}

#[component]
pub fn PhotoDeckWrapper(
group_id: core_types::PhotoGroupRecordId,
) -> impl IntoView {
let photo_group =
create_resource(move || group_id, bl::fetch::fetch_photo_group);

view! {
<Suspense fallback=|| view!{}>
{ photo_group.map(|r| {
match r {
Ok(Some(photo_group)) => view! {
<div class="flex flex-row justify-center">
<crate::components::photo_deck::PhotoDeck ids={photo_group.photos.clone()} />
</div>
}.into_view(),
Ok(None) => view! {
<div>
<p>"Photo group not found"</p>
</div>
}.into_view(),
Err(e) => view! {
<div>
<p>{e.to_string()}</p>
<p>"Failed to fetch photo group"</p>
</div>
}.into_view(),
}
})}
</Suspense>
}
}

0 comments on commit a13a469

Please sign in to comment.