mirror of
https://github.com/docmost/docmost.git
synced 2025-11-15 13:31:15 +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:
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