-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Shopping cart feature debugged and refactoring. Cart route added
Closes #30
- Loading branch information
1 parent
6c6e7c3
commit 1b58b7c
Showing
8 changed files
with
108 additions
and
55 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,51 @@ | ||
'use client' | ||
import React from 'react' | ||
import { useContext } from 'react' | ||
//Components | ||
import { BasketContext } from '../context/BasketContext' | ||
import Image from 'next/image' | ||
import BackArrow from '@/app/components/BackArrow' | ||
import RemoveCartButton from '../components/RemoveCartButton' | ||
|
||
const Cart = () => { | ||
const { state } = useContext(BasketContext) | ||
console.log(state); | ||
|
||
return ( | ||
<main> | ||
<BackArrow path={'listings'} /> | ||
<div className='text-center mx-4 mt-10 '> | ||
{state.map((product) => { | ||
return ( | ||
<> | ||
<div key={product.id}> | ||
<Image | ||
src={product.image} | ||
layout='responsive' | ||
width={1000} | ||
height={700} | ||
alt='A pretty painting' | ||
/> | ||
</div> | ||
<div className='bg-secondary px-4 shadow-lg'> | ||
<h2 className='py-4 text-white text-3xl'>{product.name}</h2> | ||
<div className='flex gap-2 justify-center'> | ||
<p className='text-sm italic'>{product.artist}</p> | ||
<p className='text-sm italic'>{product.date}</p> | ||
</div> | ||
<div className='flex items-center justify-center gap-40 py-6 '> | ||
<p> | ||
<small>{product.price}</small> | ||
</p> | ||
<RemoveCartButton product={product} /> | ||
</div> | ||
</div> | ||
</> | ||
) | ||
})} | ||
</div> | ||
</main> | ||
) | ||
} | ||
|
||
export default Cart |
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
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,31 @@ | ||
'use client' | ||
|
||
import { createContext, useReducer } from 'react' | ||
|
||
const initialBasket = [] | ||
|
||
const reducer = (state, action) => { | ||
switch (action.type) { | ||
case 'add': | ||
return [...state, action.payload.product] | ||
case 'delete': | ||
return state.filter((item) => item.id !== action.payload.id) | ||
default: | ||
throw new Error('No case for that type') | ||
} | ||
} | ||
|
||
export const BasketContext = createContext({ | ||
state: initialBasket, | ||
dispatch: () => null, | ||
}) | ||
|
||
export const BasketContextProvider = ({ children }) => { | ||
const [state, dispatch] = useReducer(reducer, initialBasket) | ||
|
||
return ( | ||
<BasketContext.Provider value={{ state, dispatch }}> | ||
{children} | ||
</BasketContext.Provider> | ||
) | ||
} |
This file was deleted.
Oops, something went wrong.
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