Skip to content

Commit

Permalink
fix tabs 3
Browse files Browse the repository at this point in the history
  • Loading branch information
GithubCosmin committed Jun 29, 2024
1 parent 6a54b04 commit d04461e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
2 changes: 1 addition & 1 deletion client/src/comp/game_board_mspaint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub fn MsPaintPage() -> impl IntoView {
</div>
<div class="main_right">

<Tabs mount=Mount::WhenShown>
<Tabs mount=Mount::Once>

<Tab name="current-cusxtom-game" label="Edit Custom Game".into_view()>
<NextPeaceSelector game_state/>
Expand Down
2 changes: 1 addition & 1 deletion client/src/page/page_replay_browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub fn GameReplayBrowserPage() -> impl IntoView {
</div>
<div class="main_left">

<Tabs mount=Mount::WhenShown>
<Tabs mount=Mount::Once>

<Tab name="tab-best-games" label="Best Games".into_view()>
<AllGamesTable list_type=GetAllGamesArg::BestGames/>
Expand Down
4 changes: 2 additions & 2 deletions client/src/page/page_user_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub fn UserProfileView(_user_id: uuid::Uuid, p: user::UserProfile) -> impl IntoV
<h1>{{ &p.display_name }}</h1>
<h3>user_id: {{ format!("{:?}", _user_id) }}</h3>

<Tabs mount=Mount::WhenShown>
<Tabs mount=Mount::Once>
<Tab
name="tab-best-user-games"
label="Best Games from $User".into_view()
Expand Down Expand Up @@ -145,7 +145,7 @@ pub fn PersonalAccountSettingsForm(user_profile: user::UserProfile, guest_id: Gu
let user_link = create_rw_signal(user_link());
let (value_menu_mmusic , set_value_menu_music) = create_signal(0.0);
view! {
<Tabs mount=Mount::WhenShown>
<Tabs mount=Mount::Once>
<Tab name="account" label="My Account".into_view()>
<div style="width: 100%; padding: 1vh; margin: 1vh;">
<h2>account</h2>
Expand Down
39 changes: 33 additions & 6 deletions lib/leptonic-0.5.0/leptonic/src/tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,44 @@ pub fn TabSelectors(
) -> impl IntoView {
let navigate = leptos_router::use_navigate();
let location = leptos_router::use_location();
let current_hash = (&location.hash.get_untracked()[1..]).to_string();
let current_path = location.pathname.get_untracked();

tabs.with_untracked(|tabs| {
for tab in tabs.iter() {
if current_hash == tab.name.clone() {
set_history.update(|history| history.push(tab.name.clone()));
let update_tabs = move |current_hash| {
tabs.with_untracked(|tabs| {
let mut found_tab = false;
for tab in tabs.iter() {
if current_hash == tab.name.clone() {
set_history.update(|history| history.push(tab.name.clone()));
found_tab = true;
break;
}
}
}
if !found_tab {
if let Some(first_tab) = tabs.first() {
set_history.update(|history| history.push(first_tab.name.clone()));
}
}
});
};

let stop_watch = leptos::watch (
move || location.hash.get(),
move |current_hash, _prev_hash, _| {
let current_hash = if current_hash.len() > 1 {(&current_hash[1..]).to_string()} else {"".to_string()};

update_tabs(current_hash);
},
false,
);
leptos::on_cleanup(move || {
stop_watch();
});

// do immmediate: false on watch() becacuse panicc bug
let current_hash = location.hash.get_untracked();
let current_hash = if current_hash.len() > 1 {(&current_hash[1..]).to_string()} else {"".to_string()};
update_tabs(current_hash);

view! {
<leptonic-tab-selectors role="tablist">
<For
Expand Down

0 comments on commit d04461e

Please sign in to comment.