fix(web): calendar navigation should use current page path (#5605)
This commit is contained in:
parent
b623162d37
commit
b5108b4f97
1 changed files with 6 additions and 4 deletions
|
|
@ -1,16 +1,18 @@
|
||||||
import { useCallback } from "react";
|
import { useCallback } from "react";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useLocation, useNavigate } from "react-router-dom";
|
||||||
import { stringifyFilters } from "@/contexts/MemoFilterContext";
|
import { stringifyFilters } from "@/contexts/MemoFilterContext";
|
||||||
|
|
||||||
export const useDateFilterNavigation = () => {
|
export const useDateFilterNavigation = (targetPath?: string) => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const location = useLocation();
|
||||||
|
|
||||||
const navigateToDateFilter = useCallback(
|
const navigateToDateFilter = useCallback(
|
||||||
(date: string) => {
|
(date: string) => {
|
||||||
const filterQuery = stringifyFilters([{ factor: "displayTime", value: date }]);
|
const filterQuery = stringifyFilters([{ factor: "displayTime", value: date }]);
|
||||||
navigate(`/?filter=${filterQuery}`);
|
const basePath = targetPath ?? location.pathname;
|
||||||
|
navigate(`${basePath}?filter=${filterQuery}`);
|
||||||
},
|
},
|
||||||
[navigate],
|
[navigate, location.pathname, targetPath],
|
||||||
);
|
);
|
||||||
|
|
||||||
return navigateToDateFilter;
|
return navigateToDateFilter;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue