2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-05 13:10:57 +00:00

Load calendar on first render (#9916)

Ensure that calendar views submit an API request on first load
This commit is contained in:
Oliver
2025-07-01 12:25:04 +10:00
committed by GitHub
parent 038337b17d
commit 6a7d04d0e6
2 changed files with 7 additions and 2 deletions

View File

@ -25,7 +25,7 @@ import {
IconDownload,
IconFilter
} from '@tabler/icons-react';
import { useCallback, useState } from 'react';
import { useCallback, useEffect, useState } from 'react';
import { useShallow } from 'zustand/react/shallow';
import type { CalendarState } from '../../hooks/UseCalendar';
import { useLocalState } from '../../states/LocalState';
@ -67,6 +67,11 @@ export default function Calendar({
[state.selectMonth]
);
useEffect(() => {
// Select initial month on first calendar render
state.ref?.current?.getApi()?.gotoDate(new Date());
}, []);
// Callback when the calendar date range is adjusted
const datesSet = useCallback(
(dateInfo: DatesSetArg) => {

View File

@ -102,7 +102,7 @@ export default function useCalendar({
const query = useQuery({
enabled: !!startDate && !!endDate,
queryKey: ['calendar', name, endpoint, queryFilters],
queryKey: ['calendar', name, endpoint, queryFilters, startDate, endDate],
throwOnError: (error: any) => {
showApiErrorMessage({
error: error,