Skip to content

Commit

Permalink
add: language switcher
Browse files Browse the repository at this point in the history
add(langs/en-US): sessions settings, profile settings, privacy settings, login, sign up
  • Loading branch information
trisuaso committed Nov 29, 2024
1 parent 7e7eec9 commit 82baa40
Show file tree
Hide file tree
Showing 13 changed files with 266 additions and 161 deletions.
2 changes: 1 addition & 1 deletion crates/langbeam/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
Expand Down
2 changes: 1 addition & 1 deletion crates/rainbeam-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
27 changes: 26 additions & 1 deletion crates/rainbeam/src/routing/api/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ use askama_axum::IntoResponse;
use axum::{
body::Body,
extract::{Query, State},
routing::get,
http::HeaderMap,
routing::{get, post},
Json, Router,
};
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())
Expand Down Expand Up @@ -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<LangFileQuery>) -> 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",
)
}
20 changes: 14 additions & 6 deletions crates/rainbeam/templates/auth/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
></div>

<div id="forms" class="flex flex-col gap-2 items-center">
<h3 class="no-margin">Login</h3>
<h3 class="no-margin">{{ text "auth:login.html:title.login" }}</h3>

<div class="card" style="width: 25rem">
<form id="login_form" class="flex flex-col gap-2">
<div class="row flex flex-col gap-1">
<label for="username">Username</label>
<label for="username"
>{{ text "auth:label.username" }}</label
>
<input
type="text"
name="username"
Expand All @@ -32,7 +34,9 @@ <h3 class="no-margin">Login</h3>
</div>

<div class="row flex flex-col gap-1">
<label for="password">Password</label>
<label for="password"
>{{ text "auth:label.password" }}</label
>
<input
type="password"
name="password"
Expand All @@ -49,13 +53,17 @@ <h3 class="no-margin">Login</h3>

<hr />

<button class="primary bold">Login</button>
<button class="primary bold">
{{ text "general:link.login" }}
</button>
</form>
</div>

<p>
Don't have an account?
<a href="/sign_up" data-turbo="false">Sign Up</a>
{{ text "auth:login.html:text.no_account" }}
<a href="/sign_up" data-turbo="false"
>{{ text "general:link.sign_up" }}</a
>
</p>
</div>

Expand Down
22 changes: 16 additions & 6 deletions crates/rainbeam/templates/auth/sign_up.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@
></div>

<div id="forms" class="flex flex-col gap-2 items-center">
<h3 class="no-margin">Sign Up</h3>
<h3 class="no-margin">
{{ text "auth:sign_up.html:title.sign_up" }}
</h3>

<div class="card" style="width: 25rem">
<form id="register_form" class="flex flex-col gap-2">
<div class="row flex flex-col gap-1">
<label for="username">Username</label>
<label for="username"
>{{ text "auth:label.username" }}</label
>
<input
type="text"
name="username"
Expand All @@ -32,7 +36,9 @@ <h3 class="no-margin">Sign Up</h3>
</div>

<div class="row flex flex-col gap-1">
<label for="password">Password</label>
<label for="password"
>{{ text "auth:label.password" }}</label
>
<input
type="password"
name="password"
Expand All @@ -49,13 +55,17 @@ <h3 class="no-margin">Sign Up</h3>

<hr />

<button class="primary bold">Register</button>
<button class="primary bold">
{{ text "general:link.sign_up" }}
</button>
</form>
</div>

<p>
Already have an account?
<a href="/login" data-turbo="false">Login</a>
{{ text "auth:sign_up.html:text.has_account" }}
<a href="/login" data-turbo="false"
>{{ text "general:link.login" }}</a
>
</p>
</div>

Expand Down
88 changes: 42 additions & 46 deletions crates/rainbeam/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -223,32 +223,32 @@
<b class="title">{{ profile.username }}</b>

<a href="/@{{ profile.username }}">
{{ icon "circle-user-round" }} {{
text "general:link.show_profile" }}
{{ icon "circle-user-round" }} {{ text
"general:link.show_profile" }}
</a>

<a href="/settings">
{{ icon "settings" }} {{
text "general:link.settings" }}
{{ icon "settings" }} {{ text
"general:link.settings" }}
</a>

<b class="title"
>{{ text "general:title.services" }}</b
>

<a href="/chats">
{{ icon "message-circle-more" }} {{
text "general:service.chats" }}
{{ icon "message-circle-more" }} {{ text
"general:service.chats" }}
</a>

<a href="/inbox/mail"
>{{ icon "mails" }} {{
text "general:service.mail" }}</a
>{{ icon "mails" }} {{ text
"general:service.mail" }}</a
>

