use leptos::*;
use leptos_meta::*;
use leptos_router::*;
#[server(GetLinksAction, "/api", "GetJson")]
#[tracing::instrument]
pub async fn get_links() -> Result, ServerFnError> {
crate::models::Link::get_all().await.map_err(|x| {
let err = format!("Error while posting a link: {x:?}");
tracing::error!("{err}");
ServerFnError::ServerError("Could not post a link, try again later".into())
})
}
#[server(LinkAction, "/api")]
pub async fn add_value(name: String, link: String, icon: String) -> Result<(), ServerFnError> {
crate::models::Link::insert(name, link, icon)
.await
.map(|_| ())
.map_err(|x| {
let err = format!("Error while posting a comment: {x:?}");
tracing::error!("{err}");
ServerFnError::ServerError("Could not post a comment, try again later".into())
})
}
#[component]
pub fn Links() -> impl IntoView {
let (show_form, set_show_form) = create_signal(false);
let (edit_link, set_edit_link) = create_signal::
}>
"Something went wrong."}
}>
{move || links.get().map(move |x| x.map(move |c| {
view! {
}
}/>
}
}))}
{move || {
show_form.get().then(|| {
view! { }
})
}}
}
}
#[server(MoveLinkAction, "/api")]
pub async fn change_position(link_id: String, direction: String) -> Result<(), ServerFnError> {
crate::models::Link::move_position(link_id, direction)
.await
.map(|_| ())
.map_err(|x| {
let err = format!("Error while posting a comment: {x:?}");
tracing::error!("{err}");
ServerFnError::ServerError("Could not post a comment, try again later".into())
})
}
#[component]
fn Link(
link: RwSignal,
edit: ReadSignal,
set_edit_link: WriteSignal