mirror of
https://github.com/docmost/docmost.git
synced 2025-11-17 02:21:09 +10:00
feat: remember and restore previous route when exiting settings (#1046)
Improves user experience by allowing users to return to the previous page after visiting the Settings section. Co-authored-by: Philipinho <16838612+Philipinho@users.noreply.github.com>
This commit is contained in:
14
apps/client/src/hooks/use-settings-navigation.ts
Normal file
14
apps/client/src/hooks/use-settings-navigation.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import { settingsOriginAtom } from "@/components/settings/atoms/settings-origin-atom";
|
||||
import { useAtomValue } from "jotai";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
|
||||
export function useSettingsNavigation() {
|
||||
const navigate = useNavigate();
|
||||
const origin = useAtomValue(settingsOriginAtom);
|
||||
|
||||
const goBack = () => {
|
||||
navigate(origin ?? "/home", { replace: true });
|
||||
};
|
||||
|
||||
return { goBack };
|
||||
}
|
||||
16
apps/client/src/hooks/use-track-origin.ts
Normal file
16
apps/client/src/hooks/use-track-origin.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { settingsOriginAtom } from "@/components/settings/atoms/settings-origin-atom";
|
||||
import { useAtomValue, useSetAtom } from "jotai";
|
||||
import { useEffect } from "react";
|
||||
import { useLocation } from "react-router-dom";
|
||||
|
||||
export function useTrackOrigin() {
|
||||
const location = useLocation();
|
||||
const setOrigin = useSetAtom(settingsOriginAtom);
|
||||
|
||||
useEffect(() => {
|
||||
const isInSettings = location.pathname.startsWith("/settings");
|
||||
if (!isInSettings) {
|
||||
setOrigin(location.pathname);
|
||||
}
|
||||
}, [location.pathname, setOrigin]);
|
||||
}
|
||||
Reference in New Issue
Block a user