Open source personal finance application
feat: improve useStatDate hook with default parameters and initialization
Ilya Komichev3f75e734ba69
diff --git a/app/components/date/useStatDate.ts b/app/components/date/useStatDate.tsindex 6d5fe2d0..17eb7390 100644--- a/app/components/date/useStatDate.ts+++ b/app/components/date/useStatDate.ts@@ -6,7 +6,20 @@ import type { Grouped, IntervalGroupedLabel, Range, StatDateParams, StatDateParaimport { calculateBestIntervalsBy, calculateIntervalInRange, getEndOf, getIntervalsInRange } from '~/components/date/utils'+const defaultParams: StatDateParams = {+ customDate: false,+ intervalsBy: 'week',+ intervalsDuration: 1,+ intervalSelected: -1,+ isShowMaxRange: false,+ isSkipEmpty: false,+ rangeBy: 'month',+ rangeDuration: 3,+ rangeOffset: 0,+}+export function useStatDate({+ initParams,key,maxRange,queryParams,@@ -16,20 +29,14 @@ export function useStatDate({maxRange: ComputedRef<Range>queryParams?: Partial<StatDateParamsQuery>}) {- const params = useStorage<StatDateParams>(`${key}-params2`, {- customDate: false,- intervalsBy: 'week',- intervalsDuration: 1,- intervalSelected: -1,- isShowMaxRange: false,- isSkipEmpty: false,- rangeBy: 'month',- rangeDuration: 3,- rangeOffset: 0,- }, localStorage, {+ const params = useStorage<StatDateParams>(`${key}-params`, {} as StatDateParams, localStorage, {mergeDefaults: (storageValue, defaults) => defu(storageValue, defaults),})+ if (Object.keys(params.value).length === 0) {+ params.value = defu(initParams ?? {}, defaultParams)+ }+const modals = ref({dateSelector: false,})