-
Notifications
You must be signed in to change notification settings - Fork 7.3k
feat: persist board filters locally and sync custom date ranges with share URLs (#4233) #4303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,41 @@ | ||
| import type { Metadata } from 'next'; | ||
| import { useEffect } from 'react'; | ||
| import { useSearchParams } from 'next/navigation'; | ||
| import { setDateRangeValue, setBoardDateRangeValue } from '@/store/app'; | ||
| import { getItem } from '@/lib/storage'; | ||
| import { DATE_RANGE_CONFIG } from '@/lib/constants'; | ||
| import { WebsitesPage } from './WebsitesPage'; | ||
|
|
||
| export default function () { | ||
| export default function Page({ params }: { params: { websiteId?: string } }) { | ||
| const websiteId = params?.websiteId; | ||
| const searchParams = useSearchParams(); | ||
|
|
||
| useEffect(() => { | ||
| if (!websiteId) return; | ||
|
|
||
| const urlRange = searchParams.get('range'); | ||
| const savedRange = getItem(`${DATE_RANGE_CONFIG}:${websiteId}`); | ||
|
|
||
| if (urlRange) { | ||
| try { | ||
| const parsedRange = urlRange.startsWith('{') ? JSON.parse(urlRange) : urlRange; | ||
| setBoardDateRangeValue(parsedRange, websiteId); | ||
| } catch { | ||
| setBoardDateRangeValue(urlRange, websiteId); | ||
| } | ||
| } else if (savedRange) { | ||
| try { | ||
| const parsedRange = savedRange.startsWith('{') ? JSON.parse(savedRange) : savedRange; | ||
| setDateRangeValue(parsedRange); | ||
| } catch { | ||
| setDateRangeValue(savedRange); | ||
| } | ||
| } | ||
| }, [websiteId, searchParams]); | ||
|
|
||
| return <WebsitesPage />; | ||
| } | ||
|
|
||
| export const metadata: Metadata = { | ||
| title: 'Websites', | ||
| }; | ||
| }; | ||
|
Comment on lines
1
to
+41
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This file is Additionally, the route |
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -9,7 +9,7 @@ import { | |||||
| TIMEZONE_CONFIG, | ||||||
| } from '@/lib/constants'; | ||||||
| import { getTimezone } from '@/lib/date'; | ||||||
| import { getItem } from '@/lib/storage'; | ||||||
| import { getItem, setItem } from '@/lib/storage'; | ||||||
|
|
||||||
| const initialState = { | ||||||
| locale: getItem(LOCALE_CONFIG) || process.env.defaultLocale || DEFAULT_LOCALE, | ||||||
|
|
@@ -51,4 +51,12 @@ export function setDateRangeValue(dateRangeValue: string) { | |||||
| store.setState({ dateRangeValue }); | ||||||
| } | ||||||
|
|
||||||
| export const useApp = store; | ||||||
| // Added scoped board setter to handle unique board filter persistence | ||||||
| export function setBoardDateRangeValue(dateRangeValue: string, boardId: string) { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| store.setState({ dateRangeValue }); | ||||||
| if (boardId) { | ||||||
| setItem(`${DATE_RANGE_CONFIG}:${boardId}`, dateRangeValue); | ||||||
| } | ||||||
|
Comment on lines
+55
to
+59
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
| } | ||||||
|
|
||||||
| export const useApp = store; | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getItemreturns a parsed value — calling.startsWithon an object throws at runtimegetIteminsrc/lib/storage.tsalways callsJSON.parseinternally before returning. When a custom date range object (e.g.,{ startDate, endDate }) was stored,getItemreturns a plain JavaScript object, not a JSON string. Calling.startsWith('{')on that object throwsTypeError: savedRange.startsWith is not a functionat runtime. The guard only works correctly when the stored value is a primitive string like"30d".