idk even know anymore
i think i added games
This commit is contained in:
33
web/src/api/games.ts
Normal file
33
web/src/api/games.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||
|
||||
export type SearchGame = {
|
||||
name: string;
|
||||
steamAppId: number;
|
||||
image: string;
|
||||
releaseDate: string;
|
||||
};
|
||||
|
||||
export const useSearchGamesQuery = (params: { search: string }) => {
|
||||
return useQuery({
|
||||
queryKey: ["search-games", params],
|
||||
queryFn: async () => {
|
||||
const q = new URLSearchParams();
|
||||
q.set("q", params.search);
|
||||
|
||||
const resp = await fetch(`/api/search/games?${q.toString()}`);
|
||||
return (await resp.json()) as SearchGame[];
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const useAddGameMutation = () => {
|
||||
return useMutation({
|
||||
mutationFn: async (data: { steamAppId: number }) => {
|
||||
const resp = await fetch("/api/user/games", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
return await resp.json();
|
||||
},
|
||||
});
|
||||
};
|
||||
@@ -1,8 +1,20 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
export type Game = {
|
||||
id: number;
|
||||
name: string;
|
||||
steamAppId: number;
|
||||
releaseDate: string;
|
||||
image: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
deletedAt: string | null;
|
||||
};
|
||||
|
||||
export type User = {
|
||||
id: number;
|
||||
login: string;
|
||||
games: Game[];
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
deletedAt: string | null;
|
||||
|
||||
Reference in New Issue
Block a user