allow to mark episodes as completed

This commit is contained in:
2026-03-12 14:53:44 +03:00
parent 618c034b05
commit 5409167a96
6 changed files with 152 additions and 28 deletions

41
web/src/api/episodes.ts Normal file
View File

@@ -0,0 +1,41 @@
import { useMutation, useQuery } from "@tanstack/react-query";
export type EpisodeDetail = {
id: number;
title: string;
pubDate: string;
guid: string;
url: string;
podcastId: number;
number: number;
listened: boolean;
createdAt: string;
};
export const usePodcastEpisodesQuery = (
id: number | string | null | undefined,
) => {
return useQuery({
queryKey: ["podcasts", id, "episodes"],
enabled: typeof id !== "undefined" && id !== null,
queryFn: async () => {
const resp = await fetch(`/api/podcasts/${id}/episodes`);
return (await resp.json()) as EpisodeDetail[];
},
});
};
export const useUpdateEpisodeMutation = () => {
return useMutation({
mutationFn: async ({
id,
...data
}: Partial<EpisodeDetail> & { id: number }) => {
const resp = await fetch(`/api/episodes/${id}`, {
method: "PATCH",
body: JSON.stringify(data),
});
return await resp.json();
},
});
};

View File

@@ -11,17 +11,6 @@ export type PodcastDetail = {
createdAt: string;
};
export type EpisodeDetail = {
id: number;
title: string;
pubDate: string;
guid: string;
url: string;
podcastId: number;
number: number;
createdAt: string;
};
export const usePodcastsQuery = () => {
return useQuery({
queryKey: ["podcasts"],
@@ -43,19 +32,6 @@ export const usePodcastQuery = (id: number | string | null | undefined) => {
});
};
export const usePodcastEpisodesQuery = (
id: number | string | null | undefined,
) => {
return useQuery({
queryKey: ["podcasts", id, "episodes"],
enabled: typeof id !== "undefined" && id !== null,
queryFn: async () => {
const resp = await fetch(`/api/podcasts/${id}/episodes`);
return (await resp.json()) as EpisodeDetail[];
},
});
};
export type CreatePodcastData = {
feed: string;
};