Added delete project functionality. Now it works
This commit is contained in:
parent
bb0e759d2e
commit
ba1a954537
@ -209,6 +209,20 @@ pub async fn update_project(project: UpdateProjectPayload) -> Result<Project, er
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn delete_project(project_id: &Uuid) -> Result<(), err::Error> {
|
||||
perform_request_without_client::<String, ()>(
|
||||
BASE_URL.into(),
|
||||
Method::DELETE,
|
||||
format!("admin/project/{project_id}"),
|
||||
None,
|
||||
200,
|
||||
Vec::new(),
|
||||
None,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
|
||||
pub async fn upload_image(item: Item, body: Vec<u8>) -> Result<String, err::Error> {
|
||||
perform_multipart_request_without_client(
|
||||
BASE_URL.into(),
|
||||
|
@ -4,7 +4,7 @@ use yew_router::prelude::use_navigator;
|
||||
|
||||
use crate::{
|
||||
pages::admin::edit::{EditItem, EditType},
|
||||
routes::main_router::Route,
|
||||
routes::main_router::Route, api::backend::delete_project,
|
||||
};
|
||||
|
||||
#[function_component(AdminProject)]
|
||||
@ -14,9 +14,18 @@ pub fn admin_project(props: &AdminProjectProps) -> Html {
|
||||
let is_attempting_delete = use_state(|| false);
|
||||
let delete_project = {
|
||||
let is_attempting_delete = is_attempting_delete.clone();
|
||||
let project_id = props.project.id.clone();
|
||||
let force_update_handle = props.forceupdate.clone();
|
||||
Callback::from(move |event: MouseEvent| {
|
||||
if *is_attempting_delete {
|
||||
// Call delete
|
||||
let project_id = project_id.clone();
|
||||
let force_update_handle = force_update_handle.clone();
|
||||
wasm_bindgen_futures::spawn_local(async move {
|
||||
match delete_project(&project_id).await {
|
||||
Ok(_) => {force_update_handle.emit(())},
|
||||
Err(error) => {log::error!("Error deleting project: {error}")}
|
||||
};
|
||||
});
|
||||
is_attempting_delete.set(false);
|
||||
} else {
|
||||
is_attempting_delete.set(true);
|
||||
@ -68,4 +77,5 @@ pub fn admin_project(props: &AdminProjectProps) -> Html {
|
||||
pub struct AdminProjectProps {
|
||||
pub project: ProjectCardDto,
|
||||
pub index: usize,
|
||||
pub forceupdate: Callback<()>,
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ use crate::{
|
||||
#[function_component(AdminProjects)]
|
||||
pub fn admin_projects() -> Html {
|
||||
let projects = use_state(|| Vec::new());
|
||||
|
||||
let force_update_handle = use_force_update();
|
||||
use_state(|| {
|
||||
let projects_handle = projects.clone();
|
||||
wasm_bindgen_futures::spawn_local(async move {
|
||||
@ -25,7 +25,7 @@ pub fn admin_projects() -> Html {
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
html! {
|
||||
<>
|
||||
<AdminNavigationBar/>
|
||||
@ -37,7 +37,11 @@ pub fn admin_projects() -> Html {
|
||||
<div class={"admin-navbar-divider"}></div>
|
||||
{(*projects).clone().into_iter().enumerate().map(|(key, project)| html! {
|
||||
<>
|
||||
<AdminProject project={project} index={key}/>
|
||||
<AdminProject project={project} index={key} forceupdate={
|
||||
let force_update_handle = force_update_handle.clone();
|
||||
Callback::from(move |_| {
|
||||
force_update_handle.force_update()
|
||||
})}/>
|
||||
<div class={"admin-navbar-divider"}></div>
|
||||
</>
|
||||
}).collect::<Html>()}
|
||||
|
Loading…
Reference in New Issue
Block a user