Update dependencies, add translation endpoint, and display a user message when logged in
This commit is contained in:
parent
6b043620b8
commit
348b0f24e9
19 changed files with 170 additions and 34 deletions
|
|
@ -1,7 +1,7 @@
|
|||
use std::str::FromStr;
|
||||
|
||||
use chrono::Locale;
|
||||
use gloo::utils::document;
|
||||
use gloo::utils::{document, window};
|
||||
use wasm_bindgen::prelude::*;
|
||||
use web_sys::Element;
|
||||
|
||||
|
|
@ -133,3 +133,45 @@ pub fn get_locale() -> Locale {
|
|||
.replace("-", "_");
|
||||
Locale::from_str(&lang_and_territory).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Extracts and remove some URL parameters from the current URL.
|
||||
pub fn extract_get_parameters(names: &[&str]) -> Vec<(String, String)> {
|
||||
let mut param_values = vec![];
|
||||
let location = window().location();
|
||||
|
||||
if let Ok(search) = location.search() {
|
||||
if !search.is_empty() && search.starts_with('?') {
|
||||
let mut search_chars = search.chars();
|
||||
search_chars.next(); // To remove the first character which is '?'.
|
||||
let mut new_search = String::with_capacity(search.len());
|
||||
for kv in search_chars.as_str().split('&') {
|
||||
match kv.split('=').collect::<Vec<&str>>()[..] {
|
||||
[key, value] if names.contains(&key) => {
|
||||
param_values.push((key.to_string(), value.to_string()));
|
||||
}
|
||||
_ => {
|
||||
if !new_search.is_empty() {
|
||||
new_search.push('&');
|
||||
}
|
||||
new_search.push_str(kv);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !param_values.is_empty() {
|
||||
let mut new_url = location.pathname().unwrap();
|
||||
if !new_search.is_empty() {
|
||||
new_url.push('?');
|
||||
new_url.push_str(&new_search);
|
||||
}
|
||||
window()
|
||||
.history()
|
||||
.unwrap()
|
||||
.push_state_with_url(&JsValue::null(), "", Some(&new_url))
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
param_values
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue