* 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),
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue