[WIP] Move over to ssr in order to get backend working (everything is broken right now)

This commit is contained in:
Leonard Steppy 2025-02-12 00:07:30 +01:00
parent 2f672ecf27
commit b171088417
6 changed files with 59 additions and 47 deletions

View File

@ -6,7 +6,9 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
chrono = "0.4.39"
chrono = { version = "0.4.39", features = ["serde"] }
clap = { version = "4.5.28", features = ["derive"] }
leptos = { version = "0.7.5", features = ["csr"] }
leptos = { version = "0.7.5", features = ["ssr"] }
leptos_axum = "0.7.5"
console_error_panic_hook = "0.1.7"
serde = { version = "1.0", features = ["derive"] }

View File

@ -1,28 +0,0 @@
use crate::session_date_calculator::{Day, NthWeekday};
use chrono::Weekday;
use clap::Parser;
pub mod session_date_calculator;
#[derive(Debug, Parser)]
pub struct StartArgs {
/// on which days of the month there are sessions
#[arg(long = "sessions", num_args = 1..)]
pub session_days: Vec<NthWeekday>
}
pub fn localize_day(day: &Day) -> String {
format!(
"{}, {}",
match day.weekday {
Weekday::Mon => "Montag",
Weekday::Tue => "Dienstag",
Weekday::Wed => "Mittwoch",
Weekday::Thu => "Donnerstag",
Weekday::Fri => "Freitag",
Weekday::Sat => "Samstag",
Weekday::Sun => "Sonntag",
},
day.date.format("%d.%m.%Y")
)
}

View File

@ -1,9 +1,40 @@
mod webpage;
mod ui;
mod session_date_calculator;
use crate::session_date_calculator::{Day, NthWeekday};
use chrono::Weekday;
use clap::Parser;
use leptos::prelude::*;
fn main() {
console_error_panic_hook::set_once();
mount_to_body(webpage::App);
#[derive(Debug, Clone, Parser)]
struct AppArgs {
/// On which days of the month there are sessions
#[arg(long = "sessions", num_args = 1..)]
session_days: Vec<NthWeekday>,
/// The text to show next to upcoming band sessions
#[arg(long)]
motd: String,
}
fn main() {
let app_args = AppArgs::parse();
console_error_panic_hook::set_once();
//TODO serving and shit
}
pub fn localize_day(day: &Day) -> String {
format!(
"{}, {}",
match day.weekday {
Weekday::Mon => "Montag",
Weekday::Tue => "Dienstag",
Weekday::Wed => "Mittwoch",
Weekday::Thu => "Donnerstag",
Weekday::Fri => "Freitag",
Weekday::Sat => "Samstag",
Weekday::Sun => "Sonntag",
},
day.date.format("%d.%m.%Y")
)
}

View File

@ -1,10 +1,11 @@
use chrono::{Datelike, Days, Local, NaiveDate, ParseWeekdayError, Weekday};
use serde::{Deserialize, Serialize};
use std::error::Error;
use std::fmt::{Display, Formatter};
use std::num::ParseIntError;
use std::str::FromStr;
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
pub struct NthWeekday {
pub n: u8,
pub weekday: Weekday,

17
src/ui.rs Normal file
View File

@ -0,0 +1,17 @@
use crate::AppArgs;
use leptos::prelude::*;
#[component]
pub fn App(app_args: AppArgs) -> impl IntoView {
let (count, set_count) = signal(0);
view! {
<div style="background-color: #292b29; color: #ffffff; font-family: Arial, sans-serif; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0;">
<div style="background-color: #196e0a; padding: 20px; border-radius: 10px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); text-align: center; max-width: 400px; width: 100%;">
<h1>"Anstehende Proben Termine"</h1>
<p>{app_args.motd}</p>
<button on:click=move |_| { *set_count.write() += 1 }>"Click counter (" {count} ")"</button>
</div>
</div>
}
}

View File

@ -1,11 +0,0 @@
use leptos::prelude::*;
#[component]
pub fn App() -> impl IntoView {
let (count, set_count) = signal(0);
view! {
<button on:click=move |_| { *set_count.write() += 1 }>"Click me: " {count}</button>
<p>"Double count: " {move || count.get() * 2}</p>
}
}