mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-15 19:52:15 +01:00
load time entries above pagination limit for calendar, fixes #995
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { useQuery } from '@tanstack/vue-query';
|
import { useQuery } from '@tanstack/vue-query';
|
||||||
import { api, type TimeEntryResponse } from '@/packages/api/src';
|
import { api, type TimeEntryResponse, type TimeEntry } from '@/packages/api/src';
|
||||||
import { getCurrentMembershipId, getCurrentOrganizationId } from '@/utils/useUser';
|
import { getCurrentMembershipId, getCurrentOrganizationId } from '@/utils/useUser';
|
||||||
import { computed, type Ref } from 'vue';
|
import { computed, type Ref } from 'vue';
|
||||||
import { getDayJsInstance } from '@/packages/ui/src/utils/time';
|
import { getDayJsInstance } from '@/packages/ui/src/utils/time';
|
||||||
@@ -49,17 +49,33 @@ export function useTimeEntriesCalendarQuery(
|
|||||||
]),
|
]),
|
||||||
enabled: enableCalendarQuery,
|
enabled: enableCalendarQuery,
|
||||||
placeholderData: (previousData) => previousData,
|
placeholderData: (previousData) => previousData,
|
||||||
queryFn: () =>
|
queryFn: async () => {
|
||||||
api.getTimeEntries({
|
const allEntries: TimeEntry[] = [];
|
||||||
params: {
|
|
||||||
organization: getCurrentOrganizationId() || '',
|
while (true) {
|
||||||
},
|
const response = await api.getTimeEntries({
|
||||||
queries: {
|
params: {
|
||||||
start: expandedDateRange.value.start!,
|
organization: getCurrentOrganizationId() || '',
|
||||||
end: expandedDateRange.value.end!,
|
},
|
||||||
member_id: getCurrentMembershipId(),
|
queries: {
|
||||||
},
|
start: expandedDateRange.value.start!,
|
||||||
}),
|
end: expandedDateRange.value.end!,
|
||||||
|
member_id: getCurrentMembershipId(),
|
||||||
|
offset: allEntries.length || undefined,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.data.length === 0) {
|
||||||
|
return { data: allEntries, meta: response.meta };
|
||||||
|
}
|
||||||
|
|
||||||
|
allEntries.push(...response.data);
|
||||||
|
|
||||||
|
if (allEntries.length >= response.meta.total) {
|
||||||
|
return { data: allEntries, meta: response.meta };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
staleTime: 1000 * 30, // 30 seconds
|
staleTime: 1000 * 30, // 30 seconds
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user