Skip to content
Snippets Groups Projects
Commit 02f5f605 authored by Yusuf Akgül's avatar Yusuf Akgül :hatching_chick:
Browse files

Merge branch 'fixStatusList' into 'main'

dropdown fix + avoiding 4igdb calls in the same place

See merge request !47
parents ce1ceb45 0fbace8c
No related branches found
No related tags found
1 merge request!47dropdown fix + avoiding 4igdb calls in the same place
Pipeline #39986 passed
......@@ -66,8 +66,13 @@ export default async function GameDetail({ params }: { params: { gameid: string
priority
className="object-cover rounded-lg" />
</Card>
<div className="flex justify-start p-6">
<AddGameDropdown fullUser={fullUser!} gameid={params.gameid} />
<div className="flex flex-col space-y-6 justify-start p-6">
{user &&
<>
< AddGameDropdown fullUser={fullUser!} gameid={params.gameid} />
<AddGameToFavList userGameList={fullUser?.favGameList!} gameId={params.gameid} />
</>
}
</div>
</div>
......@@ -98,13 +103,6 @@ export default async function GameDetail({ params }: { params: { gameid: string
</div>
</div>
</div>
<div className="px-6 md:px-12">
<div className="border-b border-gray-400 dark:border-gray-200" />
<div className="p-6 w-full flex justify-center">
{user && <AddGameToFavList userGameList={fullUser?.favGameList!} gameId={params.gameid} />}
</div>
{/* comments */}
</div>
</Card >
}
......
"use client"
import { IGame } from "@/types/igdb-types"
import { User } from "@prisma/client"
import { useState } from "react"
import AddGameToFinishedList from "./add-game-to-finished-list"
import AddGameToPlanList from "./add-game-to-plan-list"
import AddGameToPlayingList from "./add-game-to-playing-list"
import GameItem from "./game-item"
import { Card } from "./ui/card"
import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrigger, SelectValue } from "./ui/select"
import { Select, SelectContent, SelectGroup, SelectTrigger, SelectValue } from "./ui/select"
export default function AddGameDropdown(props: { gameid: string, fullUser: User }) {
return (
<>
<Select>
<SelectTrigger className={`bg-background border-full w-32 h-8}`}>
<SelectTrigger>
<SelectValue placeholder="Status" />
</SelectTrigger>
<SelectContent>
<SelectGroup>
<SelectLabel>Status</SelectLabel>
<AddGameToPlanList user={props.fullUser!} gameId={props.gameid} />
<AddGameToFinishedList user={props.fullUser!} gameId={props.gameid} />
<AddGameToPlayingList user={props.fullUser!} gameId={props.gameid} />
......@@ -29,5 +23,4 @@ export default function AddGameDropdown(props: { gameid: string, fullUser: User
</>
)
}
\ No newline at end of file
......@@ -32,7 +32,6 @@ export default function AddGameToFinishedList(props: { gameId: string, user: Use
formData.id = user.id
formData.finishedGameList = props.user.finishedGameList.filter((id) => id !== gameId)
console.log(formData.finishedGameList)
const response = await fetch('/api/users/gamelists', {
method: 'PUT',
body: JSON.stringify(formData)
......@@ -71,16 +70,16 @@ export default function AddGameToFinishedList(props: { gameId: string, user: Use
if (!props.user.finishedGameList.includes(parseFloat(props.gameId))) {
button = (
<form onSubmit={addGame}>
<Button type="submit" size="lg">
Add Game To finished-playing-List
<Button type="submit" size="lg" variant="ghost">
Set as Finished
</Button>
</form>
)
} else {
button = (
<form onSubmit={removeGame}>
<Button type="submit" size="lg" variant={"secondary"}>
Remove Game From finished-playing-List
<Button type="submit" size="lg" variant="ghost">
Unset Finished
</Button>
</form>
)
......
......@@ -32,7 +32,6 @@ export default function AddGameToPlanList(props: { gameId: string, user: User })
formData.id = user.id
formData.planningGameList = props.user.planningGameList.filter((id) => id !== gameId)
console.log(formData.planningGameList)
const response = await fetch('/api/users/gamelists', {
method: 'PUT',
body: JSON.stringify(formData)
......@@ -71,16 +70,16 @@ export default function AddGameToPlanList(props: { gameId: string, user: User })
if (!props.user.planningGameList.includes(parseFloat(props.gameId))) {
button = (
<form onSubmit={addGame}>
<Button type="submit" size="lg">
Add Game To Planning-to-play-List
<Button type="submit" size="lg" variant={"ghost"}>
Set as Planning
</Button>
</form>
)
} else {
button = (
<form onSubmit={removeGame}>
<Button type="submit" size="lg" variant={"secondary"}>
Remove Game From Planning-to-play-List
<Button type="submit" size="lg" variant={"ghost"}>
Unset Planning
</Button>
</form>
)
......
......@@ -32,7 +32,6 @@ export default function AddGameToPlayingList(props: { gameId: string, user: User
formData.id = user.id
formData.playingGameList = props.user.playingGameList.filter((id) => id !== gameId)
console.log(formData.playingGameList)
const response = await fetch('/api/users/gamelists', {
method: 'PUT',
body: JSON.stringify(formData)
......@@ -56,7 +55,7 @@ export default function AddGameToPlayingList(props: { gameId: string, user: User
method: 'PUT',
body: JSON.stringify(formData)
})
console.log("add game")
startTransition(() => {
// Refresh the current route and fetch new data from the server without
// losing client-side browser or React state.
......@@ -71,16 +70,16 @@ export default function AddGameToPlayingList(props: { gameId: string, user: User
if (!props.user.playingGameList.includes(parseFloat(props.gameId))) {
button = (
<form onSubmit={addGame}>
<Button type="submit" size="lg">
Add Game To currently-playing-List
<Button type="submit" size="lg" variant={"ghost"}>
Set as Playing
</Button>
</form>
)
} else {
button = (
<form onSubmit={removeGame}>
<Button type="submit" size="lg" variant={"secondary"}>
Remove Game From currently-playing-List
<Button type="submit" size="lg" variant={"ghost"}>
Unset Playing
</Button>
</form>
)
......
......@@ -53,7 +53,7 @@ export default function AddGameToFavList(props: { userGameList: Number[], gameId
button = (
<form onSubmit={addGame}>
<Button type="submit" size="lg">
Add Game To Favorite List
Add To Favorites
</Button>
</form>
)
......@@ -61,7 +61,7 @@ export default function AddGameToFavList(props: { userGameList: Number[], gameId
button = (
<form onSubmit={removeGame}>
<Button type="submit" size="lg" variant={"secondary"}>
Remove Game From Favorite List
Remove From Favorites
</Button>
</form>
)
......
......@@ -8,16 +8,6 @@ import { redirect } from "next/navigation"
export const UserGames = async ({ username }: { username: string }) => {
const user = await getCurrentUser()
const sessionUser = await db.user.findFirst({
where: {
id: user?.id
},
include: {
following: true,
followers: true
}
})
const fullUser = await db.user.findFirst({
where: {
username: username
......@@ -37,19 +27,32 @@ export const UserGames = async ({ username }: { username: string }) => {
let finishedGames = undefined
let planningGames = undefined
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!)
// New Implementation
let allgames = fullUser.favGameList.concat(fullUser.playingGameList, fullUser.finishedGameList, fullUser.planningGameList)
let fetchedGames = undefined
if (allgames.length !== 0) {
fetchedGames = await getFavoriteGames(allgames)
favoritegames = fetchedGames.filter(game => fullUser.favGameList.includes(game.id))
playingGames = fetchedGames.filter(game => fullUser.playingGameList.includes(game.id))
finishedGames = fetchedGames.filter(game => fullUser.finishedGameList.includes(game.id))
planningGames = fetchedGames.filter(game => fullUser.planningGameList.includes(game.id))
}
// 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 (
<div className="p-3 space-y-12">
<div>
......
{
"name": "project_ss23_gameunity",
"version": "0.2.0",
"version": "0.3.0",
"private": true,
"scripts": {
"dev": "next dev",
......
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