Skip to content

Commit

Permalink
fix backbtn issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ravi-sawlani-yral committed May 15, 2024
1 parent c94f912 commit 7eae679
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
12 changes: 4 additions & 8 deletions src/component/back_btn.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
use leptos::{component, expect_context, view, Callback, IntoView};
use gloo::history::{BrowserHistory, History};
use leptos::{component, expect_context, view, window, Callback, IntoView};
use leptos_icons::Icon;
use leptos_router::use_navigate;

use crate::state::history::HistoryCtx;

#[component]
pub fn BackButton(fallback: String) -> impl IntoView {
let history_ctx = expect_context::<HistoryCtx>();

let go_back = Callback::new(move |_| {
let back_url = history_ctx.back(&fallback);
use_navigate()(&back_url, Default::default());
let history = BrowserHistory::new();
history.back();
});

view! {
Expand Down
9 changes: 5 additions & 4 deletions src/page/err.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::state::history::HistoryCtx;
use gloo::history::{BrowserHistory, History};
use leptos::*;
use leptos_router::*;

Expand All @@ -22,10 +22,11 @@ pub fn ServerErrorPage() -> impl IntoView {

#[component]
pub fn ErrorView(#[prop(into)] error: MaybeSignal<String>) -> impl IntoView {
let history_ctx = expect_context::<HistoryCtx>();
let go_back = move || {
let back_url = history_ctx.back("/");
use_navigate()(&back_url, Default::default());
let history = BrowserHistory::new();

//go back
history.back();
};

view! {
Expand Down
13 changes: 10 additions & 3 deletions src/page/profile/profile_post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,23 @@ pub fn ProfilePostWithUpdates(initial_post: PostDetails) -> impl IntoView {
})
});

//TODO: fix the navigation for the vidoes.
create_effect(move |_| {
let Some((canister_id, post_id)) = current_post_base() else {
let Some((canister_id, post_id)) = current_post_base.get() else {
return;
};

if recovering_state.get_untracked() {
return;
}
log::warn!("navigated {canister_id} {post_id}");

use_navigate()(
&format!("profile/{canister_id}/{post_id}"),
NavigateOptions {
resolve: true,
scroll: false,
state: State(None),
replace: true,
..NavigateOptions::default()
},
);
});
Expand Down

0 comments on commit 7eae679

Please sign in to comment.