Skip to content
Snippets Groups Projects
Commit abc14097 authored by DESKTOP-9FO96TP\hehexd's avatar DESKTOP-9FO96TP\hehexd
Browse files

dropdown fix + avoiding 4api calls in the same place

parent ce1ceb45
No related branches found
No related tags found
1 merge request!47dropdown fix + avoiding 4igdb calls in the same place
Pipeline #39979 passed
...@@ -67,7 +67,7 @@ export default async function GameDetail({ params }: { params: { gameid: string ...@@ -67,7 +67,7 @@ export default async function GameDetail({ params }: { params: { gameid: string
className="object-cover rounded-lg" /> className="object-cover rounded-lg" />
</Card> </Card>
<div className="flex justify-start p-6"> <div className="flex justify-start p-6">
<AddGameDropdown fullUser={fullUser!} gameid={params.gameid} /> {user && < AddGameDropdown fullUser={fullUser!} gameid={params.gameid} />}
</div> </div>
</div> </div>
......
...@@ -11,6 +11,7 @@ import { Card } from "./ui/card" ...@@ -11,6 +11,7 @@ import { Card } from "./ui/card"
import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrigger, SelectValue } from "./ui/select" import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrigger, SelectValue } from "./ui/select"
export default function AddGameDropdown(props: { gameid: string, fullUser: User }) { export default function AddGameDropdown(props: { gameid: string, fullUser: User }) {
return ( return (
<> <>
<Select> <Select>
...@@ -19,7 +20,6 @@ export default function AddGameDropdown(props: { gameid: string, fullUser: User ...@@ -19,7 +20,6 @@ export default function AddGameDropdown(props: { gameid: string, fullUser: User
</SelectTrigger> </SelectTrigger>
<SelectContent> <SelectContent>
<SelectGroup> <SelectGroup>
<SelectLabel>Status</SelectLabel>
<AddGameToPlanList user={props.fullUser!} gameId={props.gameid} /> <AddGameToPlanList user={props.fullUser!} gameId={props.gameid} />
<AddGameToFinishedList user={props.fullUser!} gameId={props.gameid} /> <AddGameToFinishedList user={props.fullUser!} gameId={props.gameid} />
<AddGameToPlayingList user={props.fullUser!} gameId={props.gameid} /> <AddGameToPlayingList user={props.fullUser!} gameId={props.gameid} />
......
...@@ -32,7 +32,6 @@ export default function AddGameToFinishedList(props: { gameId: string, user: Use ...@@ -32,7 +32,6 @@ export default function AddGameToFinishedList(props: { gameId: string, user: Use
formData.id = user.id formData.id = user.id
formData.finishedGameList = props.user.finishedGameList.filter((id) => id !== gameId) formData.finishedGameList = props.user.finishedGameList.filter((id) => id !== gameId)
console.log(formData.finishedGameList)
const response = await fetch('/api/users/gamelists', { const response = await fetch('/api/users/gamelists', {
method: 'PUT', method: 'PUT',
body: JSON.stringify(formData) body: JSON.stringify(formData)
...@@ -71,16 +70,16 @@ export default function AddGameToFinishedList(props: { gameId: string, user: Use ...@@ -71,16 +70,16 @@ export default function AddGameToFinishedList(props: { gameId: string, user: Use
if (!props.user.finishedGameList.includes(parseFloat(props.gameId))) { if (!props.user.finishedGameList.includes(parseFloat(props.gameId))) {
button = ( button = (
<form onSubmit={addGame}> <form onSubmit={addGame}>
<Button type="submit" size="lg"> <Button type="submit" size="lg" variant="ghost">
Add Game To finished-playing-List Finished
</Button> </Button>
</form> </form>
) )
} else { } else {
button = ( button = (
<form onSubmit={removeGame}> <form onSubmit={removeGame}>
<Button type="submit" size="lg" variant={"secondary"}> <Button type="submit" size="lg" variant="ghost">
Remove Game From finished-playing-List Remove Finished
</Button> </Button>
</form> </form>
) )
......
...@@ -32,7 +32,6 @@ export default function AddGameToPlanList(props: { gameId: string, user: User }) ...@@ -32,7 +32,6 @@ export default function AddGameToPlanList(props: { gameId: string, user: User })
formData.id = user.id formData.id = user.id
formData.planningGameList = props.user.planningGameList.filter((id) => id !== gameId) formData.planningGameList = props.user.planningGameList.filter((id) => id !== gameId)
console.log(formData.planningGameList)
const response = await fetch('/api/users/gamelists', { const response = await fetch('/api/users/gamelists', {
method: 'PUT', method: 'PUT',
body: JSON.stringify(formData) body: JSON.stringify(formData)
...@@ -71,16 +70,16 @@ export default function AddGameToPlanList(props: { gameId: string, user: User }) ...@@ -71,16 +70,16 @@ export default function AddGameToPlanList(props: { gameId: string, user: User })
if (!props.user.planningGameList.includes(parseFloat(props.gameId))) { if (!props.user.planningGameList.includes(parseFloat(props.gameId))) {
button = ( button = (
<form onSubmit={addGame}> <form onSubmit={addGame}>
<Button type="submit" size="lg"> <Button type="submit" size="lg" variant={"ghost"}>
Add Game To Planning-to-play-List Planning-to-play-List
</Button> </Button>
</form> </form>
) )
} else { } else {
button = ( button = (
<form onSubmit={removeGame}> <form onSubmit={removeGame}>
<Button type="submit" size="lg" variant={"secondary"}> <Button type="submit" size="lg" variant={"ghost"}>
Remove Game From Planning-to-play-List Remove Planning-to-play
</Button> </Button>
</form> </form>
) )
......
...@@ -32,7 +32,6 @@ export default function AddGameToPlayingList(props: { gameId: string, user: User ...@@ -32,7 +32,6 @@ export default function AddGameToPlayingList(props: { gameId: string, user: User
formData.id = user.id formData.id = user.id
formData.playingGameList = props.user.playingGameList.filter((id) => id !== gameId) formData.playingGameList = props.user.playingGameList.filter((id) => id !== gameId)
console.log(formData.playingGameList)
const response = await fetch('/api/users/gamelists', { const response = await fetch('/api/users/gamelists', {
method: 'PUT', method: 'PUT',
body: JSON.stringify(formData) body: JSON.stringify(formData)
...@@ -56,7 +55,7 @@ export default function AddGameToPlayingList(props: { gameId: string, user: User ...@@ -56,7 +55,7 @@ export default function AddGameToPlayingList(props: { gameId: string, user: User
method: 'PUT', method: 'PUT',
body: JSON.stringify(formData) body: JSON.stringify(formData)
}) })
console.log("add game")
startTransition(() => { startTransition(() => {
// Refresh the current route and fetch new data from the server without // Refresh the current route and fetch new data from the server without
// losing client-side browser or React state. // losing client-side browser or React state.
...@@ -71,16 +70,16 @@ export default function AddGameToPlayingList(props: { gameId: string, user: User ...@@ -71,16 +70,16 @@ export default function AddGameToPlayingList(props: { gameId: string, user: User
if (!props.user.playingGameList.includes(parseFloat(props.gameId))) { if (!props.user.playingGameList.includes(parseFloat(props.gameId))) {
button = ( button = (
<form onSubmit={addGame}> <form onSubmit={addGame}>
<Button type="submit" size="lg"> <Button type="submit" size="lg" variant={"ghost"}>
Add Game To currently-playing-List Currently Playing
</Button> </Button>
</form> </form>
) )
} else { } else {
button = ( button = (
<form onSubmit={removeGame}> <form onSubmit={removeGame}>
<Button type="submit" size="lg" variant={"secondary"}> <Button type="submit" size="lg" variant={"ghost"}>
Remove Game From currently-playing-List Remove Currently Playing
</Button> </Button>
</form> </form>
) )
......
...@@ -53,7 +53,7 @@ export default function AddGameToFavList(props: { userGameList: Number[], gameId ...@@ -53,7 +53,7 @@ export default function AddGameToFavList(props: { userGameList: Number[], gameId
button = ( button = (
<form onSubmit={addGame}> <form onSubmit={addGame}>
<Button type="submit" size="lg"> <Button type="submit" size="lg">
Add Game To Favorite List Add To Favorites
</Button> </Button>
</form> </form>
) )
...@@ -61,7 +61,7 @@ export default function AddGameToFavList(props: { userGameList: Number[], gameId ...@@ -61,7 +61,7 @@ export default function AddGameToFavList(props: { userGameList: Number[], gameId
button = ( button = (
<form onSubmit={removeGame}> <form onSubmit={removeGame}>
<Button type="submit" size="lg" variant={"secondary"}> <Button type="submit" size="lg" variant={"secondary"}>
Remove Game From Favorite List Remove From Favorites
</Button> </Button>
</form> </form>
) )
......
...@@ -32,24 +32,39 @@ export const UserGames = async ({ username }: { username: string }) => { ...@@ -32,24 +32,39 @@ export const UserGames = async ({ username }: { username: string }) => {
redirect('/home') redirect('/home')
} }
let favoritegames = undefined let favoritegames = undefined;
let playingGames = undefined let playingGames = undefined
let finishedGames = undefined let finishedGames = undefined
let planningGames = undefined let planningGames = undefined
if (fullUser?.favGameList?.length !== 0 && fullUser?.favGameList?.length != undefined) { // new Implementation
favoritegames = await getFavoriteGames(fullUser?.favGameList!) let allgames = fullUser.favGameList.concat(fullUser.playingGameList, fullUser.finishedGameList, fullUser.planningGameList);
} let fetchedGames = undefined;
if (fullUser?.playingGameList?.length !== 0) { if (allgames.length !== 0) {
playingGames = await getFavoriteGames(fullUser?.playingGameList!) fetchedGames = await getFavoriteGames(allgames)
}
if (fullUser?.finishedGameList?.length !== 0) { favoritegames = fetchedGames.filter(game => fullUser.favGameList.includes(game.id));
finishedGames = await getFavoriteGames(fullUser?.finishedGameList!) playingGames = fetchedGames.filter(game => fullUser.playingGameList.includes(game.id));
} finishedGames = fetchedGames.filter(game => fullUser.finishedGameList.includes(game.id));
if (fullUser?.planningGameList?.length !== 0) { planningGames = fetchedGames.filter(game => fullUser.planningGameList.includes(game.id));
planningGames = await getFavoriteGames(fullUser?.planningGameList!)
} }
// Old Implementation
/* if (fullUser?.favGameList?.length !== 0 && fullUser?.favGameList?.length != undefined) {
favoritegames = await getFavoriteGames(fullUser?.favGameList!)
}
if (fullUser?.playingGameList?.length !== 0) {
playingGames = await getFavoriteGames(fullUser?.playingGameList!)
}
if (fullUser?.finishedGameList?.length !== 0) {
finishedGames = await getFavoriteGames(fullUser?.finishedGameList!)
}
if (fullUser?.planningGameList?.length !== 0) {
planningGames = await getFavoriteGames(fullUser?.planningGameList!)
} */
return ( return (
<div className="p-3 space-y-12"> <div className="p-3 space-y-12">
<div> <div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment