feat: update to newest leptos

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2023-10-20 23:06:21 +02:00
parent 8ee2ca5c14
commit a7986e304c
15 changed files with 733 additions and 831 deletions

View File

@@ -6,50 +6,50 @@ pub struct CommandLineState {
}
#[component]
pub fn CommandLineModalView(cx: Scope) -> impl IntoView {
view! { cx, <div>"modal"</div> }
pub fn CommandLineModalView() -> impl IntoView {
view! { <div>"modal"</div> }
}
#[component]
pub fn CommandLineModal(cx: Scope) -> impl IntoView {
pub fn CommandLineModal() -> impl IntoView {
let state =
use_context::<RwSignal<CommandLineState>>(cx).expect("command line state must be provided");
use_context::<RwSignal<CommandLineState>>().expect("command line state must be provided");
let (hidden, _) = create_slice(cx, state, |state| state.hidden, |state, n| state.hidden = n);
let (hidden, _) = create_slice(state, |state| state.hidden, |state, n| state.hidden = n);
view! { cx,
view! {
{move || {
if !hidden.get() {
view! { cx, <CommandLineModalView/> }
view! { <CommandLineModalView/> }
} else {
view! { cx, }
view! { }.into_view()
}
}}
}
}
#[component]
pub fn CommandLine(cx: Scope, children: Children) -> impl IntoView {
let state = create_rw_signal(cx, CommandLineState { hidden: true });
provide_context(cx, state);
pub fn CommandLine(children: Children) -> impl IntoView {
let state = create_rw_signal(CommandLineState { hidden: true });
provide_context(state);
let (hidden, set_hidden) =
create_slice(cx, state, |state| state.hidden, |state, n| state.hidden = n);
create_slice(state, |state| state.hidden, |state, n| state.hidden = n);
leptos_dom::helpers::window_event_listener(ev::keypress, move |event| {
if event.ctrl_key() {
match event.code().as_str() {
"KeyK" => {
set_hidden(!hidden.get());
log!("toggle command")
set_hidden.set(!hidden.get());
//log!("toggle command")
}
_ => {}
}
}
});
view! { cx,
view! {
<div>
<div>{children(cx)}</div>
<div>{children()}</div>
<CommandLineModal/>
</div>
}

View File

@@ -24,17 +24,14 @@ pub async fn get_projects_list() -> anyhow::Result<Vec<GetProjectsListViewGetPro
}
#[component]
pub fn DashboardItemView(cx: Scope, item: GetProjectsListViewGetProjectsItems) -> impl IntoView {
view! { cx, <div class="dashboard-list-item dashboard-item">{item.title}</div> }
pub fn DashboardItemView(item: GetProjectsListViewGetProjectsItems) -> impl IntoView {
view! { <div class="dashboard-list-item dashboard-item">{item.title}</div> }
}
#[component]
pub fn DashboardProjectItemView(
cx: Scope,
project: GetProjectsListViewGetProjects,
) -> impl IntoView {
view! { cx,
<div class="dashboard-list-item dashboard-list-project">
pub fn DashboardProjectItemView(project: GetProjectsListViewGetProjects) -> impl IntoView {
view! {
<div class="dashboard-list-item dashboard-list-project">
<a href=format!("/dash/project/{}", & project.id) class="project-item flex flex-row">
<div class="space-x-2">
<span>{&project.name}</span>
@@ -48,46 +45,49 @@ pub fn DashboardProjectItemView(
#[component]
pub fn DashboardListView(
cx: Scope,
projects: Resource<(), Vec<GetProjectsListViewGetProjects>>,
) -> impl IntoView {
let projects_view = move || {
projects.with(cx, |projects| {
projects.with(|projects| {
if projects.is_none() {
return Vec::new();
}
let projects = projects.as_ref().unwrap();
if projects.is_empty() {
return vec![view! { cx, <div class="project-item">"No projects"</div> }.into_any()];
return vec![view! { <div class="project-item">"No projects"</div> }.into_any()];
}
projects
.into_iter()
.filter(|project| !project.items.is_empty())
.map(|project| {
view! { cx,
<div>
<DashboardProjectItemView project=project.clone()/>
{&project
.items
.clone()
.into_iter()
.map(|item| {
view! { cx, <DashboardItemView item=item/> }
})
.collect::<Vec<_>>()
.into_view(cx)}
</div>
}
view! {
<div>
<DashboardProjectItemView project=project.clone()/>
{&project
.items
.clone()
.into_iter()
.map(|item| {
view! { <DashboardItemView item=item/> }
})
.collect::<Vec<_>>()
.into_view()}
</div>
}
.into_any()
})
.collect::<Vec<_>>()
})
};
view! { cx, <div class="project-items">{projects_view}</div> }
view! {<div class="project-items">{projects_view}</div> }
}
#[component]
pub fn DashboardList(cx: Scope) -> impl IntoView {
let projects =
create_local_resource(cx, || (), |_| async { get_projects_list().await.unwrap() });
pub fn DashboardList() -> impl IntoView {
let projects = create_local_resource(|| (), |_| async { get_projects_list().await.unwrap() });
view! { cx, <DashboardListView projects=projects/> }
view! {<DashboardListView projects=projects/> }
}

View File

@@ -25,20 +25,24 @@ pub async fn get_projects_list() -> anyhow::Result<Vec<GetProjectsListViewGetPro
#[component]
pub fn NavbarProjectsView(
cx: Scope,
projects: Resource<(), Vec<GetProjectsListViewGetProjects>>,
) -> impl IntoView {
let projects_view = move || {
projects.with(cx, |projects| {
projects.with(|projects| {
if projects.is_none() {
return Vec::new()
}
let projects = projects.as_ref().unwrap();
if projects.is_empty() {
return vec![view! { cx, <div class="project-item">"No projects"</div> }.into_any()];
return vec![view! { <div class="project-item">"No projects"</div> }.into_any()];
}
projects
.into_iter()
.map(|project| {
view! { cx,
view! {
<a href=format!("/dash/project/{}", & project.id) class="project-item">
@@ -53,13 +57,13 @@ pub fn NavbarProjectsView(
})
};
view! { cx, <div class="project-items space-y-1">{projects_view}</div> }
view! { <div class="project-items space-y-1">{projects_view}</div> }
}
#[component]
pub fn NavbarProjects(cx: Scope) -> impl IntoView {
pub fn NavbarProjects() -> impl IntoView {
let projects =
create_local_resource(cx, || (), |_| async { get_projects_list().await.unwrap() });
create_local_resource(|| (), |_| async { get_projects_list().await.unwrap() });
view! { cx, <NavbarProjectsView projects=projects/> }
view! { <NavbarProjectsView projects=projects/> }
}