mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-02 19:55:18 +02:00
add getPodcasts query atom
This commit is contained in:
parent
eca4580f76
commit
d2fddd5ea5
14 changed files with 77 additions and 14 deletions
|
|
@ -5,13 +5,15 @@ import type { DeletePodcastRequest, Podcast } from "@/contracts/types/podcast.ty
|
|||
import { podcastsApiService } from "@/lib/apis/podcasts-api.service";
|
||||
import { cacheKeys } from "@/lib/query-client/cache-keys";
|
||||
import { queryClient } from "@/lib/query-client/client";
|
||||
import { globalPodcastsQueryParamsAtom } from "./ui.atoms";
|
||||
|
||||
export const deletePodcastMutationAtom = atomWithMutation((get) => {
|
||||
const searchSpaceId = get(activeSearchSpaceIdAtom);
|
||||
const authToken = localStorage.getItem("surfsense_bearer_token");
|
||||
const podcastsQueryParams = get(globalPodcastsQueryParamsAtom);
|
||||
|
||||
return {
|
||||
mutationKey: cacheKeys.podcasts(),
|
||||
mutationKey: cacheKeys.podcasts.globalQueryParams(podcastsQueryParams),
|
||||
enabled: !!searchSpaceId && !!authToken,
|
||||
mutationFn: async (request: DeletePodcastRequest) => {
|
||||
return podcastsApiService.deletePodcast(request);
|
||||
|
|
@ -19,9 +21,12 @@ export const deletePodcastMutationAtom = atomWithMutation((get) => {
|
|||
|
||||
onSuccess: (_, request: DeletePodcastRequest) => {
|
||||
toast.success("Podcast deleted successfully");
|
||||
queryClient.setQueryData(cacheKeys.podcasts(), (oldData: Podcast[]) => {
|
||||
return oldData.filter((podcast) => podcast.id !== request.id);
|
||||
});
|
||||
queryClient.setQueryData(
|
||||
cacheKeys.podcasts.globalQueryParams(podcastsQueryParams),
|
||||
(oldData: Podcast[]) => {
|
||||
return oldData.filter((podcast) => podcast.id !== request.id);
|
||||
}
|
||||
);
|
||||
},
|
||||
};
|
||||
});
|
||||
|
|
|
|||
17
surfsense_web/atoms/podcasts/podcast-query.atoms.ts
Normal file
17
surfsense_web/atoms/podcasts/podcast-query.atoms.ts
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import { atomWithQuery } from "jotai-tanstack-query";
|
||||
import { podcastsApiService } from "@/lib/apis/podcasts-api.service";
|
||||
import { cacheKeys } from "@/lib/query-client/cache-keys";
|
||||
import { globalPodcastsQueryParamsAtom } from "./ui.atoms";
|
||||
|
||||
export const podcastsAtom = atomWithQuery((get) => {
|
||||
const queryParams = get(globalPodcastsQueryParamsAtom);
|
||||
|
||||
return {
|
||||
queryKey: cacheKeys.podcasts.globalQueryParams(queryParams),
|
||||
queryFn: async () => {
|
||||
return podcastsApiService.getPodcasts({
|
||||
queryParams: queryParams,
|
||||
});
|
||||
},
|
||||
};
|
||||
});
|
||||
7
surfsense_web/atoms/podcasts/ui.atoms.ts
Normal file
7
surfsense_web/atoms/podcasts/ui.atoms.ts
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import { atom } from "jotai";
|
||||
import type { GetPodcastsRequest } from "@/contracts/types/podcast.types";
|
||||
|
||||
export const globalPodcastsQueryParamsAtom = atom<GetPodcastsRequest["queryParams"]>({
|
||||
limit: 5,
|
||||
skip: 0,
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue