From b2147b43b1c12b3db0002e0904da47b52e42226a Mon Sep 17 00:00:00 2001 From: PetoMPP Date: Mon, 18 Dec 2023 16:04:49 +0100 Subject: [PATCH 01/18] fix #40: start trunk with --no-autoreload flag --- dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dockerfile b/dockerfile index 33cade8..3b0a30a 100644 --- a/dockerfile +++ b/dockerfile @@ -14,4 +14,4 @@ WORKDIR /front COPY . . RUN npm install -D EXPOSE 8080 -CMD trunk serve --release --address 0.0.0.0 \ No newline at end of file +CMD trunk serve --no-autoreload --release --address 0.0.0.0 \ No newline at end of file From f3b04ed68ea8d316c28b7ecd8e62cccd5739aa72 Mon Sep 17 00:00:00 2001 From: PetoMPP Date: Mon, 18 Dec 2023 16:06:27 +0100 Subject: [PATCH 02/18] fix #31: Avoid substracting from usize equal to 0 in dec_page --- src/components/atoms/resource_select.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/atoms/resource_select.rs b/src/components/atoms/resource_select.rs index ed5c329..0cb8030 100644 --- a/src/components/atoms/resource_select.rs +++ b/src/components/atoms/resource_select.rs @@ -111,10 +111,9 @@ pub fn resource_select(props: &ResourceSelectProps) -> Html { let onselectedchanged_resid = { let props = props.clone(); Callback::from(move |r| { - props.onselectedchanged.emit(ResourceId::from(( - r, - props.lang.unwrap_or_default(), - ))) + props + .onselectedchanged + .emit(ResourceId::from((r, props.lang.unwrap_or_default()))) }) }; let onselectedchanged_lang = { @@ -175,7 +174,8 @@ struct ResourceListProps { fn resource_list(props: &ResourceListProps) -> Html { let (locales_store, _) = use_store::(); let mode: UseStateHandle = use_state_eq(|| { - props.currentresid + props + .currentresid .as_ref() .map(|r| r.into()) .unwrap_or(Mode::Resources) @@ -255,7 +255,7 @@ fn resource_list(props: &ResourceListProps) -> Html { }; let dec_page = { let page = page.clone(); - Callback::from(move |_| page.set((*page - 1).max(0))) + Callback::from(move |_| page.set(page.max(1) - 1)) }; const NEW_INPUT_ID: &str = "new-input-00"; let (_, local_dispatch) = use_store::(); From a62e8d498c6c095041d12f4265f431d1ffc8ceac Mon Sep 17 00:00:00 2001 From: PetoMPP Date: Mon, 18 Dec 2023 16:16:14 +0100 Subject: [PATCH 03/18] fix #37: Parse links correctly in markdown --- src/components/atoms/markdown.rs | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/components/atoms/markdown.rs b/src/components/atoms/markdown.rs index 9fc53db..2dad36d 100644 --- a/src/components/atoms/markdown.rs +++ b/src/components/atoms/markdown.rs @@ -132,10 +132,7 @@ pub fn edit_button(props: &EditButtonProps) -> Html { let (resid, lang) = (props.resid.clone(), locales_store.curr); let edit_onclick = Callback::from(move |_| { navigator - .push_with_query( - &Route::Editor, - &ResourceId::from((resid.clone(), lang)), - ) + .push_with_query(&Route::Editor, &ResourceId::from((resid.clone(), lang))) .unwrap() }); @@ -156,13 +153,20 @@ fn make_links_clickable(navigator: &Navigator, id: &str) { let Some(href) = link.get_attribute("href") else { continue; }; - if let Some(onclick) = Route::get_onclick_from_str(href.as_str(), navigator.clone()) { - link.add_event_listener_with_callback("click", onclick.as_ref().unchecked_ref()) - .unwrap(); - onclick.forget(); - }; - if href.starts_with("http") { - link.set_attribute("target", "_blank").unwrap(); + match href { + href if href.starts_with("http") => link.set_attribute("target", "_blank").unwrap(), + href if href.starts_with("/") => { + if let Some(onclick) = Route::get_onclick_from_str(href.as_str(), navigator.clone()) + { + link.add_event_listener_with_callback( + "click", + onclick.as_ref().unchecked_ref(), + ) + .unwrap(); + onclick.forget(); + } + } + _ => {} } } } From ccb3a23d7535d3e0400d5b356fc76e7a0c77f763 Mon Sep 17 00:00:00 2001 From: PetoMPP Date: Mon, 18 Dec 2023 16:33:25 +0100 Subject: [PATCH 04/18] fix #27: localize missing string in editor --- src/pages/editor.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/pages/editor.rs b/src/pages/editor.rs index 9185a3f..65bd1d4 100644 --- a/src/pages/editor.rs +++ b/src/pages/editor.rs @@ -214,7 +214,7 @@ pub fn editor() -> Html { }, State::Ok(None) => html! {
-

{"Select something to edit!"}

+

