mirror of
https://github.com/kjuulh/bitebuds.git
synced 2025-12-07 20:07:58 +01:00
feat: with local store
This commit is contained in:
@@ -2,7 +2,7 @@ use lazy_static::lazy_static;
|
||||
use leptos::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::models::{Event, EventOverview, Image};
|
||||
use domain::{Event, EventOverview, Image};
|
||||
|
||||
lazy_static! {
|
||||
static ref EVENTS: Vec<Event> = vec![
|
||||
@@ -18,7 +18,8 @@ lazy_static! {
|
||||
description: Some("Lorem ipsum dolor sit amet, qui minim labore adipisicing minim sint cillum sint consectetur cupidatat.".into()),
|
||||
time: chrono::Utc::now()
|
||||
.checked_add_days(chrono::Days::new(1))
|
||||
.unwrap(),
|
||||
.unwrap()
|
||||
.date_naive(),
|
||||
recipe_id: None,
|
||||
images: vec![],
|
||||
metadata: None,
|
||||
@@ -35,7 +36,8 @@ lazy_static! {
|
||||
description: Some("Lorem ipsum dolor sit amet, officia excepteur ex fugiat reprehenderit enim labore culpa sint ad nisi Lorem pariatur mollit ex esse exercitation amet. Nisi anim cupidatat excepteur officia. Reprehenderit nostrud nostrud ipsum Lorem est aliquip amet voluptate voluptate dolor minim nulla est proident. Nostrud officia pariatur ut officia. Sit irure elit esse ea nulla sunt ex occaecat reprehenderit commodo officia dolor Lorem duis laboris cupidatat officia voluptate. Culpa proident adipisicing id nulla nisi laboris ex in Lorem sunt duis officia eiusmod. Aliqua reprehenderit commodo ex non excepteur duis sunt velit enim. Voluptate laboris sint cupidatat ullamco ut ea consectetur et est culpa et culpa duis.".into()),
|
||||
time: chrono::Utc::now()
|
||||
.checked_add_days(chrono::Days::new(4))
|
||||
.unwrap(),
|
||||
.unwrap()
|
||||
.date_naive(),
|
||||
recipe_id: None,
|
||||
images: vec![],
|
||||
metadata: None,
|
||||
@@ -52,7 +54,8 @@ lazy_static! {
|
||||
description: Some("description".into()),
|
||||
time: chrono::Utc::now()
|
||||
.checked_sub_days(chrono::Days::new(2))
|
||||
.unwrap(),
|
||||
.unwrap()
|
||||
.date_naive(),
|
||||
recipe_id: None,
|
||||
images: vec![],
|
||||
metadata: None,
|
||||
@@ -71,15 +74,19 @@ pub async fn get_upcoming_events() -> Result<UpcomingEventsOverview, ServerFnErr
|
||||
get_upcoming_events_fn().await
|
||||
}
|
||||
|
||||
#[cfg(feature = "ssr")]
|
||||
async fn get_upcoming_events_fn() -> Result<UpcomingEventsOverview, ServerFnError> {
|
||||
let current_time = chrono::Utc::now();
|
||||
|
||||
let mut events: Vec<EventOverview> = EVENTS
|
||||
let es = services::EventStore::default();
|
||||
|
||||
let events = es
|
||||
.get_upcoming_events()
|
||||
.await
|
||||
.map_err(|e| ServerFnError::ServerError(e.to_string()))?
|
||||
.iter()
|
||||
.filter(|data| data.time > current_time)
|
||||
.map(|data| data.clone().into())
|
||||
.collect();
|
||||
events.sort_by(|a, b| a.time.cmp(&b.time));
|
||||
|
||||
Ok(UpcomingEventsOverview { events })
|
||||
}
|
||||
@@ -91,6 +98,7 @@ pub async fn get_full_event(event_id: uuid::Uuid) -> Result<Option<Event>, Serve
|
||||
get_full_event_fn(event_id).await
|
||||
}
|
||||
|
||||
#[cfg(feature = "ssr")]
|
||||
async fn get_full_event_fn(event_id: uuid::Uuid) -> Result<Option<Event>, ServerFnError> {
|
||||
let event = EVENTS
|
||||
.iter()
|
||||
|
||||
28
src/app.rs
28
src/app.rs
@@ -10,20 +10,20 @@ pub fn App(cx: Scope) -> impl IntoView {
|
||||
provide_meta_context(cx);
|
||||
|
||||
view! { cx,
|
||||
<Stylesheet id="leptos" href="/pkg/ssr_modes.css" />
|
||||
<Title text="Bitebuds" />
|
||||
<Stylesheet id="leptos" href="/pkg/ssr_modes.css" />
|
||||
<Title text="Bitebuds" />
|
||||
|
||||
<Router>
|
||||
<div class="app grid lg:grid-cols-[25%,50%,25%] sm:grid-cols-[10%,80%,10%] grid-cols-[5%,90%,5%]">
|
||||
<main class="main col-start-2">
|
||||
<div class="pt-4">
|
||||
<h1 class="font-semibold text-xl tracking-wide">"Bitebuds"</h1>
|
||||
<Routes>
|
||||
<Route path="" view=|cx| view! { cx, <HomePage /> }/>
|
||||
</Routes>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
</Router>
|
||||
<Router>
|
||||
<div class="app grid lg:grid-cols-[25%,50%,25%] sm:grid-cols-[10%,80%,10%] grid-cols-[5%,90%,5%]">
|
||||
<main class="main col-start-2">
|
||||
<div class="pt-4">
|
||||
<h1 class="font-semibold text-xl tracking-wide">"Bitebuds"</h1>
|
||||
<Routes>
|
||||
<Route path="" view=|cx| view! { cx, <HomePage /> }/>
|
||||
</Routes>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
</Router>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ use chrono::Datelike;
|
||||
use leptos::*;
|
||||
|
||||
use crate::api::events::*;
|
||||
use crate::models::{EventOverview, Image};
|
||||
use domain::{EventOverview, Image};
|
||||
|
||||
#[component]
|
||||
pub fn Day(
|
||||
|
||||
@@ -4,7 +4,6 @@ pub mod api;
|
||||
pub mod app;
|
||||
mod components;
|
||||
pub mod fallback;
|
||||
mod models;
|
||||
mod pages;
|
||||
use cfg_if::cfg_if;
|
||||
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct Metadata(HashMap<String, String>);
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct Recipe {
|
||||
pub id: uuid::Uuid,
|
||||
pub metadata: Option<Metadata>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct Image {
|
||||
pub id: uuid::Uuid,
|
||||
pub url: String,
|
||||
pub alt: String,
|
||||
pub metadata: Option<Metadata>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct Event {
|
||||
pub id: uuid::Uuid,
|
||||
pub cover_image: Option<Image>,
|
||||
pub name: String,
|
||||
pub description: Option<String>,
|
||||
pub time: chrono::DateTime<chrono::Utc>,
|
||||
pub recipe_id: Option<uuid::Uuid>,
|
||||
pub images: Vec<Image>,
|
||||
pub metadata: Option<Metadata>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct EventOverview {
|
||||
pub id: uuid::Uuid,
|
||||
pub cover_image: Option<Image>,
|
||||
pub name: String,
|
||||
pub description: Option<String>,
|
||||
pub time: chrono::DateTime<chrono::Utc>,
|
||||
}
|
||||
|
||||
impl From<Event> for EventOverview {
|
||||
fn from(value: Event) -> Self {
|
||||
Self {
|
||||
id: value.id,
|
||||
cover_image: value.cover_image,
|
||||
name: value.name,
|
||||
description: value.description,
|
||||
time: value.time,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user