mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-09 20:29:36 +02:00
Add genres api
This commit is contained in:
@@ -0,0 +1,22 @@
|
|||||||
|
import { BaseResponse, Genre } from '@/renderer/api/types';
|
||||||
|
import { ax } from '@/renderer/lib/axios';
|
||||||
|
|
||||||
|
export type GenreListResponse = BaseResponse<Genre[]>;
|
||||||
|
|
||||||
|
const getGenreList = async (
|
||||||
|
query: { serverId: string },
|
||||||
|
signal?: AbortSignal
|
||||||
|
) => {
|
||||||
|
const { data } = await ax.get<GenreListResponse>(
|
||||||
|
`/servers/${query.serverId}/genres`,
|
||||||
|
{
|
||||||
|
signal,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return data;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const genresApi = {
|
||||||
|
getGenreList,
|
||||||
|
};
|
||||||
@@ -1,14 +1,16 @@
|
|||||||
|
import { albumsApi } from '@/renderer/api/albums.api';
|
||||||
|
import { authApi } from '@/renderer/api/auth.api';
|
||||||
|
import { genresApi } from '@/renderer/api/genres.api';
|
||||||
|
import { serversApi } from '@/renderer/api/servers.api';
|
||||||
import { tasksApi } from '@/renderer/api/tasks.api';
|
import { tasksApi } from '@/renderer/api/tasks.api';
|
||||||
import { albumsApi } from './albums.api';
|
import { usersApi } from '@/renderer/api/users.api';
|
||||||
import { authApi } from './auth.api';
|
|
||||||
import { serversApi } from './servers.api';
|
|
||||||
import { usersApi } from './users.api';
|
|
||||||
|
|
||||||
export * from './sockets.api';
|
export * from './sockets.api';
|
||||||
|
|
||||||
export const api = {
|
export const api = {
|
||||||
albums: albumsApi,
|
albums: albumsApi,
|
||||||
auth: authApi,
|
auth: authApi,
|
||||||
|
genres: genresApi,
|
||||||
servers: serversApi,
|
servers: serversApi,
|
||||||
tasks: tasksApi,
|
tasks: tasksApi,
|
||||||
users: usersApi,
|
users: usersApi,
|
||||||
|
|||||||
@@ -4,11 +4,18 @@ export const queryKeys = {
|
|||||||
albums: {
|
albums: {
|
||||||
detail: (albumId: string) => ['albums', albumId] as const,
|
detail: (albumId: string) => ['albums', albumId] as const,
|
||||||
list: (serverId: string, params: AlbumListParams) =>
|
list: (serverId: string, params: AlbumListParams) =>
|
||||||
['albums', 'list', serverId, params] as const,
|
[serverId, 'albums', 'list', params] as const,
|
||||||
root: ['albums'],
|
root: ['albums'],
|
||||||
songList: (albumId: string) => ['albums', albumId, 'songs'] as const,
|
songList: (albumId: string) => ['albums', albumId, 'songs'] as const,
|
||||||
},
|
},
|
||||||
|
genres: {
|
||||||
|
list: (serverId: string) => [serverId, 'genres', 'list'] as const,
|
||||||
|
root: (serverId: string) => [serverId, 'genres'] as const,
|
||||||
|
},
|
||||||
ping: (url: string) => ['ping', url] as const,
|
ping: (url: string) => ['ping', url] as const,
|
||||||
|
server: {
|
||||||
|
root: (serverId: string) => [serverId] as const,
|
||||||
|
},
|
||||||
servers: {
|
servers: {
|
||||||
list: (params?: any) => ['servers', 'list', params] as const,
|
list: (params?: any) => ['servers', 'list', params] as const,
|
||||||
root: ['servers'],
|
root: ['servers'],
|
||||||
|
|||||||
@@ -174,10 +174,13 @@ export type Ping = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type Genre = {
|
export type Genre = {
|
||||||
createdAt: string;
|
albumArtistCount: number;
|
||||||
|
albumCount: number;
|
||||||
|
artistCount: number;
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
updatedAt: string;
|
songCount: number;
|
||||||
|
totalCount: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type RelatedGenre = {
|
export type RelatedGenre = {
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
export * from './queries/genre-list';
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
import { AxiosError } from 'axios';
|
||||||
|
import { api } from '@/renderer/api';
|
||||||
|
import { GenreListResponse } from '@/renderer/api/genres.api';
|
||||||
|
import { queryKeys } from '@/renderer/api/query-keys';
|
||||||
|
import { ApiError } from '@/renderer/api/types';
|
||||||
|
import { QueryOptions } from '@/renderer/lib/react-query';
|
||||||
|
import { useAuthStore } from '@/renderer/store';
|
||||||
|
|
||||||
|
export const useGenreList = (options?: QueryOptions<GenreListResponse>) => {
|
||||||
|
const serverId = useAuthStore((state) => state.currentServer?.id) || '';
|
||||||
|
|
||||||
|
const query = useQuery<GenreListResponse, AxiosError<ApiError>>({
|
||||||
|
enabled: !!serverId,
|
||||||
|
queryFn: ({ signal }) => api.genres.getGenreList({ serverId }, signal),
|
||||||
|
queryKey: queryKeys.genres.list(serverId),
|
||||||
|
staleTime: Infinity,
|
||||||
|
...options,
|
||||||
|
});
|
||||||
|
|
||||||
|
return query;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user