From 31b720a15cba3674171739f4c87af756a3032171 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Fri, 8 Mar 2024 16:37:46 +0100 Subject: [PATCH] Add button to toggle article protection --- src/frontend/pages/article/actions.rs | 30 ++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/frontend/pages/article/actions.rs b/src/frontend/pages/article/actions.rs index 01fee0e..dad534c 100644 --- a/src/frontend/pages/article/actions.rs +++ b/src/frontend/pages/article/actions.rs @@ -1,5 +1,5 @@ use crate::{ - common::ForkArticleForm, + common::{ForkArticleForm, ProtectArticleForm}, frontend::{ app::GlobalState, article_link, @@ -14,6 +14,7 @@ use leptos_router::Redirect; #[component] pub fn ArticleActions() -> impl IntoView { + let global_state = use_context::>().unwrap(); let article = article_resource(); let (new_title, set_new_title) = create_signal(String::new()); let (fork_response, set_fork_response) = create_signal(Option::::None); @@ -34,8 +35,22 @@ pub fn ArticleActions() -> impl IntoView { } } }); - // TODO: show fork article option (with option to set different title). after forking do redirect - + let protect_action = create_action(move |(id, protected): &(i32, bool)| { + let params = ProtectArticleForm { + article_id: *id, + protected: !protected, + }; + async move { + set_error.update(|e| *e = None); + let result = GlobalState::api_client().protect_article(¶ms).await; + match result { + Ok(_res) => article.refetch(), + Err(err) => { + set_error.update(|e| *e = Some(err.0.to_string())); + } + } + } + }); view! { { @@ -50,6 +65,15 @@ pub fn ArticleActions() -> impl IntoView { view! {

{err}

} }) }} + + +

"Protect a local article so that only admins can edit it"

+