diff --git a/.husky/pre-commit b/.husky/pre-commit index 7e2936624c..d4a43dd13e 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1,4 @@ #!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" -yarn pre-commit \ No newline at end of file +npm run pre-commit diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 835dc37367..acf2b867ca 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11011,14 +11011,6 @@ packages: dependencies: find-up: 3.0.0 dev: false - resolution: {integrity: sha512-XIidXV8fDr0kKt28vqki84fRK8VW8eTuIa4PChv2MqKuT6C9UjmSKzen6KaWhWEoYvwxFCa7n/tC1SZ3tyq4SQ==} - engines: {node: ^12 || ^14 || >=16} - peerDependencies: - postcss: ^8.2 - dependencies: - postcss: 8.4.38 - postcss-selector-parser: 6.0.15 - dev: false /postcss-browser-comments@4.0.0(browserslist@4.22.2)(postcss@8.4.38): resolution: {integrity: sha512-X9X9/WN3KIvY9+hNERUqX9gncsgBA25XaeR+jshHz2j8+sYyHktHw1JdKuMjeLpGktXidqDhA7b/qm1mrBDmgg==} diff --git a/src/App.jsx b/src/App.jsx index bf142a1aa5..1388175837 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,11 +1,15 @@ import './App.css'; import { Outlet } from 'react-router-dom'; +import { Provider } from 'react-redux'; +import { store } from './Redux/Store'; function App() { return ( -
- -
+ +
+ +
+
); } diff --git a/src/Redux/Store/index.jsx b/src/Redux/Store/index.jsx new file mode 100644 index 0000000000..c7115b77cb --- /dev/null +++ b/src/Redux/Store/index.jsx @@ -0,0 +1,14 @@ +// /src/Redux/Store/index.jsx +// Configure and export the Redux store using Redux Toolkit. +// The "list" slice is handled by the default export from ../reducer/index.jsx + +import { configureStore } from '@reduxjs/toolkit'; +import index from '../Reducer/index.jsx'; + +export const store = configureStore({ + reducer: { + // 'list' will be available on the state as state.list + list: index + } + // You can add middleware or devTools options here if needed +}); diff --git a/src/Redux/reducer/index.jsx b/src/Redux/reducer/index.jsx new file mode 100644 index 0000000000..4d39748130 --- /dev/null +++ b/src/Redux/reducer/index.jsx @@ -0,0 +1,43 @@ +import { createSlice } from '@reduxjs/toolkit'; + +// Initial state for this slice: an array of basket items. +// Each item is expected to be an object with at least an `id` property. +const initialState = []; + +// createSlice automatically generates action creators and action types +// based on the reducers we provide below. +const reduxReducer = createSlice({ + name: 'index', + initialState, + reducers: { + // addItem: adds one or more items into the basket state. + // Payload expectation: + // - If you dispatch a single item object, use: dispatch(addItem(item)) + // - If you dispatch an array of items, use: dispatch(addItem(itemsArray)) + // + // Note: current implementation uses state.push(...item), so the payload + // should be an iterable (e.g. array). If you intend to add a single object, + // change to state.push(item). + addItem: (state, action) => { + const item = action.payload; + + // Spread the payload into state (works if payload is an array). + state.push(...item); + }, + + // removeItem: removes an item by id. + // Expects the payload to be the id of the item to remove. + removeItem: (state, action) => { + const newState = state.filter((item) => item.id !== action.payload); + + // Returning a new array replaces the current slice state. + return newState; + } + } +}); + +// Export generated action creators for use in components. +export const { addItem, removeItem } = reduxReducer.actions; + +// Export the reducer to be included in the store. +export default reduxReducer.reducer;