mirror of
https://github.com/narrrl/holy-flavor-rater.git
synced 2026-11-03 16:41:27 +01:00
typed api
This commit is contained in:
1 parent
5219a66722
commit
fa37f8eb79
61 files changed
+2961
-2578
No files matched your search
@@ -0,0 +1,50 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import api from '../../lib/api';
|
||||
import { queryKeys } from '../keys';
|
||||
|
||||
export interface FlavorListRating {
|
||||
id: number;
|
||||
user: string;
|
||||
score: number;
|
||||
comment: string;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface FlavorListItem {
|
||||
id: number;
|
||||
name: string;
|
||||
category_name: string;
|
||||
description: string;
|
||||
average_rating: number;
|
||||
user_rating: number | null;
|
||||
ratings: FlavorListRating[];
|
||||
image_url: string | null;
|
||||
is_available: boolean;
|
||||
is_legacy?: boolean;
|
||||
shop_url: string | null;
|
||||
}
|
||||
|
||||
export interface CategoryItem {
|
||||
id: number;
|
||||
name: string;
|
||||
slug: string;
|
||||
}
|
||||
|
||||
export const useFlavorsList = () =>
|
||||
useQuery({
|
||||
queryKey: queryKeys.flavors({ scope: 'all' }),
|
||||
queryFn: async () => {
|
||||
const res = await api.get<FlavorListItem[]>('flavors/');
|
||||
return res.data;
|
||||
},
|
||||
});
|
||||
|
||||
export const useCategories = () =>
|
||||
useQuery({
|
||||
queryKey: ['categories'],
|
||||
queryFn: async () => {
|
||||
const res = await api.get<CategoryItem[]>('categories/');
|
||||
return res.data;
|
||||
},
|
||||
staleTime: 5 * 60_000,
|
||||
});
|
||||
Reference in new issue
Block a user