-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Monique Cheng
committed
Apr 9, 2024
1 parent
19d0c3a
commit 2d5b4ea
Showing
6 changed files
with
223 additions
and
325 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import React, { useState } from 'react'; | ||
|
||
import { useRouter } from 'next/navigation'; | ||
|
||
import { Body1Bold, Body2, Body3 } from '@/styles/fonts'; | ||
|
||
import { | ||
HeartIcon, | ||
Hover, | ||
FavoriteDiv, | ||
ProductNameDiv, | ||
ViewItem, | ||
TransparentButton, | ||
} from './styles'; | ||
|
||
import { addOrRemoveProductFromFavorite } from '../../api/supabase/queries/user_queries'; | ||
|
||
import { Product } from '../../schema/schema'; | ||
|
||
export default function IndividualItem(props: { | ||
favorite: Product; | ||
setFavorites: (category: Product[]) => void; | ||
Favorites: Product[]; | ||
}) { | ||
const { favorite, Favorites, setFavorites } = props; | ||
const router = useRouter(); | ||
const [hovering, setHovering] = useState(false); | ||
|
||
async function clickFunctions(props2: { fav: Product }) { | ||
const { fav } = props2; | ||
addOrRemoveProductFromFavorite(fav, false); | ||
setFavorites(Favorites.filter(Prod => Prod.id !== fav.id)); | ||
} | ||
|
||
return ( | ||
<FavoriteDiv key={favorite.id}> | ||
<img | ||
src={favorite.photo} | ||
alt={favorite.name} | ||
style={{ width: '150px', height: '150px' }} | ||
/> | ||
|
||
<ProductNameDiv> | ||
<Body1Bold>{favorite.name}</Body1Bold> | ||
<Body2>Category: {favorite.category}</Body2> | ||
<ViewItem onClick={() => router.push(`/${favorite.id}`)}> | ||
<Body2>View Item</Body2> | ||
</ViewItem> | ||
</ProductNameDiv> | ||
|
||
<TransparentButton | ||
onClick={() => clickFunctions({ fav: favorite })} | ||
onMouseEnter={() => setHovering(true)} | ||
onMouseLeave={() => setHovering(false)} | ||
> | ||
<Hover $ishovering={hovering}> | ||
<Body3>Remove from favorites</Body3> | ||
</Hover> | ||
<HeartIcon /> | ||
</TransparentButton> | ||
</FavoriteDiv> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import React, { useState } from 'react'; | ||
|
||
import { Body1Bold, Body2, Body3 } from '@/styles/fonts'; | ||
|
||
import { HeartIcon, Hover, FavoriteDiv, ProductNameDiv } from './styles'; | ||
|
||
import { addOrRemoveProductFromFavorite } from '../../api/supabase/queries/user_queries'; | ||
|
||
import { Product } from '../../schema/schema'; | ||
import { TransparentButton } from '../favorites/styles'; | ||
|
||
export default function IndividualItem(props: { | ||
favorite: Product; | ||
setFavorites: (category: Product[]) => void; | ||
Favorites: Product[]; | ||
}) { | ||
const { favorite, Favorites, setFavorites } = props; | ||
const [hovering, setHovering] = useState(false); | ||
|
||
async function clickFunctions(props2: { fav: Product }) { | ||
const { fav } = props2; | ||
addOrRemoveProductFromFavorite(fav, false); | ||
setFavorites(Favorites.filter(Prod => Prod.id !== fav.id)); | ||
} | ||
|
||
return ( | ||
<FavoriteDiv key={favorite.id}> | ||
<img | ||
src={favorite.photo} | ||
alt={favorite.name} | ||
style={{ width: '75px', height: '75px' }} | ||
/> | ||
<ProductNameDiv> | ||
<Body1Bold>{favorite.name}</Body1Bold> | ||
<Body2>Category: {favorite.category}</Body2> | ||
</ProductNameDiv> | ||
<TransparentButton | ||
onClick={() => clickFunctions({ fav: favorite })} | ||
onMouseEnter={() => setHovering(true)} | ||
onMouseLeave={() => setHovering(false)} | ||
> | ||
<Hover $ishovering={hovering}> | ||
<Body3>Remove from favorites</Body3> | ||
</Hover> | ||
<HeartIcon /> | ||
</TransparentButton> | ||
</FavoriteDiv> | ||
); | ||
} |
Oops, something went wrong.