fix: take into account cookie in js

This commit is contained in:
Anna 2021-10-10 13:42:33 -04:00
parent 1d67debfd0
commit 1a3cecabe5
4 changed files with 23 additions and 4 deletions

View File

@ -42,8 +42,8 @@ body {
}
.no-js .requires-js {
display: none;
visibility: hidden;
display: none !important;
visibility: hidden !important;
}
details {

View File

@ -5,7 +5,7 @@
allowed: [],
centre: 'All',
list: null,
lang: 'en',
lang: null,
};
function addJsClass() {
@ -62,6 +62,16 @@
dataCentre.value = state.centre;
let language = document.getElementById('language');
if (state.lang === null) {
state.lang = language.dataset.accept;
let cookie = document.cookie
.split(';')
.find(row => row.trim().startsWith('lang='));
if (cookie !== undefined) {
state.lang = decodeURIComponent(cookie.split('=')[1]);
}
}
language.value = state.lang;
}

View File

@ -30,6 +30,15 @@ pub enum Language {
}
impl Language {
pub fn code(&self) -> &'static str {
match self {
Self::English => "en",
Self::Japanese => "ja",
Self::German => "de",
Self::French => "fr",
}
}
pub fn from_codes(val: Option<&str>) -> Self {
let val = match val {
Some(v) => v,

View File

@ -52,7 +52,7 @@ Remote Party Finder
</details>
</div>
<div class="right">
<select id="language">
<select id="language" data-accept="{{ lang.code() }}">
<option value="en">English</option>
<option value="ja">日本語</option>
<option value="de">Deutsch</option>