rewrite ui with vite+react

This commit is contained in:
2026-03-12 11:57:43 +03:00
parent 44c7126ac5
commit da9f4bb0ec
24 changed files with 3165 additions and 63 deletions

73
web/src/api/podcasts.ts Normal file
View File

@@ -0,0 +1,73 @@
import { useMutation, useQuery } from "@tanstack/react-query";
export type PodcastDetail = {
id: number;
name: string;
description: string;
feed: string;
language: string;
link: string;
image: string;
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"],
queryFn: async () => {
const resp = await fetch("/api/podcasts");
return (await resp.json()) as PodcastDetail[];
},
});
};
export const usePodcastQuery = (id: number | string | null | undefined) => {
return useQuery({
queryKey: ["podcasts", id],
enabled: typeof id !== "undefined" && id !== null,
queryFn: async () => {
const resp = await fetch(`/api/podcasts/${id}`);
return (await resp.json()) as PodcastDetail;
},
});
};
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;
};
export const useCreatePodcastMutation = () => {
return useMutation({
mutationFn: async (data: CreatePodcastData) => {
const resp = await fetch("/api/podcasts", {
method: "POST",
body: JSON.stringify(data),
});
return await resp.json();
},
});
};