fix value decimal form

This commit is contained in:
Romulus21
2024-11-30 22:07:53 +01:00
parent 319e901dd8
commit ba67b0becd
5 changed files with 51 additions and 51 deletions

View File

@@ -38,9 +38,6 @@ WantedBy=multi-user.target
[x] formulaire
[ ] recap capteurs
## style
[Simple dark dashboard](https://dribbble.com/shots/10090105-Dashboard-UI/attachments/2097885?mode=media)

View File

@@ -88,4 +88,11 @@ impl Link {
}
}
}
#[cfg(feature = "ssr")]
pub async fn destroy(id: String) -> Result<sqlx::mysql::MySqlQueryResult, sqlx::Error> {
sqlx::query!("DELETE FROM links WHERE id = ? ", id,)
.execute(crate::database::get_db())
.await
}
}

View File

@@ -1,8 +1,6 @@
use ev::MouseEvent;
use leptos::*;
use leptos_meta::*;
//use leptos_meta::*;
use leptos_router::*;
use wasm_bindgen::JsCast;
#[server(GetLinksAction, "/api", "GetJson")]
#[tracing::instrument]
@@ -37,25 +35,12 @@ pub fn Links() -> impl IntoView {
let links = create_resource(
move || (result.get()),
move |_| async move {
logging::log!("fetch");
reset_form.set("");
set_show.set(false);
get_links().await
},
);
create_effect(move |_| {
logging::log!("here .refetch() runs effect instead of get_q_sort.get()");
logging::log!("{:?}", links.get());
});
async fn move_click_position(id: String) {
logging::log!("move click {}", id);
change_position(id, "prev".to_string())
.await
.expect("REASON");
}
let form = move || {
show.get().then(|| {
view! { <div class="my-0 mx-auto w-72 p-6 bg-prim-light rounded-lg">
@@ -85,7 +70,7 @@ pub fn Links() -> impl IntoView {
};
view! {
<ul class="flex flex-wrap gap-5 mt-5 justify-center">
<ul class="flex flex-wrap gap-5 m-5 justify-center">
<Suspense fallback=move || view! {<p>"Loading Comments from the article"</p> }>
<ErrorBoundary fallback=|_| {
view! { <p class="error-messages text-xs-center">"Something went wrong."</p>}
@@ -106,7 +91,7 @@ pub fn Links() -> impl IntoView {
</Suspense>
</ul>
<div class="flex justify-end gap-5 m-5">
<div class="flex justify-end gap-5 mx-5">
<button on:click=move |_| {set_edit.set(!edit.get())} class="bg-prim-light hover:bg-prim-lightest rounded-full px-5 py-3 text-second-dark hover:text-third transition-colors">"Edit"</button>
<button on:click=move |_| {set_show.set(true)} class="bg-prim-light hover:bg-prim-lightest rounded-full px-5 py-3 text-second-dark hover:text-third transition-colors">"Ajouter un lien +"</button>
</div>
@@ -135,27 +120,9 @@ fn Link<T: 'static + Clone, S: 'static>(
edit: ReadSignal<bool>,
links: Resource<T, S>,
) -> impl IntoView {
/*let result = move_link.version();
let _ = create_resource(
move || (result.get()),
move |_| async move {
logging::log!("move");
//set_reload.update(|n| *n += 1);
//links.refetch();
},
);*/
//let on_click = move |event: MouseEvent| {
//.dyn_into::<leptos::web_sys::HtmlElement>().unwrap();
//let dataset = element.dataset();
//logging::log!("move {:?}", element);
//let _ = move_link.dispatch(());
//links.refetch();
//};
view! {
<li>
<a class="bg-prim-light hover:bg-prim-lightest text-xl rounded-lg text-center hover:text-third transition-colors px-5 py-4 min-w-60 inline-block"
<a class="bg-prim-light 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 min-w-60 inline-block"
target="_blank"
href={move || link.with(|x| x.link.to_string())}>
{move || link.with(|x| x.name.to_string())}
@@ -167,9 +134,7 @@ fn Link<T: 'static + Clone, S: 'static>(
<button class="block px-2 py-1 flex-1 hover:bg-third-light"
//on:click=move |_| {set_show.set(true)}
>"Editer"</button>
<button class="block px-2 py-1 flex-1 hover:bg-third-light"
//on:click=move |_| {set_show.set(true)}
>"Supp."</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> }
})
@@ -200,3 +165,35 @@ fn MoveButton<T: 'static + Clone, S: 'static>(
</ActionForm>
}
}
#[server(DeleteLinkAction, "/api")]
pub async fn delete_link(link_id: String) -> Result<(), ServerFnError> {
crate::models::Link::destroy(link_id)
.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 DeleteButton<T: 'static + Clone, S: 'static>(
id: String,
links: Resource<T, S>,
) -> impl IntoView {
let delete_link = create_server_action::<DeleteLinkAction>();
view! {
<ActionForm action=delete_link on:submit= move |ev| {
let Ok(_) = DeleteLinkAction::from_event(&ev) else {
return ev.prevent_default();
};
links.refetch();
}>
<input name="link_id" type="hidden" value=id />
<button type="submit" class="block px-2 py-1 flex-1 hover:bg-third-light">"Supp."</button>
</ActionForm>
}
}

View File

@@ -1,5 +1,5 @@
use leptos::*;
use leptos_meta::*;
//use leptos_meta::*;
use leptos_router::*;
use crate::models::OPTIONS;
@@ -29,7 +29,7 @@ pub fn FormValues() -> impl IntoView {
);
view! {
<div class="my-0 mx-auto w-72 p-6 bg-prim-light rounded-lg">
<div class="my-5 mx-auto w-72 p-6 bg-prim-light rounded-lg">
<h2 class="pb-6 text-2xl text-center">"Formulaire"</h2>
<ActionForm action=value_action attr:class="">
@@ -45,6 +45,7 @@ pub fn FormValues() -> impl IntoView {
<label class="block mt-3 mb-1">Valeur</label>
<input name="value"
type="number"
step="0.01"
prop:value=move || reset_value.get()
class="text-center bg-prim border border-transparent rounded-lg focus:border-third px-2 py-2 w-60" />
</div>

View File

@@ -660,10 +660,6 @@ video {
border-bottom-left-radius: 0.5rem;
}
.rounded-bl-lg {
border-bottom-left-radius: 0.5rem;
}
.rounded-br-lg {
border-bottom-right-radius: 0.5rem;
}
@@ -764,8 +760,10 @@ video {
transition-duration: 150ms;
}
.red {
color: red;
.active-link {
border-bottom-width: 1px;
--tw-text-opacity: 1;
color: rgb(252 68 61 / var(--tw-text-opacity));
}
.hover\:border-b:hover {