80 lines
2.2 KiB
TypeScript
80 lines
2.2 KiB
TypeScript
import { QueryClient } from '@tanstack/react-query';
|
|
import { getUserData, getUserFilesInfo, getBuildData } from '@/app/actions/action';
|
|
import { getUserFilesData } from '@/app/actions/fileEntity';
|
|
import { fetchReferralUserStats } from '@/app/actions/referralsActions';
|
|
import { getAllowedFilesExtensions } from '@/app/actions/fileUpload';
|
|
|
|
export interface allFilesExtensions {
|
|
videos: string[];
|
|
audios: string[];
|
|
images: string[];
|
|
documents: string[];
|
|
maxFileSize: number;
|
|
}
|
|
|
|
export async function getAllFilesExtensions(): Promise<allFilesExtensions> {
|
|
const [video, audio, image, document] = await Promise.all([
|
|
getAllowedFilesExtensions('video'),
|
|
getAllowedFilesExtensions('audio'),
|
|
getAllowedFilesExtensions('image'),
|
|
getAllowedFilesExtensions('document')
|
|
]);
|
|
|
|
const result: allFilesExtensions = {
|
|
videos: video?.file_extension ? video.file_extension : [],
|
|
audios: audio?.file_extension ? audio.file_extension : [],
|
|
images: image?.file_extension ? image.file_extension : [],
|
|
documents: document?.file_extension ? document.file_extension : [],
|
|
maxFileSize: video?.max_file_size ? video.max_file_size : 0
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
export async function prefetchLayoutQueries(queryClient: QueryClient) {
|
|
await Promise.all([
|
|
queryClient.prefetchQuery({
|
|
queryKey: ['userData'],
|
|
queryFn: () => getUserData()
|
|
}),
|
|
queryClient.prefetchQuery({
|
|
queryKey: ['userFilesData'],
|
|
queryFn: () => {
|
|
return getUserFilesData({
|
|
page: 1,
|
|
pageSize: 10,
|
|
sortBy: '',
|
|
sortOrder: '',
|
|
type: '',
|
|
date: '',
|
|
query: ''
|
|
});
|
|
},
|
|
staleTime: 30 * 1000
|
|
}),
|
|
queryClient.prefetchQuery({
|
|
queryKey: ['userFilesInfo'],
|
|
queryFn: () => getUserFilesInfo()
|
|
}),
|
|
queryClient.prefetchQuery({
|
|
queryKey: ['referralUserStats'],
|
|
queryFn: () => fetchReferralUserStats()
|
|
}),
|
|
queryClient.prefetchQuery({
|
|
queryKey: ['backendBuildDate'],
|
|
queryFn: async () => {
|
|
try {
|
|
const response = await getBuildData();
|
|
return response.buildTimeBack ?? null;
|
|
} catch (error) {
|
|
return null;
|
|
}
|
|
}
|
|
}),
|
|
queryClient.prefetchQuery({
|
|
queryKey: ['allFilesExtensions'],
|
|
queryFn: () => getAllFilesExtensions(),
|
|
staleTime: 5 * 60 * 1000
|
|
}),
|
|
]);
|
|
} |