chore: fmt

This commit is contained in:
2025-03-04 11:08:19 +01:00
parent 0ca9d6b9c6
commit df90835aac
16 changed files with 81 additions and 41 deletions

View File

@@ -6,11 +6,14 @@ language-servers = ["rust-analyzer", "tailwindcss-ls"]
# procMacro = { ignored = { leptos_macro = ["server"] } } # procMacro = { ignored = { leptos_macro = ["server"] } }
cargo = { features = ["ssr", "hydrate"] } cargo = { features = ["ssr", "hydrate"] }
check = { command = "check" } check = { command = "check" }
rustfmt = { overrideCommand = [
"sh", rustfmt = { overrideCommand = ["leptosfmt", "--stdin", "--rustfmt"] }
"-c",
"rustfmt --emit stdout --edition 2024 | leptosfmt --stdin", # rustfmt = { overrideCommand = [
] } # "sh",
# "-c",
# "set -euo pipefail; rustfmt --emit stdout --edition 2024 | leptosfmt --stdin",
# ] }
[language-server.tailwindcss-ls] [language-server.tailwindcss-ls]
config = { userLanguages = { rust = "html", "*.rs" = "html" } } config = { userLanguages = { rust = "html", "*.rs" = "html" } }

View File

@@ -17,7 +17,7 @@ pub fn shell(options: LeptosOptions) -> impl IntoView {
<HydrationScripts options /> <HydrationScripts options />
<MetaTags /> <MetaTags />
</head> </head>
<body class="bg-slate-950 text-white"> <body class="text-white bg-slate-950">
<App /> <App />
</body> </body>
</html> </html>

View File

@@ -22,7 +22,7 @@ pub fn Attempt(#[prop(into)] attempt: Signal<Option<models::Attempt>>) -> impl I
}; };
view! { view! {
<div class="flex gap-2 items-center justify-center"> <div class="flex gap-2 justify-center items-center">
<span>{icon}</span> <span>{icon}</span>
<span>{text}</span> <span>{text}</span>
</div> </div>

View File

@@ -2,14 +2,45 @@ use leptos::prelude::*;
use web_sys::MouseEvent; use web_sys::MouseEvent;
#[component] #[component]
pub fn Button(#[prop(into)] text: String, onclick: impl Fn(MouseEvent) + 'static) -> impl IntoView { pub fn Button<I, I_IV, T, T_IV>(icon: I, text: T, onclick: impl FnMut(MouseEvent) + 'static) -> impl IntoView
where
I: Fn() -> I_IV,
I_IV: IntoView,
T: Fn() -> T_IV,
T_IV: IntoView,
{
// let icon = icon.map(|f| f());
view! { view! {
<button <button
on:click=onclick on:click=onclick
type="button" type="button"
class="text-black bg-orange-300 hover:bg-orange-400 focus:ring-4 focus:ring-orange-500 font-medium rounded-lg text-sm px-5 py-2.5 me-2 mb-2 focus:outline-none" class="py-2.5 px-5 mb-2 text-sm font-medium text-black bg-orange-300 rounded-lg hover:bg-orange-400 focus:ring-4 focus:ring-orange-500 focus:outline-none me-2"
> >
{text} {icon()}
{text()}
</button> </button>
} }
} }
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn baseline() {
let icon = || ();
let text = || ();
let onclick = |_| {};
let props = ButtonProps { icon, text, onclick };
Button(props);
}
#[test]
fn simple() {
let icon = || view! { <crate::components::icons::ForwardSolid /> };
let text = || Some("foo".to_string());
let onclick = |_| {};
view! { <Button icon text onclick /> };
}
}

View File

@@ -17,7 +17,7 @@ pub struct HeaderItem {
#[component] #[component]
pub fn StyledHeader(#[prop(into)] items: Signal<HeaderItems>) -> impl IntoView { pub fn StyledHeader(#[prop(into)] items: Signal<HeaderItems>) -> impl IntoView {
view! { view! {
<div class="bg-orange-300 text-black border-b-2 border-b-orange-400"> <div class="text-black bg-orange-300 border-b-2 border-b-orange-400">
// <div class="container mx-auto" > // <div class="container mx-auto" >
<Header items /> <Header items />
// </div> // </div>
@@ -33,7 +33,7 @@ pub fn Header(#[prop(into)] items: Signal<HeaderItems>) -> impl IntoView {
let right = move || items.read().right.clone(); let right = move || items.read().right.clone();
view! { view! {
<div class="grid grid-cols-[1fr_3fr_1fr] text-xl font-semibold p-4"> <div class="grid p-4 text-xl font-semibold grid-cols-[1fr_3fr_1fr]">
// Left side of header // Left side of header
<div class="justify-self-start"> <div class="justify-self-start">
<Items items=Signal::derive(left) /> <Items items=Signal::derive(left) />

View File

@@ -31,7 +31,7 @@ pub fn Problem(
let grid_classes = move || format!("grid grid-rows-{} grid-cols-{} gap-3", dim.get().rows, dim.get().cols); let grid_classes = move || format!("grid grid-rows-{} grid-cols-{} gap-3", dim.get().rows, dim.get().cols);
view! { view! {
<div class="grid grid-cols-[auto,1fr] gap-8"> <div class="grid gap-8 grid-cols-[auto,1fr]">
<div class=move || { grid_classes }>{holds}</div> <div class=move || { grid_classes }>{holds}</div>
</div> </div>
} }

View File

@@ -11,7 +11,7 @@ pub fn ProblemInfo(problem: models::Problem) -> impl IntoView {
let method = problem.method; let method = problem.method;
view! { view! {
<div class="grid grid-rows-none grid-cols-[auto,1fr] gap-0.5"> <div class="grid grid-rows-none gap-0.5 grid-cols-[auto,1fr]">
<NameValue name="Name:" value=name /> <NameValue name="Name:" value=name />
<NameValue name="Method:" value=method.to_string() /> <NameValue name="Method:" value=method.to_string() />
<NameValue name="Set By:" value=set_by /> <NameValue name="Set By:" value=set_by />
@@ -23,7 +23,7 @@ pub fn ProblemInfo(problem: models::Problem) -> impl IntoView {
#[tracing::instrument(skip_all)] #[tracing::instrument(skip_all)]
fn NameValue(#[prop(into)] name: String, #[prop(into)] value: String) -> impl IntoView { fn NameValue(#[prop(into)] name: String, #[prop(into)] value: String) -> impl IntoView {
view! { view! {
<p class="text-orange-300 mr-4 text-right">{name}</p> <p class="mr-4 text-right text-orange-300">{name}</p>
<p class="text-white font-semibold">{value}</p> <p class="font-semibold text-white">{value}</p>
} }
} }

View File

@@ -6,6 +6,7 @@ pub mod pages {
pub mod wall; pub mod wall;
} }
pub mod components { pub mod components {
pub use attempt::Attempt;
pub use button::Button; pub use button::Button;
pub use header::StyledHeader; pub use header::StyledHeader;
pub use problem::Problem; pub use problem::Problem;

View File

@@ -49,7 +49,7 @@ pub fn EditWall() -> impl IntoView {
}; };
leptos::view! { leptos::view! {
<div class="min-w-screen min-h-screen bg-slate-900"> <div class="min-h-screen min-w-screen bg-slate-900">
<StyledHeader items=Signal::derive(header_items) /> <StyledHeader items=Signal::derive(header_items) />
<div class="container mx-auto mt-2"> <div class="container mx-auto mt-2">
@@ -155,7 +155,7 @@ fn Hold(wall_uid: models::WallUid, hold: models::Hold) -> impl IntoView {
view! { view! {
<button on:click=open_camera> <button on:click=open_camera>
<div class="bg-indigo-100 aspect-square rounded">{img}</div> <div class="bg-indigo-100 rounded aspect-square">{img}</div>
</button> </button>
<input <input

View File

@@ -65,7 +65,7 @@ pub fn Routes() -> impl IntoView {
children=move |problem: models::Problem| { children=move |problem: models::Problem| {
view! { view! {
<Problem dim=wall_dimensions problem /> <Problem dim=wall_dimensions problem />
<hr class="h-px my-8 border-0 bg-gray-700" /> <hr class="my-8 h-px bg-gray-700 border-0" />
} }
} }
/> />
@@ -78,7 +78,7 @@ pub fn Routes() -> impl IntoView {
}; };
view! { view! {
<div class="min-w-screen min-h-screen bg-neutral-950"> <div class="min-h-screen min-w-screen bg-neutral-950">
<StyledHeader items=Signal::derive(header_items) /> <StyledHeader items=Signal::derive(header_items) />
<div class="container mx-auto mt-6"> <div class="container mx-auto mt-6">

View File

@@ -20,11 +20,11 @@ pub fn Settings() -> impl IntoView {
}; };
view! { view! {
<div class="min-w-screen min-h-screen bg-neutral-950"> <div class="min-h-screen min-w-screen bg-neutral-950">
<StyledHeader items=header_items /> <StyledHeader items=header_items />
// {move || view! { <Import wall_uid=wall_uid.get() /> }} // {move || view! { <Import wall_uid=wall_uid.get() /> }}
<div class="container mx-auto mt-2"></div> <div class="container mx-auto mt-2" />
</div> </div>
} }
} }

View File

@@ -107,7 +107,7 @@ pub fn Wall() -> impl IntoView {
}; };
leptos::view! { leptos::view! {
<div class="min-w-screen min-h-screen bg-neutral-950"> <div class="min-h-screen min-w-screen bg-neutral-950">
<StyledHeader items=Signal::derive(header_items) /> <StyledHeader items=Signal::derive(header_items) />
<div class="m-2"> <div class="m-2">
@@ -137,14 +137,14 @@ pub fn Wall() -> impl IntoView {
} }
}; };
let v = view! { let v = view! {
<div class="grid grid-cols-1 md:grid-cols-[auto,1fr] gap-8"> <div class="grid grid-cols-1 gap-8 md:grid-cols-[auto,1fr]">
<div>{grid}</div> <div>{grid}</div>
<div> <div>
<Button <Button
icon=|| view! { <icons::ForwardSolid /> }
text=|| Some("Next problem".to_string())
onclick=move |_| fn_next_problem(&wall) onclick=move |_| fn_next_problem(&wall)
// TODO: use forward icon
text="➤ Next problem"
/> />
<div class="m-4" /> <div class="m-4" />
@@ -162,7 +162,7 @@ pub fn Wall() -> impl IntoView {
<div class="m-4" /> <div class="m-4" />
<div class="relative inline-flex items-center justify-center p-0.5 mb-2 me-2 overflow-hidden text-sm font-medium rounded-lg group bg-gradient-to-br from-cyan-500 to-blue-500 text-white hover:brightness-125"> <div class="inline-flex overflow-hidden relative justify-center items-center p-0.5 mb-2 text-sm font-medium text-white bg-gradient-to-br from-cyan-500 to-blue-500 rounded-lg me-2 group hover:brightness-125">
<input <input
type="checkbox" type="checkbox"
id="flash-option" id="flash-option"
@@ -173,10 +173,10 @@ pub fn Wall() -> impl IntoView {
/> />
<label for="flash-option" class="cursor-pointer"> <label for="flash-option" class="cursor-pointer">
<div <div
class="flex items-center gap-2 relative px-5 py-3.5 transition-all ease-in duration-75 bg-gray-900 rounded-md" class="flex relative gap-2 items-center py-3.5 px-5 bg-gray-900 rounded-md transition-all duration-75 ease-in"
class:bg-transparent=move || ui_is_flash.get() class:bg-transparent=move || ui_is_flash.get()
> >
<div class="aspect-square rounded-sm ring-offset-gray-700 bg-white border-gray-500 text-white"> <div class="text-white bg-white rounded-sm border-gray-500 ring-offset-gray-700 aspect-square">
<span class=("text-cyan-500", move || ui_is_flash.get())> <span class=("text-cyan-500", move || ui_is_flash.get())>
<icons::Check /> <icons::Check />
</span> </span>
@@ -187,7 +187,7 @@ pub fn Wall() -> impl IntoView {
</label> </label>
</div> </div>
<div class="relative inline-flex items-center justify-center p-0.5 mb-2 me-2 overflow-hidden text-sm font-medium rounded-lg group bg-gradient-to-br from-teal-300 to-lime-300 text-white hover:brightness-125"> <div class="inline-flex overflow-hidden relative justify-center items-center p-0.5 mb-2 text-sm font-medium text-white bg-gradient-to-br from-teal-300 to-lime-300 rounded-lg me-2 group hover:brightness-125">
<input <input
type="checkbox" type="checkbox"
id="climbed-option" id="climbed-option"
@@ -198,10 +198,10 @@ pub fn Wall() -> impl IntoView {
/> />
<label for="climbed-option" class="cursor-pointer"> <label for="climbed-option" class="cursor-pointer">
<div <div
class="flex items-center gap-2 relative px-5 py-3.5 transition-all ease-in duration-75 bg-gray-900 rounded-md text-white" class="flex relative gap-2 items-center py-3.5 px-5 text-white bg-gray-900 rounded-md transition-all duration-75 ease-in"
class:bg-transparent=move || ui_is_climbed.get() class:bg-transparent=move || ui_is_climbed.get()
> >
<div class="aspect-square rounded-sm ring-offset-gray-700 bg-white border-gray-500"> <div class="bg-white rounded-sm border-gray-500 ring-offset-gray-700 aspect-square">
<span class=("text-black", move || ui_is_climbed.get())> <span class=("text-black", move || ui_is_climbed.get())>
<icons::Check /> <icons::Check />
</span> </span>
@@ -216,7 +216,7 @@ pub fn Wall() -> impl IntoView {
</label> </label>
</div> </div>
<div class="relative inline-flex items-center justify-center p-0.5 mb-2 me-2 overflow-hidden text-sm font-medium rounded-lg group bg-gradient-to-br from-pink-500 to-orange-400 text-white hover:brightness-125"> <div class="inline-flex overflow-hidden relative justify-center items-center p-0.5 mb-2 text-sm font-medium text-white bg-gradient-to-br from-pink-500 to-orange-400 rounded-lg me-2 group hover:brightness-125">
<input <input
type="checkbox" type="checkbox"
id="favorite-option" id="favorite-option"
@@ -227,10 +227,10 @@ pub fn Wall() -> impl IntoView {
/> />
<label for="favorite-option" class="cursor-pointer"> <label for="favorite-option" class="cursor-pointer">
<div <div
class="flex items-center gap-2 relative px-5 py-3.5 transition-all ease-in duration-75 bg-gray-900 rounded-md" class="flex relative gap-2 items-center py-3.5 px-5 bg-gray-900 rounded-md transition-all duration-75 ease-in"
class:bg-transparent=move || ui_is_favorite.get() class:bg-transparent=move || ui_is_favorite.get()
> >
<div class="aspect-square rounded-sm ring-offset-gray-700 border-gray-500 text-pink-500"> <div class="text-pink-500 rounded-sm border-gray-500 ring-offset-gray-700 aspect-square">
<span class=("text-white", move || ui_is_favorite.get())> <span class=("text-white", move || ui_is_favorite.get())>
<icons::HeartOutline /> <icons::HeartOutline />
</span> </span>

View File

@@ -63,7 +63,8 @@ impl Database {
let mut table = txn.open_table(TABLE_VERSION)?; let mut table = txn.open_table(TABLE_VERSION)?;
table.insert((), version)?; table.insert((), version)?;
Ok(()) Ok(())
}).await })
.await
} }
} }

View File

@@ -23,7 +23,7 @@ pub async fn migrate_to_v3(db: &Database) -> Result<(), Box<dyn std::error::Erro
}) })
.await?; .await?;
db.set_version(db::Version {version: db::v3::VERSION}).await?; db.set_version(db::Version { version: db::v3::VERSION }).await?;
Ok(()) Ok(())
} }

4
leptosfmt.toml Normal file
View File

@@ -0,0 +1,4 @@
closing_tag_style = "SelfClosing"
[attr_values]
class = "Tailwind"

View File

@@ -1,4 +1,4 @@
style_edition = "2024" edition = "2024"
unstable_features = true unstable_features = true
imports_granularity = "Item" imports_granularity = "Item"
group_imports = "One" group_imports = "One"