mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-05 21:20:56 +00:00
Load calendar on first render (#9916)
Ensure that calendar views submit an API request on first load
This commit is contained in:
@ -25,7 +25,7 @@ import {
|
|||||||
IconDownload,
|
IconDownload,
|
||||||
IconFilter
|
IconFilter
|
||||||
} from '@tabler/icons-react';
|
} from '@tabler/icons-react';
|
||||||
import { useCallback, useState } from 'react';
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
import { useShallow } from 'zustand/react/shallow';
|
import { useShallow } from 'zustand/react/shallow';
|
||||||
import type { CalendarState } from '../../hooks/UseCalendar';
|
import type { CalendarState } from '../../hooks/UseCalendar';
|
||||||
import { useLocalState } from '../../states/LocalState';
|
import { useLocalState } from '../../states/LocalState';
|
||||||
@ -67,6 +67,11 @@ export default function Calendar({
|
|||||||
[state.selectMonth]
|
[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
|
// Callback when the calendar date range is adjusted
|
||||||
const datesSet = useCallback(
|
const datesSet = useCallback(
|
||||||
(dateInfo: DatesSetArg) => {
|
(dateInfo: DatesSetArg) => {
|
||||||
|
@ -102,7 +102,7 @@ export default function useCalendar({
|
|||||||
|
|
||||||
const query = useQuery({
|
const query = useQuery({
|
||||||
enabled: !!startDate && !!endDate,
|
enabled: !!startDate && !!endDate,
|
||||||
queryKey: ['calendar', name, endpoint, queryFilters],
|
queryKey: ['calendar', name, endpoint, queryFilters, startDate, endDate],
|
||||||
throwOnError: (error: any) => {
|
throwOnError: (error: any) => {
|
||||||
showApiErrorMessage({
|
showApiErrorMessage({
|
||||||
error: error,
|
error: error,
|
||||||
|
Reference in New Issue
Block a user