From 82baa40794fa78ba37324e65634737c2a194b89b Mon Sep 17 00:00:00 2001 From: trisua Date: Thu, 28 Nov 2024 22:23:20 -0500 Subject: [PATCH] add: language switcher add(langs/en-US): sessions settings, profile settings, privacy settings, login, sign up --- crates/langbeam/src/lib.rs | 2 +- crates/rainbeam-core/src/config.rs | 2 +- crates/rainbeam/src/routing/api/util.rs | 27 +++- crates/rainbeam/templates/auth/login.html | 20 ++- crates/rainbeam/templates/auth/sign_up.html | 22 +++- crates/rainbeam/templates/base.html | 88 +++++++------- crates/rainbeam/templates/homepage.html | 6 +- .../rainbeam/templates/settings/account.html | 4 + .../settings/components/lang_picker.html | 26 ++++ .../settings/components/privacy_options.html | 32 +++-- .../settings/components/profile_options.html | 115 +++++++----------- .../rainbeam/templates/settings/sessions.html | 30 +++-- langs/en-US.json | 53 +++++++- 13 files changed, 266 insertions(+), 161 deletions(-) create mode 100644 crates/rainbeam/templates/settings/components/lang_picker.html diff --git a/crates/langbeam/src/lib.rs b/crates/langbeam/src/lib.rs index 37a202e0..b5a071f8 100644 --- a/crates/langbeam/src/lib.rs +++ b/crates/langbeam/src/lib.rs @@ -12,7 +12,7 @@ pub struct LangFile { impl Default for LangFile { fn default() -> Self { Self { - name: "net.rainbeam.langs:aa-BB".to_string(), + name: "net.rainbeam.langs.testing:aa-BB".to_string(), version: "0.0.0".to_string(), data: HashMap::new(), } diff --git a/crates/rainbeam-core/src/config.rs b/crates/rainbeam-core/src/config.rs index a9bb42f9..114066bd 100644 --- a/crates/rainbeam-core/src/config.rs +++ b/crates/rainbeam-core/src/config.rs @@ -12,7 +12,7 @@ pub struct Tiers { /// /// * Questions: ~~2048~~ **4096** /// * Responses: ~~4096~~ **8192** - /// * CommentS: ~~2048~~ **4096** + /// * Comments: ~~2048~~ **4096** /// /// *\*Carpgraph drawings stay at 32kb maximum* #[serde(default)] diff --git a/crates/rainbeam/src/routing/api/util.rs b/crates/rainbeam/src/routing/api/util.rs index 40b0cfbf..a9bbd290 100644 --- a/crates/rainbeam/src/routing/api/util.rs +++ b/crates/rainbeam/src/routing/api/util.rs @@ -4,7 +4,8 @@ use askama_axum::IntoResponse; use axum::{ body::Body, extract::{Query, State}, - routing::get, + http::HeaderMap, + routing::{get, post}, Json, Router, }; use serde::{Deserialize, Serialize}; @@ -12,6 +13,7 @@ use serde::{Deserialize, Serialize}; pub fn routes(database: Database) -> Router { Router::new() .route("/lang", get(langfile_request)) + .route("/lang/set", post(set_langfile_request)) .route("/ext/image", get(external_image_request)) // ... .with_state(database.clone()) @@ -117,3 +119,26 @@ pub async fn langfile_request( ) -> impl IntoResponse { Json(database.lang(&props.id)) } + +/// Set a langfile +pub async fn set_langfile_request(Query(props): Query) -> impl IntoResponse { + ( + { + let mut headers = HeaderMap::new(); + + headers.insert( + "Set-Cookie", + format!( + "net.rainbeam.langs.choice={}; SameSite=Lax; Secure; Path=/; HostOnly=true; HttpOnly=true; Max-Age={}", + props.id, + 60* 60 * 24 * 365 + ) + .parse() + .unwrap(), + ); + + headers + }, + "Language changed", + ) +} diff --git a/crates/rainbeam/templates/auth/login.html b/crates/rainbeam/templates/auth/login.html index 8e6c7520..efd3697a 100644 --- a/crates/rainbeam/templates/auth/login.html +++ b/crates/rainbeam/templates/auth/login.html @@ -15,12 +15,14 @@ >
-

Login

+

{{ text "auth:login.html:title.login" }}

- + Login
- + Login
- +

- Don't have an account? - Sign Up + {{ text "auth:login.html:text.no_account" }} + {{ text "general:link.sign_up" }}

diff --git a/crates/rainbeam/templates/auth/sign_up.html b/crates/rainbeam/templates/auth/sign_up.html index 8dd1ed12..6d5a7a71 100644 --- a/crates/rainbeam/templates/auth/sign_up.html +++ b/crates/rainbeam/templates/auth/sign_up.html @@ -15,12 +15,16 @@ >
-

Sign Up

+

+ {{ text "auth:sign_up.html:title.sign_up" }} +

- + Sign Up
- + Sign Up
- +

- Already have an account? - Login + {{ text "auth:sign_up.html:text.has_account" }} + {{ text "general:link.login" }}

diff --git a/crates/rainbeam/templates/base.html b/crates/rainbeam/templates/base.html index d1291172..61d5b388 100644 --- a/crates/rainbeam/templates/base.html +++ b/crates/rainbeam/templates/base.html @@ -223,13 +223,13 @@ {{ profile.username }} - {{ icon "circle-user-round" }} {{ - text "general:link.show_profile" }} + {{ icon "circle-user-round" }} {{ text + "general:link.show_profile" }} - {{ icon "settings" }} {{ - text "general:link.settings" }} + {{ icon "settings" }} {{ text + "general:link.settings" }} - {{ icon "message-circle-more" }} {{ - text "general:service.chats" }} + {{ icon "message-circle-more" }} {{ text + "general:service.chats" }} {{ icon "mails" }} {{ - text "general:service.mail" }}{{ icon "mails" }} {{ text + "general:service.mail" }} - {{ icon "users-round" }} {{ - text "general:service.circles" }} + {{ icon "users-round" }} {{ text + "general:service.circles" }} - {{ icon "book-user" }} {{ - text "general:link.friends" }} + {{ icon "book-user" }} {{ text + "general:link.friends" }} - {{ icon "user-round-plus" }} {{ - text "general:link.requests" }} + {{ icon "user-round-plus" }} {{ text + "general:link.requests" }} {% else %} - {{ icon "log-in" }} {{ - text "general:link.login" }} + {{ icon "log-in" }} {{ text "general:link.login" + }} - {{ icon "user-round-plus" }} {{ - text "base.html:link.sign_up" }} + {{ icon "user-round-plus" }} {{ text + "general:link.sign_up" }} {% endif %} @@ -290,19 +290,19 @@ {{ config.name }} - {{ icon "info" }} {{ - text "base.html:link.about" }} + {{ icon "info" }} {{ text "base.html:link.about" + }} - {{ icon "book" }} {{ - text "base.html:link.reference" }} + {{ icon "book" }} {{ text + "base.html:link.reference" }} - {{ icon "search" }} {{ - text "general:link.search" }} + {{ icon "search" }} {{ text + "general:link.search" }} {% if profile.is_some() %} @@ -312,8 +312,8 @@ onclick="trigger('app:logout')" class="red" > - {{ icon "log-out" }} {{ - text "base.html:link.sign_out" }} + {{ icon "log-out" }} {{ text + "base.html:link.sign_out" }} {% endif %}
@@ -388,13 +388,12 @@ Actions - {{ icon "square-pen" }} {{ - text "general:link.post" }} + {{ icon "square-pen" }} {{ text "general:link.post" + }} - {{ icon "search" }} {{ - text "general:link.search" }} + {{ icon "search" }} {{ text "general:link.search" }} @@ -402,13 +401,12 @@ Services - {{ icon "message-circle-more" }} {{ - text "general:service.chats" }} + {{ icon "message-circle-more" }} {{ text + "general:service.chats" }} - {{ icon "mails" }} {{ - text "general:service.mail" }} + {{ icon "mails" }} {{ text "general:service.mail" }} {% endif %} @@ -417,16 +415,15 @@ Site - {{ icon "info" }} {{ - text "base.html:link.about" }} + {{ icon "info" }} {{ text "base.html:link.about" }} - {{ icon "code" }} {{ - text "base.html:link.source_code" }} + {{ icon "code" }} {{ text + "base.html:link.source_code" }} @@ -553,8 +550,8 @@ onclick="globalThis.web_api_prompt_submit(document.getElementById('prompt').value); document.getElementById('prompt').value = ''" type="buton" > - {{ icon "check" }} {{ - text "general:dialog.okay" }} + {{ icon "check" }} {{ text "general:dialog.okay" + }} @@ -590,8 +587,8 @@ onclick="globalThis.web_api_confirm_submit(true)" type="buton" > - {{ icon "check" }} {{ - text "general:dialog.yes" }} + {{ icon "check" }} {{ text "general:dialog.yes" + }} diff --git a/crates/rainbeam/templates/homepage.html b/crates/rainbeam/templates/homepage.html index 39c84883..ba07e562 100644 --- a/crates/rainbeam/templates/homepage.html +++ b/crates/rainbeam/templates/homepage.html @@ -28,8 +28,8 @@

data-turbo="false" style="gap: 1rem !important" > - {{ icon "user-round-plus" }} {{ - text "homepage.html:link.create_account" }} + {{ icon "user-round-plus" }} {{ text + "homepage.html:link.create_account" }} > {{ icon "smile" }} {{ text "general:link.login" }} + + {% include "settings/components/lang_picker.html" %} diff --git a/crates/rainbeam/templates/settings/account.html b/crates/rainbeam/templates/settings/account.html index bf1730b7..d0a7d00e 100644 --- a/crates/rainbeam/templates/settings/account.html +++ b/crates/rainbeam/templates/settings/account.html @@ -6,6 +6,10 @@ {% endblock %} {% block panel %}
+

{{ text "settings:account.html:title.language" }}

+ + {% include "components/lang_picker.html" %} +

{{ text "settings:account.html:title.local_theming" }}

diff --git a/crates/rainbeam/templates/settings/components/lang_picker.html b/crates/rainbeam/templates/settings/components/lang_picker.html new file mode 100644 index 00000000..66c9769c --- /dev/null +++ b/crates/rainbeam/templates/settings/components/lang_picker.html @@ -0,0 +1,26 @@ + + + diff --git a/crates/rainbeam/templates/settings/components/privacy_options.html b/crates/rainbeam/templates/settings/components/privacy_options.html index 4b61faef..2ab6d950 100644 --- a/crates/rainbeam/templates/settings/components/privacy_options.html +++ b/crates/rainbeam/templates/settings/components/privacy_options.html @@ -1,5 +1,7 @@
-

General Privacy

+

+ {{ text "settings:privacy_options.html:title.general_privacy" }} +

General Privacy

/> @@ -28,7 +31,8 @@

General Privacy

/> @@ -42,7 +46,9 @@

General Privacy

/> @@ -56,7 +62,7 @@

General Privacy

/> @@ -69,13 +75,18 @@

General Privacy

/> -

Moderation

+

+ {{ text "settings:privacy_options.html:title.moderation" }} +

- +

- A list of strings that are not allowed in questions asked to you. - Each different string - must - be on a new line. + {{ text "settings:privacy_options.html:text.filter" }}

diff --git a/crates/rainbeam/templates/settings/components/profile_options.html b/crates/rainbeam/templates/settings/components/profile_options.html index 66170203..e8975008 100644 --- a/crates/rainbeam/templates/settings/components/profile_options.html +++ b/crates/rainbeam/templates/settings/components/profile_options.html @@ -1,7 +1,11 @@
-

About Me

+

+ {{ text "settings:profile_options.html:title.about_me" }} +

- + About Me
-