From 68f7f31b8ec04b0eed2bf1a887c43f47fb8f3ef2 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Wed, 16 Oct 2024 16:40:32 +0200 Subject: [PATCH] wip2 --- src/frontend/components/article_nav.rs | 73 ++++++++++++++++++++++---- src/frontend/components/credentials.rs | 5 +- src/frontend/components/nav.rs | 28 +++++----- src/frontend/mod.rs | 6 ++- src/frontend/pages/article/actions.rs | 29 +++++----- src/frontend/pages/article/edit.rs | 25 ++++----- src/frontend/pages/article/history.rs | 53 +++++++++---------- src/frontend/pages/article/list.rs | 10 ++-- src/frontend/pages/article/read.rs | 13 +++-- src/frontend/pages/diff.rs | 4 +- 10 files changed, 152 insertions(+), 94 deletions(-) diff --git a/src/frontend/components/article_nav.rs b/src/frontend/components/article_nav.rs index b4432d4..ef68a9a 100644 --- a/src/frontend/components/article_nav.rs +++ b/src/frontend/components/article_nav.rs @@ -3,20 +3,34 @@ use crate::{ frontend::{ app::GlobalState, article_link, + article_title, components::instance_follow_button::InstanceFollowButton, }, }; use leptos::*; use leptos_router::*; +pub enum ActiveTab { + Read, + History, + Edit, + Actions, +} + #[component] -pub fn ArticleNav(article: Resource, ArticleView>) -> impl IntoView { +pub fn ArticleNav( + article: Resource, ArticleView>, + active_tab: ActiveTab, +) -> impl IntoView { + let tab_classes = tab_classes(&active_tab); + view! { {move || { article .get() .map(|article_| { + let title = article_title(&article_.article); let instance = create_local_resource( move || article_.article.instance_id, move |instance_id| async move { @@ -32,8 +46,12 @@ pub fn ArticleNav(article: Resource, ArticleView>) -> impl IntoVi let protected = article_.article.protected; view! {
- "Read" - "History" + + "Read" + + + "History" + , ArticleView>) -> impl IntoVi && can_edit_article(&article_.article, is_admin).is_ok() }) }> - "Edit" + + "Edit" + - "Actions" + + "Actions" + {instance .get() .map(|i| { @@ -61,12 +86,15 @@ pub fn ArticleNav(article: Resource, ArticleView>) -> impl IntoVi })} - - - "Protected" - -
+
+

{title}

+ + + "Protected" + + +
} }) }} @@ -74,3 +102,28 @@ pub fn ArticleNav(article: Resource, ArticleView>) -> impl IntoVi
} } + +struct ActiveTabClasses { + read: &'static str, + history: &'static str, + edit: &'static str, + actions: &'static str, +} + +fn tab_classes(active_tab: &ActiveTab) -> ActiveTabClasses { + const TAB_INACTIVE: &str = "tab"; + const TAB_ACTIVE: &str = "tab tab-active"; + let mut classes = ActiveTabClasses { + read: TAB_INACTIVE, + history: TAB_INACTIVE, + edit: TAB_INACTIVE, + actions: TAB_INACTIVE, + }; + match active_tab { + ActiveTab::Read => classes.read = TAB_ACTIVE, + ActiveTab::History => classes.history = TAB_ACTIVE, + ActiveTab::Edit => classes.edit = TAB_ACTIVE, + ActiveTab::Actions => classes.actions = TAB_ACTIVE, + } + classes +} diff --git a/src/frontend/components/credentials.rs b/src/frontend/components/credentials.rs index b9af707..cecebec 100644 --- a/src/frontend/components/credentials.rs +++ b/src/frontend/components/credentials.rs @@ -24,12 +24,13 @@ pub fn CredentialsForm( error .get() .map(|err| { - view! {

{err}

} + view! {

{err}

} }) }} + } } diff --git a/src/frontend/mod.rs b/src/frontend/mod.rs index f85c740..ad2be2c 100644 --- a/src/frontend/mod.rs +++ b/src/frontend/mod.rs @@ -52,7 +52,11 @@ fn user_link(person: &DbPerson) -> impl IntoView { extract_domain(&person.ap_id) ) }; - view! { {user_title(person)} } + view! { + + {user_title(person)} + + } } fn render_date_time(date_time: DateTime) -> String { diff --git a/src/frontend/pages/article/actions.rs b/src/frontend/pages/article/actions.rs index cf7e776..53e1c9b 100644 --- a/src/frontend/pages/article/actions.rs +++ b/src/frontend/pages/article/actions.rs @@ -3,8 +3,7 @@ use crate::{ frontend::{ app::GlobalState, article_link, - article_title, - components::article_nav::ArticleNav, + components::article_nav::{ActiveTab, ArticleNav}, pages::article_resource, DbArticle, }, @@ -52,7 +51,7 @@ pub fn ArticleActions() -> impl IntoView { } }); view! { - + @@ -61,16 +60,14 @@ pub fn ArticleActions() -> impl IntoView { .get() .map(|article| { view! { -
-

{article_title(&article.article)}

+
{move || { error .get() .map(|err| { - view! {

{err}

} + view! {

{err}

} }) }} - impl IntoView { .unwrap_or_default() && article.article.local }) }> - +

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

-
- + impl IntoView { /> - +
-
-
+
Markdown " formatting is supported" -
-
+
impl IntoView { />