diff options
Diffstat (limited to 'frontend/src/apis/hooks')
-rw-r--r-- | frontend/src/apis/hooks/episodes.ts | 26 | ||||
-rw-r--r-- | frontend/src/apis/hooks/movies.ts | 33 | ||||
-rw-r--r-- | frontend/src/apis/hooks/system.ts | 37 |
3 files changed, 36 insertions, 60 deletions
diff --git a/frontend/src/apis/hooks/episodes.ts b/frontend/src/apis/hooks/episodes.ts index 6a489e938..956fd103f 100644 --- a/frontend/src/apis/hooks/episodes.ts +++ b/frontend/src/apis/hooks/episodes.ts @@ -25,23 +25,6 @@ const cacheEpisodes = (client: QueryClient, episodes: Item.Episode[]) => { }); }; -export function useEpisodesByIds(ids: number[]) { - const client = useQueryClient(); - - const query = useQuery({ - queryKey: [QueryKeys.Series, QueryKeys.Episodes, ids], - queryFn: () => api.episodes.byEpisodeId(ids), - }); - - useEffect(() => { - if (query.isSuccess && query.data) { - cacheEpisodes(client, query.data); - } - }, [query.isSuccess, query.data, client]); - - return query; -} - export function useEpisodesBySeriesId(id: number) { const client = useQueryClient(); @@ -87,10 +70,11 @@ export function useEpisodeAddBlacklist() { }, onSuccess: (_, { seriesId }) => { - client.invalidateQueries({ + void client.invalidateQueries({ queryKey: [QueryKeys.Series, QueryKeys.Episodes, QueryKeys.Blacklist], }); - client.invalidateQueries({ + + void client.invalidateQueries({ queryKey: [QueryKeys.Series, seriesId], }); }, @@ -105,8 +89,8 @@ export function useEpisodeDeleteBlacklist() { mutationFn: (param: { all?: boolean; form?: FormType.DeleteBlacklist }) => api.episodes.deleteBlacklist(param.all, param.form), - onSuccess: (_) => { - client.invalidateQueries({ + onSuccess: () => { + void client.invalidateQueries({ queryKey: [QueryKeys.Series, QueryKeys.Episodes, QueryKeys.Blacklist], }); }, diff --git a/frontend/src/apis/hooks/movies.ts b/frontend/src/apis/hooks/movies.ts index cf4594cbe..6b1c5c2a5 100644 --- a/frontend/src/apis/hooks/movies.ts +++ b/frontend/src/apis/hooks/movies.ts @@ -15,23 +15,6 @@ const cacheMovies = (client: QueryClient, movies: Item.Movie[]) => { }); }; -export function useMoviesByIds(ids: number[]) { - const client = useQueryClient(); - - const query = useQuery({ - queryKey: [QueryKeys.Movies, ...ids], - queryFn: () => api.movies.movies(ids), - }); - - useEffect(() => { - if (query.isSuccess && query.data) { - cacheMovies(client, query.data); - } - }, [query.isSuccess, query.data, client]); - - return query; -} - export function useMovieById(id: number) { return useQuery({ queryKey: [QueryKeys.Movies, id], @@ -74,12 +57,13 @@ export function useMovieModification() { onSuccess: (_, form) => { form.id.forEach((v) => { - client.invalidateQueries({ + void client.invalidateQueries({ queryKey: [QueryKeys.Movies, v], }); }); + // TODO: query less - client.invalidateQueries({ + void client.invalidateQueries({ queryKey: [QueryKeys.Movies], }); }, @@ -93,7 +77,7 @@ export function useMovieAction() { mutationFn: (form: FormType.MoviesAction) => api.movies.action(form), onSuccess: () => { - client.invalidateQueries({ + void client.invalidateQueries({ queryKey: [QueryKeys.Movies], }); }, @@ -125,10 +109,11 @@ export function useMovieAddBlacklist() { }, onSuccess: (_, { id }) => { - client.invalidateQueries({ + void client.invalidateQueries({ queryKey: [QueryKeys.Movies, QueryKeys.Blacklist], }); - client.invalidateQueries({ + + void client.invalidateQueries({ queryKey: [QueryKeys.Movies, id], }); }, @@ -143,8 +128,8 @@ export function useMovieDeleteBlacklist() { mutationFn: (param: { all?: boolean; form?: FormType.DeleteBlacklist }) => api.movies.deleteBlacklist(param.all, param.form), - onSuccess: (_, param) => { - client.invalidateQueries({ + onSuccess: () => { + void client.invalidateQueries({ queryKey: [QueryKeys.Movies, QueryKeys.Blacklist], }); }, diff --git a/frontend/src/apis/hooks/system.ts b/frontend/src/apis/hooks/system.ts index 109e77105..a0ce17fb9 100644 --- a/frontend/src/apis/hooks/system.ts +++ b/frontend/src/apis/hooks/system.ts @@ -54,22 +54,27 @@ export function useSettingsMutation() { mutationFn: (data: LooseObject) => api.system.updateSettings(data), onSuccess: () => { - client.invalidateQueries({ + void client.invalidateQueries({ queryKey: [QueryKeys.System], }); - client.invalidateQueries({ + + void client.invalidateQueries({ queryKey: [QueryKeys.Series], }); - client.invalidateQueries({ + + void client.invalidateQueries({ queryKey: [QueryKeys.Episodes], }); - client.invalidateQueries({ + + void client.invalidateQueries({ queryKey: [QueryKeys.Movies], }); - client.invalidateQueries({ + + void client.invalidateQueries({ queryKey: [QueryKeys.Wanted], }); - client.invalidateQueries({ + + void client.invalidateQueries({ queryKey: [QueryKeys.Badges], }); }, @@ -101,7 +106,7 @@ export function useDeleteLogs() { mutationFn: () => api.system.deleteLogs(), onSuccess: () => { - client.invalidateQueries({ + void client.invalidateQueries({ queryKey: [QueryKeys.System, QueryKeys.Logs], }); }, @@ -128,11 +133,12 @@ export function useSystemAnnouncementsAddDismiss() { return api.system.addAnnouncementsDismiss(hash); }, - onSuccess: (_, { hash }) => { - client.invalidateQueries({ + onSuccess: () => { + void client.invalidateQueries({ queryKey: [QueryKeys.System, QueryKeys.Announcements], }); - client.invalidateQueries({ + + void client.invalidateQueries({ queryKey: [QueryKeys.System, QueryKeys.Badges], }); }, @@ -156,10 +162,11 @@ export function useRunTask() { mutationFn: (id: string) => api.system.runTask(id), onSuccess: () => { - client.invalidateQueries({ + void client.invalidateQueries({ queryKey: [QueryKeys.System, QueryKeys.Tasks], }); - client.invalidateQueries({ + + void client.invalidateQueries({ queryKey: [QueryKeys.System, QueryKeys.Backups], }); }, @@ -180,7 +187,7 @@ export function useCreateBackups() { mutationFn: () => api.system.createBackups(), onSuccess: () => { - client.invalidateQueries({ + void client.invalidateQueries({ queryKey: [QueryKeys.System, QueryKeys.Backups], }); }, @@ -194,7 +201,7 @@ export function useRestoreBackups() { mutationFn: (filename: string) => api.system.restoreBackups(filename), onSuccess: () => { - client.invalidateQueries({ + void client.invalidateQueries({ queryKey: [QueryKeys.System, QueryKeys.Backups], }); }, @@ -208,7 +215,7 @@ export function useDeleteBackups() { mutationFn: (filename: string) => api.system.deleteBackups(filename), onSuccess: () => { - client.invalidateQueries({ + void client.invalidateQueries({ queryKey: [QueryKeys.System, QueryKeys.Backups], }); }, |