fix(web): calendar navigation should use current page path instead of hardcoded root

Previously, clicking on a date in the calendar always navigated to /?filter=...
regardless of the current page context. This caused issues on non-home pages
like /explore where users expected to stay on the same page with the date filter.

This change:
- Adds an optional targetPath parameter to useDateFilterNavigation hook
- Falls back to location.pathname when no targetPath is provided
- Maintains backward compatibility for existing usage
This commit is contained in:
muling 2026-02-09 03:11:47 +08:00
parent b623162d37
commit 2366e2f156
1 changed files with 6 additions and 4 deletions

View File

@ -1,16 +1,18 @@
import { useCallback } from "react";
import { useNavigate } from "react-router-dom";
import { useLocation, useNavigate } from "react-router-dom";
import { stringifyFilters } from "@/contexts/MemoFilterContext";
export const useDateFilterNavigation = () => {
export const useDateFilterNavigation = (targetPath?: string) => {
const navigate = useNavigate();
const location = useLocation();
const navigateToDateFilter = useCallback(
(date: string) => {
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;