* Support for lang in URL as /fr/recipe/view/42
* Create a pages module in the frontend crate
This commit is contained in:
parent
b812525f4b
commit
418d31a127
12 changed files with 117 additions and 80 deletions
|
|
@ -9,12 +9,10 @@ use crate::utils::selector;
|
|||
|
||||
mod calendar;
|
||||
mod error;
|
||||
mod home;
|
||||
mod modal_dialog;
|
||||
mod on_click;
|
||||
mod recipe_edit;
|
||||
mod pages;
|
||||
mod recipe_scheduler;
|
||||
mod recipe_view;
|
||||
mod request;
|
||||
mod shopping_list;
|
||||
mod toast;
|
||||
|
|
@ -24,8 +22,14 @@ mod utils;
|
|||
pub fn main() -> Result<(), JsValue> {
|
||||
console_error_panic_hook::set_once();
|
||||
|
||||
let lang = utils::get_current_lang();
|
||||
|
||||
let location = window().location().pathname()?;
|
||||
let path: Vec<&str> = location.split('/').skip(1).collect();
|
||||
let path: Vec<&str> = location
|
||||
.split('/')
|
||||
.skip(1)
|
||||
.skip_while(|part| *part == lang)
|
||||
.collect();
|
||||
|
||||
let is_user_logged = selector::<HtmlElement>("html")
|
||||
.dataset()
|
||||
|
|
@ -36,14 +40,14 @@ pub fn main() -> Result<(), JsValue> {
|
|||
match path[..] {
|
||||
["recipe", "edit", id] => {
|
||||
let id = id.parse::<i64>().unwrap(); // TODO: remove unwrap.
|
||||
recipe_edit::setup_page(id)
|
||||
pages::recipe_edit::setup_page(id)
|
||||
}
|
||||
["recipe", "view", id] => {
|
||||
let id = id.parse::<i64>().unwrap(); // TODO: remove unwrap.
|
||||
recipe_view::setup_page(id, is_user_logged)
|
||||
pages::recipe_view::setup_page(id, is_user_logged)
|
||||
}
|
||||
// Home.
|
||||
[""] => home::setup_page(is_user_logged),
|
||||
[""] => pages::home::setup_page(is_user_logged),
|
||||
_ => log!("Path unknown: ", location),
|
||||
}
|
||||
|
||||
|
|
|
|||
3
frontend/src/pages/mod.rs
Normal file
3
frontend/src/pages/mod.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
pub mod home;
|
||||
pub mod recipe_edit;
|
||||
pub mod recipe_view;
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
use chrono::{Datelike, Days, Months, NaiveDate};
|
||||
use common::ron_api;
|
||||
use gloo::storage::{LocalStorage, Storage};
|
||||
use ron::ser::{to_string_pretty, PrettyConfig};
|
||||
use ron::ser::{PrettyConfig, to_string_pretty};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use thiserror::Error;
|
||||
|
||||
|
|
|
|||
|
|
@ -99,6 +99,16 @@ where
|
|||
.unwrap()
|
||||
}
|
||||
|
||||
pub fn get_current_lang() -> String {
|
||||
selector::<Element>("html")
|
||||
.get_attribute("lang")
|
||||
.unwrap()
|
||||
.split("-")
|
||||
.next()
|
||||
.unwrap()
|
||||
.to_string()
|
||||
}
|
||||
|
||||
pub fn get_locale() -> Locale {
|
||||
let lang_and_territory = selector::<Element>("html")
|
||||
.get_attribute("lang")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue