This commit is contained in:
2025-03-04 17:36:13 +01:00
parent df90835aac
commit 3c4952ce50
4 changed files with 87 additions and 22 deletions

View File

@@ -1,23 +1,39 @@
use super::icons::Icon;
use leptos::prelude::*; use leptos::prelude::*;
use web_sys::MouseEvent; use web_sys::MouseEvent;
#[component] #[component]
pub fn Button<I, I_IV, T, T_IV>(icon: I, text: T, onclick: impl FnMut(MouseEvent) + 'static) -> impl IntoView pub fn Button(
where #[prop(optional)]
I: Fn() -> I_IV, #[prop(into)]
I_IV: IntoView, icon: MaybeProp<Icon>,
T: Fn() -> T_IV,
T_IV: IntoView, #[prop(into)] text: Signal<String>,
{
// let icon = icon.map(|f| f()); onclick: impl FnMut(MouseEvent) + 'static,
) -> impl IntoView {
let icon_view = icon.get().map(|i| {
let icon_view = i.into_view();
view! { <div class="self-center mx-5 my-2.5 text-pink-500 rounded-sm">{icon_view}</div> }
});
let separator = icon
.get()
.is_some()
.then(|| view! { <div class="w-0.5 bg-gradient-to-br from-pink-500 to-orange-400" /> });
let text_view = view! { <div class="self-center mx-5 my-2.5 uppercase w-full text-lg font-thin">{text.get()}</div> };
view! { view! {
<button <button
on:click=onclick on:click=onclick
type="button" type="button"
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" class="p-0.5 mb-2 bg-gradient-to-br from-pink-500 to-orange-400 rounded-lg me-2 hover:brightness-125 active:brightness-90"
> >
{icon()} <div class="flex items-stretch py-1.5 bg-gray-900 rounded-md">
{text()} {icon_view} {separator} {text_view}
</div>
</button> </button>
} }
} }
@@ -28,17 +44,16 @@ mod tests {
#[test] #[test]
fn baseline() { fn baseline() {
let icon = || (); let text = "foo";
let text = || ();
let onclick = |_| {}; let onclick = |_| {};
let props = ButtonProps { icon, text, onclick };
Button(props); view! { <Button text onclick /> };
} }
#[test] #[test]
fn simple() { fn simple() {
let icon = || view! { <crate::components::icons::ForwardSolid /> }; let icon = Icon::ForwardSolid;
let text = || Some("foo".to_string()); let text = "foo";
let onclick = |_| {}; let onclick = |_| {};
view! { <Button icon text onclick /> }; view! { <Button icon text onclick /> };

View File

@@ -1,5 +1,34 @@
use leptos::prelude::*; use leptos::prelude::*;
#[derive(Copy, Debug, Clone)]
pub enum Icon {
BoltSolid,
BoltSlashSolid,
WrenchSolid,
ForwardSolid,
Check,
HeartOutline,
ArrowPath,
PaperAirplaneSolid,
NoSymbol,
}
impl Icon {
// TODO: Actually impl IntoView for Icon instead
pub fn into_view(self) -> impl IntoView {
match self {
Icon::BoltSolid => view! { <BoltSolid /> }.into_any(),
Icon::BoltSlashSolid => view! { <BoltSlashSolid /> }.into_any(),
Icon::WrenchSolid => view! { <WrenchSolid /> }.into_any(),
Icon::ForwardSolid => view! { <ForwardSolid /> }.into_any(),
Icon::Check => view! { <Check /> }.into_any(),
Icon::HeartOutline => view! { <HeartOutline /> }.into_any(),
Icon::ArrowPath => view! { <ArrowPath /> }.into_any(),
Icon::PaperAirplaneSolid => view! { <PaperAirplaneSolid /> }.into_any(),
Icon::NoSymbol => view! { <NoSymbol /> }.into_any(),
}
}
}
#[component] #[component]
pub fn BoltSolid() -> impl IntoView { pub fn BoltSolid() -> impl IntoView {
view! { view! {

View File

@@ -1,16 +1,35 @@
// +----------- <Best attempt> -----------+ // +--------------- Filter ----------- ↓ -+
// | |
// | |
// | |
// | |
// | |
// | |
// | |
// +--------------------------------------+
//
// +---------------------------+
// | Next Problem |
// +---------------------------+
//
// +--------------- Problem --------------+
// | Name: ... | // | Name: ... |
// | Method: ... | // | Method: ... |
// | Set by: ... | // | Set by: ... |
// | | // | |
// | | Flash | Top | Attempt | | // | | Flash | Top | Attempt | |
// | | // | |
// +--------------- History --------------+ // +--------------------------------------+
// + ------- + + ------ -+ +---------+
// | Flash | | Top | | Attempt |
// + ------- + + ------ -+ +---------+
//
// +---------- <Latest attempt> ----------+
// | Today: <Attempt> | // | Today: <Attempt> |
// | 14 days ago: <Attempt> | // | 14 days ago: <Attempt> |
// +--------------------------------------+ // +--------------------------------------+
use crate::codec::ron::RonEncoded;
use crate::components::ProblemInfo; use crate::components::ProblemInfo;
use crate::components::attempt::Attempt; use crate::components::attempt::Attempt;
use crate::components::button::Button; use crate::components::button::Button;
@@ -18,6 +37,7 @@ use crate::components::header::HeaderItem;
use crate::components::header::HeaderItems; use crate::components::header::HeaderItems;
use crate::components::header::StyledHeader; use crate::components::header::StyledHeader;
use crate::components::icons; use crate::components::icons;
use crate::components::icons::Icon;
use crate::models; use crate::models;
use crate::models::HoldRole; use crate::models::HoldRole;
use leptos::Params; use leptos::Params;
@@ -142,8 +162,8 @@ pub fn Wall() -> impl IntoView {
<div> <div>
<Button <Button
icon=|| view! { <icons::ForwardSolid /> } icon=Icon::ArrowPath
text=|| Some("Next problem".to_string()) text="Next problem"
onclick=move |_| fn_next_problem(&wall) onclick=move |_| fn_next_problem(&wall)
/> />

View File

@@ -10,3 +10,4 @@
- clock - clock
- hotkeys (enter =next problem, arrow = shift left/right up/down) - hotkeys (enter =next problem, arrow = shift left/right up/down)
- impl `sizes` hint next to `srcset` - impl `sizes` hint next to `srcset`
- add refresh wall button for when a hold is changed