remove unused pages & update links

This commit is contained in:
Romulus21
2025-10-08 14:16:27 +02:00
parent e7a45dc46c
commit 3bf77add88
9 changed files with 120 additions and 294 deletions

View File

@@ -45,7 +45,7 @@ pub fn Links() -> impl IntoView {
show.get().then(|| {
view! { <div class="my-0 mx-auto w-72 p-6 bg-prim-light rounded-lg">
<h2 class="pb-6 text-2xl text-center">"Ajout d'un lien"</h2>
<ActionForm action=link_action attr:class="">
<ActionForm action=link_action>
<div>
<label class="block mt-3 mb-1">"Nom"</label>
<input type="text"
@@ -130,6 +130,8 @@ fn Link<T: 'static + Clone, S: 'static>(
edit: ReadSignal<bool>,
links: Resource<T, S>,
) -> impl IntoView {
let (show_edit, set_show_edit) = create_signal(false);
view! {
<li class="mx-auto w-44 lg:w-60">
<a class="bg-prim-light w-full hover:bg-prim-lightest border-b hover:border-third border-transparent text-xl rounded-lg text-center hover:text-third transition-colors px-5 py-4 inline-block"
@@ -148,13 +150,18 @@ fn Link<T: 'static + Clone, S: 'static>(
view! { <div class="bg-third border border-transparent rounded-b-lg flex justify-between">
<MoveButton id=link.with(|x| x.id.to_string()) value="prev".to_string() label="<".to_string() links=links />
<button class="block px-2 py-1 flex-1 hover:bg-third-light"
//on:click=move |_| {set_show.set(true)}
on:click=move |_| {set_show_edit.set(true)}
>"Editer"</button>
<DeleteButton id=link.with(|x| x.id.to_string()) links=links />
<MoveButton id=link.with(|x| x.id.to_string()) value="next".to_string() label=">".to_string() links=links />
</div> }
})
}}
{move || {
show_edit.get().then(|| {
view! { <EditLinkForm link=link set_show=set_show_edit links=links /> }
})
}}
</li>
}
}
@@ -213,3 +220,82 @@ fn DeleteButton<T: 'static + Clone, S: 'static>(
</ActionForm>
}
}
#[server(UpdateLinkAction, "/api")]
pub async fn update_link(id: String, name: String, link: String, icon: String) -> Result<(), ServerFnError> {
crate::models::Link::update(id, name, link, icon)
.await
.map(|_| ())
.map_err(|x| {
let err = format!("Error while updating a link: {x:?}");
tracing::error!("{err}");
ServerFnError::ServerError("Could not update the link, try again later".into())
})
}
#[component]
fn EditLinkForm<T: 'static + Clone, S: 'static>(
link: RwSignal<crate::models::Link>,
set_show: WriteSignal<bool>,
links: Resource<T, S>,
) -> impl IntoView {
let update_action = create_server_action::<UpdateLinkAction>();
let (name, set_name) = create_signal(link.with(|x| x.name.clone()));
let (link_url, set_link_url) = create_signal(link.with(|x| x.link.clone()));
let (icon, set_icon) = create_signal(link.with(|x| x.icon.clone()));
create_effect(move |_| {
if update_action.value().get().is_some() {
links.refetch();
set_show.set(false);
}
});
view! {
<div class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50">
<div class="bg-prim-light p-6 rounded-lg w-96">
<h2 class="pb-6 text-2xl text-center">"Édition du lien"</h2>
<ActionForm action=update_action>
<input name="id" type="hidden" value={move || link.with(|x| x.id.to_string())} />
<div>
<label class="block mt-3 mb-1">"Nom"</label>
<input type="text"
name="name"
prop:value=move || name.get()
on:input=move |ev| set_name.set(event_target_value(&ev))
class="text-center bg-prim border border-transparent rounded-lg focus:border-third px-2 py-2 w-full" />
</div>
<div>
<label class="block mt-3 mb-1">"Lien"</label>
<input type="url"
name="link"
prop:value=move || link_url.get()
on:input=move |ev| set_link_url.set(event_target_value(&ev))
class="text-center bg-prim border border-transparent rounded-lg focus:border-third px-2 py-2 w-full" />
</div>
<div>
<label class="block mt-3 mb-1">"Icône"</label>
<input type="url"
name="icon"
prop:value=move || icon.get()
on:input=move |ev| set_icon.set(event_target_value(&ev))
class="text-center bg-prim border border-transparent rounded-lg focus:border-third px-2 py-2 w-full" />
</div>
<div class="flex gap-2 mt-5">
<button type="button"
on:click=move |_| set_show.set(false)
class="bg-prim hover:bg-prim-light rounded-lg transition-colors px-2 py-1 flex-1">"Annuler"</button>
<button type="submit"
class="bg-third hover:bg-third-light rounded-lg transition-colors px-2 py-1 flex-1">"Valider"</button>
</div>
</ActionForm>
</div>
</div>
}
}