error component wip
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
use crate::services::confirm::ConfirmService;
|
||||
use crate::services::rest::RestService;
|
||||
use common::DeleteMilestone;
|
||||
use common::Milestone;
|
||||
use wasm_bindgen_futures::spawn_local;
|
||||
use yew::prelude::*;
|
||||
|
||||
#[derive(Properties, Clone, PartialEq)]
|
||||
@@ -9,6 +13,8 @@ pub struct Props {
|
||||
|
||||
#[function_component(MilestoneComponent)]
|
||||
pub fn milestone_component(props: &Props) -> Html {
|
||||
let confirm_service = use_memo(|_| ConfirmService, ());
|
||||
|
||||
let unfilled = props.milestone.goal - props.completed_achievements.min(props.milestone.goal);
|
||||
let filled = props.completed_achievements.min(props.milestone.goal);
|
||||
|
||||
@@ -24,14 +30,32 @@ pub fn milestone_component(props: &Props) -> Html {
|
||||
.take(filled)
|
||||
.collect::<Html>();
|
||||
|
||||
let uuid = props.milestone.uuid;
|
||||
let onclick_delete = Callback::from(move |_| {
|
||||
if !confirm_service.confirm("Are you sure you want to delete?") {
|
||||
return;
|
||||
}
|
||||
log::info!("Delete achievement confirmed.");
|
||||
|
||||
spawn_local(async move {
|
||||
match RestService::delete_milestone(DeleteMilestone { uuid }).await {
|
||||
Ok(_response) => {}
|
||||
Err(_err) => {}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
html! {
|
||||
<div class="row">
|
||||
<p style="text-align: center" class="u-full-width">
|
||||
{format!("{} / {}", props.completed_achievements, props.milestone.goal)}
|
||||
<br />
|
||||
{filled_stars}
|
||||
{unfilled_stars}
|
||||
</p>
|
||||
<div class="row flex">
|
||||
<p style="text-align: center" class="flex-grow">
|
||||
{format!("{} / {}", props.completed_achievements, props.milestone.goal)}
|
||||
<br />
|
||||
{filled_stars}
|
||||
{unfilled_stars}
|
||||
</p>
|
||||
<div class="flex-intrinsic-size">
|
||||
<button onclick={onclick_delete} class="button color-danger"><i class="fas fa-trash"/></button>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user