<a href="/circles">
{{ icon "users-round" }} {{
text "general:service.circles" }}
{{ icon "users-round" }} {{ text
"general:service.circles" }}
</a>

<b class="title"
Expand All @@ -259,50 +259,50 @@
href="/@{{ profile.username }}/friends"
title="My friends"
>
{{ icon "book-user" }} {{
text "general:link.friends" }}
{{ icon "book-user" }} {{ text
"general:link.friends" }}
</a>

<a
href="/@{{ profile.username }}/friends/requests"
title="My friend requests"
>
{{ icon "user-round-plus" }} {{
text "general:link.requests" }}
{{ icon "user-round-plus" }} {{ text
"general:link.requests" }}
</a>
{% else %}
<b class="title"
>{{ text "general:title.account" }}</b
>

<a href="/login" data-turbo="false">
{{ icon "log-in" }} {{
text "general:link.login" }}
{{ icon "log-in" }} {{ text "general:link.login"
}}
</a>

<a href="/sign_up" data-turbo="false">
{{ icon "user-round-plus" }} {{
text "base.html:link.sign_up" }}
{{ icon "user-round-plus" }} {{ text
"general:link.sign_up" }}
</a>
{% endif %}

<!-- site stuff -->
<b class="title">{{ config.name }}</b>

<a href="/site/about">
{{ icon "info" }} {{
text "base.html:link.about" }}
{{ icon "info" }} {{ text "base.html:link.about"
}}
</a>

<a href="https://swmff.github.io/rainbeam/">
{{ icon "book" }} {{
text "base.html:link.reference" }}
{{ icon "book" }} {{ text
"base.html:link.reference" }}
</a>

<!-- ... -->
<a href="/search">
{{ icon "search" }} {{
text "general:link.search" }}
{{ icon "search" }} {{ text
"general:link.search" }}
</a>

{% if profile.is_some() %}
Expand All @@ -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" }}
</a>
{% endif %}
</div>
Expand Down Expand Up @@ -388,27 +388,25 @@
<b class="header">Actions</b>

<a href="/intents/post" class="button camo">
{{ icon "square-pen" }} {{
text "general:link.post" }}
{{ icon "square-pen" }} {{ text "general:link.post"
}}
</a>

<a href="/search" class="button camo">
{{ icon "search" }} {{
text "general:link.search" }}
{{ icon "search" }} {{ text "general:link.search" }}
</a>
</section>

<section class="fade">
<b class="header">Services</b>

<a href="/chats" class="button camo">
{{ icon "message-circle-more" }} {{
text "general:service.chats" }}
{{ icon "message-circle-more" }} {{ text
"general:service.chats" }}
</a>

<a href="/inbox/mail" class="button camo">
{{ icon "mails" }} {{
text "general:service.mail" }}
{{ icon "mails" }} {{ text "general:service.mail" }}
</a>
</section>
{% endif %}
Expand All @@ -417,16 +415,15 @@
<b class="header">Site</b>

<a href="/site/about" class="button camo">
{{ icon "info" }} {{
text "base.html:link.about" }}
{{ icon "info" }} {{ text "base.html:link.about" }}
</a>

<a
href="https://github.com/swmff/rainbeam"
class="button camo"
>
{{ icon "code" }} {{
text "base.html:link.source_code" }}
{{ icon "code" }} {{ text
"base.html:link.source_code" }}
</a>
</section>
</div>
Expand Down Expand Up @@ -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"
}}
</button>

<button
Expand All @@ -563,8 +560,8 @@
type="button"
title="Close"
>
{{ icon "x" }} {{
text "general:dialog.cancel" }}
{{ icon "x" }} {{ text "general:dialog.cancel"
}}
</button>
</div>
</div>
Expand All @@ -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"
}}
</button>

<button
Expand All @@ -600,8 +597,7 @@
type="button"
title="Close"
>
{{ icon "x" }} {{ text "general:dialog.no"
}}
{{ icon "x" }} {{ text "general:dialog.no" }}
</button>
</div>
</div>
Expand Down
6 changes: 4 additions & 2 deletions crates/rainbeam/templates/homepage.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ <h3 style="font-weight: normal; margin-top: 0">
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" }}
</a>

<a
Expand All @@ -40,6 +40,8 @@ <h3 style="font-weight: normal; margin-top: 0">
>
{{ icon "smile" }} {{ text "general:link.login" }}
</a>

{% include "settings/components/lang_picker.html" %}
</div>
</div>
</main>
Expand Down
Loading

0 comments on commit 82baa40

Please sign in to comment.