{locales_store.get(TK::NothingSelected)}

}, State::Loading => html! { @@ -311,12 +311,14 @@ pub fn editor() -> Html { Some(true) => locales_store.get(TK::Creating), _ => locales_store.get(TK::Editing), }; - let edit_text = match &resid { - Some(ResId::Blob(_)) => locales_store.get(TK::BlogPost), - Some(ResId::ResKey(_)) => locales_store.get(TK::Resource), - None => locales_store.get(TK::NothingSelected), - }; - format!("{}: {}:", edit_pref, edit_text) + match match &resid { + Some(ResId::Blob(_)) => Some(locales_store.get(TK::BlogPost)), + Some(ResId::ResKey(_)) => Some(locales_store.get(TK::Resource)), + None => None, + } { + Some(e) => format!("{}: {}:", edit_pref, e), + None => format!("{}:", edit_pref), + } }; let onchange = Callback::from(move |e: Event| { let element: HtmlInputElement = e.target_unchecked_into(); From 7ac6bfc2a96c1309d5b40b30686ba58b23fa34b4 Mon Sep 17 00:00:00 2001 From: PetoMPP Date: Tue, 19 Dec 2023 16:33:11 +0100 Subject: [PATCH 05/18] resolves #28: Implement page titles --- index.html | 1 - src/components/organisms/markdown_preview.rs | 2 +- src/pages/about.rs | 12 ++- src/pages/admin/admin_panel.rs | 2 +- src/pages/admin/user_management.rs | 2 +- src/pages/blog.rs | 2 +- src/pages/blog_post.rs | 10 +- src/pages/contact.rs | 12 ++- src/pages/editor.rs | 106 +++++++++++-------- src/pages/home.rs | 12 ++- src/pages/login.rs | 5 +- src/pages/not_found.rs | 2 +- src/pages/page_base.rs | 39 ++++++- src/pages/projects.rs | 2 +- src/pages/register.rs | 2 +- 15 files changed, 144 insertions(+), 67 deletions(-) diff --git a/index.html b/index.html index 0c6b1f7..6048fa4 100644 --- a/index.html +++ b/index.html @@ -10,7 +10,6 @@ - PetoMPP.NET \ No newline at end of file diff --git a/src/components/organisms/markdown_preview.rs b/src/components/organisms/markdown_preview.rs index cd6975a..a5fd36a 100644 --- a/src/components/organisms/markdown_preview.rs +++ b/src/components/organisms/markdown_preview.rs @@ -43,7 +43,7 @@ pub fn markdown_preview(props: &MarkdownPreviewProps) -> Html {
- + {meta} diff --git a/src/pages/about.rs b/src/pages/about.rs index 0da8f30..34716e9 100644 --- a/src/pages/about.rs +++ b/src/pages/about.rs @@ -1,10 +1,18 @@ -use crate::{data::resources::id::ResId, pages::page_base::EditablePage}; +use crate::{ + data::{ + locales::{store::LocalesStore, tk::TK}, + resources::id::ResId, + }, + pages::page_base::EditablePage, +}; use yew::prelude::*; +use yewdux::prelude::*; #[function_component(About)] pub fn about() -> Html { const RES_KEY: &str = "about-content"; + let (locales_store, _) = use_store::(); html! { - + } } diff --git a/src/pages/admin/admin_panel.rs b/src/pages/admin/admin_panel.rs index 36c4621..ff63d44 100644 --- a/src/pages/admin/admin_panel.rs +++ b/src/pages/admin/admin_panel.rs @@ -14,6 +14,6 @@ pub fn admin_panel() -> Html { return html! {}; }; html! { - + } } diff --git a/src/pages/admin/user_management.rs b/src/pages/admin/user_management.rs index d49974a..f08151d 100644 --- a/src/pages/admin/user_management.rs +++ b/src/pages/admin/user_management.rs @@ -18,7 +18,7 @@ pub fn user_management() -> Html { }; let (locales_store, _) = use_store::(); html! { - +

{locales_store.get(TK::UserManagement)}

diff --git a/src/pages/blog.rs b/src/pages/blog.rs index ea92f04..333f54a 100644 --- a/src/pages/blog.rs +++ b/src/pages/blog.rs @@ -70,7 +70,7 @@ pub fn blog() -> Html { } }; html! { - + {posts} diff --git a/src/pages/blog_post.rs b/src/pages/blog_post.rs index d6ece4f..cbdd819 100644 --- a/src/pages/blog_post.rs +++ b/src/pages/blog_post.rs @@ -68,12 +68,15 @@ pub fn blog_post(props: &BlogPostProps) -> Html { }, (props.clone(), data.clone(), locales_store.clone()), ); - let (meta, markdown) = match &*data { + let (meta, markdown, title) = match &*data { State::Ok(Some((m, md, _))) => ( html! {}, Some(html! {}), + m.title.clone(), ), - State::Loading | State::Ok(None) => (html! { }, None), + State::Loading | State::Ok(None) => { + (html! { }, None, locales_store.get(TK::Loading)) + } State::Err(e) => { if let Err(redirect) = e.handle_failed_auth(session_dispatch) { return redirect; @@ -86,12 +89,13 @@ pub fn blog_post(props: &BlogPostProps) -> Html { }, None, + locales_store.get(TK::ErrorOccured), ) } }; let onclick = Callback::from(move |_| navigator.push(&Route::Blog)); html! { - + {locales_store.get(TK::BackToBlogPosts)} {meta} diff --git a/src/pages/contact.rs b/src/pages/contact.rs index 3bd7730..15e6866 100644 --- a/src/pages/contact.rs +++ b/src/pages/contact.rs @@ -1,10 +1,18 @@ -use crate::{data::resources::id::ResId, pages::page_base::EditablePage}; +use crate::{ + data::{ + locales::{store::LocalesStore, tk::TK}, + resources::id::ResId, + }, + pages::page_base::EditablePage, +}; use yew::prelude::*; +use yewdux::prelude::*; #[function_component(Contact)] pub fn contact() -> Html { const RES_KEY: &str = "contact-content"; + let (locales_store, _) = use_store::(); html! { - + } } diff --git a/src/pages/editor.rs b/src/pages/editor.rs index 65bd1d4..8da11d6 100644 --- a/src/pages/editor.rs +++ b/src/pages/editor.rs @@ -184,52 +184,74 @@ pub fn editor() -> Html { return redirect; } } - let editor = match &*state { - State::Ok(Some((_, (resid, lang), (value, meta)))) => match &*is_preview { - true => { - html! {} - } - false => { - let onchanged = { - let local_dispatch = local_dispatch.clone(); - let resid = resid.clone(); - let lang = *lang; - let meta = meta.clone(); - Callback::from(move |data: String| { - local_dispatch.reduce_mut(|store| { - if let Some((value, _)) = store.get_mut(&resid, lang.key()) { - *value = data.clone(); - } else { - store.insert(resid.clone(), lang.key(), data.clone(), meta.clone()); - } - }); - }) - }; - html! { -
- -
+ let (editor, title) = match &*state { + State::Ok(Some((is_new, (resid, lang), (value, meta)))) => { + let editor = match &*is_preview { + true => { + html! {} } - } - }, - State::Ok(None) => html! { -
-

{locales_store.get(TK::NothingSelected)}

-
- }, - State::Loading => html! { - - }, + false => { + let onchanged = { + let local_dispatch = local_dispatch.clone(); + let resid = resid.clone(); + let lang = *lang; + let meta = meta.clone(); + Callback::from(move |data: String| { + local_dispatch.reduce_mut(|store| { + if let Some((value, _)) = store.get_mut(&resid, lang.key()) { + *value = data.clone(); + } else { + store.insert( + resid.clone(), + lang.key(), + data.clone(), + meta.clone(), + ); + } + }); + }) + }; + html! { +
+ +
+ } + } + }; + let action = match is_new.unwrap_or_default() { + true => locales_store.get(TK::Creating), + false => locales_store.get(TK::Editing), + }; + (editor, format!("{}: {}", action, resid.id())) + } + State::Ok(None) => { + let text = locales_store.get(TK::NothingSelected); + let editor = html! { +
+

{&text}

+
+ }; + (editor, text) + } + State::Loading => ( + html! { + + }, + locales_store.get(TK::Loading), + ), State::Err(e) => { if let Err(redirect) = e.handle_failed_auth(session_dispatch) { return redirect; } - html! { -
-

{locales_store.get(TK::ErrorOccured)}

-

{e.to_string()}

-
- } + ( + html! { +
+

{locales_store.get(TK::ErrorOccured)}

+

{e.to_string()}

+
+ }, + String::new(), + ) } }; let reload = match &*state { @@ -343,7 +365,7 @@ pub fn editor() -> Html { }); html! { - +

{edit_text}

diff --git a/src/pages/home.rs b/src/pages/home.rs index 3324b22..cf4aa10 100644 --- a/src/pages/home.rs +++ b/src/pages/home.rs @@ -1,10 +1,18 @@ -use crate::{data::resources::id::ResId, pages::page_base::EditablePage}; +use crate::{ + data::{ + locales::{store::LocalesStore, tk::TK}, + resources::id::ResId, + }, + pages::page_base::EditablePage, +}; use yew::prelude::*; +use yewdux::prelude::*; #[function_component(Home)] pub fn home() -> Html { const RES_KEY: &str = "home-content"; + let (locales_store, _) = use_store::(); html! { - + } } diff --git a/src/pages/login.rs b/src/pages/login.rs index 2915a58..9063a48 100644 --- a/src/pages/login.rs +++ b/src/pages/login.rs @@ -1,5 +1,3 @@ -use std::collections::BTreeMap; - use crate::{ api::{self, client::ApiClient}, async_event, @@ -15,6 +13,7 @@ use crate::{ router::route::Route, }; use petompp_web_models::models::credentials::Credentials; +use std::collections::BTreeMap; use yew::prelude::*; use yew_router::prelude::*; use yewdux::prelude::use_store; @@ -97,7 +96,7 @@ pub fn login() -> Html { ) }; html! { - +