diff --git a/starter/src/App.js b/starter/src/App.js deleted file mode 100644 index 040be9f..0000000 --- a/starter/src/App.js +++ /dev/null @@ -1,4 +0,0 @@ -function App() { - return

Redux Toolkit

; -} -export default App; diff --git a/starter/src/App.jsx b/starter/src/App.jsx new file mode 100644 index 0000000..14f8f32 --- /dev/null +++ b/starter/src/App.jsx @@ -0,0 +1,10 @@ +import CartContainer from "./components/CartContainer"; +import Navbar from "./components/Navbar"; + +function App() { + return
+ + +
; +} +export default App; diff --git a/starter/src/components/CartContainer/index.jsx b/starter/src/components/CartContainer/index.jsx new file mode 100644 index 0000000..6fb0a1c --- /dev/null +++ b/starter/src/components/CartContainer/index.jsx @@ -0,0 +1,56 @@ +import React from "react"; +import { useSelector } from "react-redux"; + +import CartItem from "../CartItem"; + +const CartContainer = () => { + const {amount, cartItems, total} = useSelector(store => store.cart); + + if (amount < 1) { + return ( +
+ {/* cart header */} + +
+

your bag

+

is currently empty

+
+
+ ); + } + + return ( +
+ {/* cart header */} +
+

your bag

+
+ + {/* cart items */} +
+ {cartItems.map(item => { + return ; + })} +
+ + {/* cart footer */} + +
+ ); +}; + +export default CartContainer; + diff --git a/starter/src/components/CartItem/index.jsx b/starter/src/components/CartItem/index.jsx new file mode 100644 index 0000000..f6f737a --- /dev/null +++ b/starter/src/components/CartItem/index.jsx @@ -0,0 +1,10 @@ +import React from "react"; + +const CartItem = () => { + return ( +
Cart Item
+ ); +}; + +export default CartItem; + diff --git a/starter/src/components/Navbar/index.jsx b/starter/src/components/Navbar/index.jsx new file mode 100644 index 0000000..eafdbca --- /dev/null +++ b/starter/src/components/Navbar/index.jsx @@ -0,0 +1,29 @@ +import React from "react"; +import { useSelector } from "react-redux"; + +import {CartIcon} from "../../icons"; + +const Navbar = () => { + const {amount} = useSelector(state => state.cart); + + return ( + + ); +}; + +export default Navbar; + diff --git a/starter/src/features/cart/cartSlice.js b/starter/src/features/cart/cartSlice.js new file mode 100644 index 0000000..7994cf5 --- /dev/null +++ b/starter/src/features/cart/cartSlice.js @@ -0,0 +1,20 @@ +import { createSlice } from "@reduxjs/toolkit"; + +import cartItems from "../../cartItems.js"; + +const initialState = { + cartItems: cartItems, + amount: 4, + total: 0, + isLoading: true +}; + +const cartSlice = createSlice({ + name: "cart", + initialState, +}); + +console.log(cartSlice); + +export default cartSlice.reducer; + diff --git a/starter/src/icons.js b/starter/src/icons.js index 9c3b4f5..4116546 100644 --- a/starter/src/icons.js +++ b/starter/src/icons.js @@ -46,3 +46,10 @@ export const ChevronUp = () => { ); }; + +export const Testing = () => ( + + + +); + diff --git a/starter/src/index.js b/starter/src/index.js index ba22d89..eb31d32 100644 --- a/starter/src/index.js +++ b/starter/src/index.js @@ -1,13 +1,18 @@ import React from 'react'; import { createRoot } from 'react-dom/client'; +import { Provider } from 'react-redux'; + import './index.css'; import App from './App'; +import { store } from './store'; const container = document.getElementById('root'); const root = createRoot(container); root.render( - + + + ); diff --git a/starter/src/store.js b/starter/src/store.js new file mode 100644 index 0000000..3c02dd1 --- /dev/null +++ b/starter/src/store.js @@ -0,0 +1,10 @@ +import { configureStore } from "@reduxjs/toolkit"; + +import cartReducer from "./features/cart/cartSlice"; + +export const store = configureStore({ + reducer: { + cart: cartReducer + } +}); +