From 351a17d5fba4b36985f63208f4aaae5f0e19bd77 Mon Sep 17 00:00:00 2001 From: omid2007hope Date: Wed, 10 Dec 2025 10:07:27 +0100 Subject: [PATCH 1/3] fix pnpm lock, install react-redux, and integrate Redux Provider --- pnpm-lock.yaml | 8 ------- src/App.jsx | 10 +++++--- src/Redux/Store/index.jsx | 14 +++++++++++ src/Redux/reducer/index.jsx | 46 +++++++++++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+), 11 deletions(-) create mode 100644 src/Redux/Store/index.jsx create mode 100644 src/Redux/reducer/index.jsx 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..14be073fa2 --- /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..0c9efdd8f9 --- /dev/null +++ b/src/Redux/reducer/index.jsx @@ -0,0 +1,46 @@ +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); + + // Persist basket items to localStorage so they survive page reloads. + localStorage.setItem('BasketItems', JSON.stringify(state)); + }, + + // 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; From 0b8e65fe9fdac859f9ca52e3ecc82f8f8cc4d337 Mon Sep 17 00:00:00 2001 From: omid2007hope Date: Wed, 10 Dec 2025 10:08:40 +0100 Subject: [PATCH 2/3] switch pre-commit hook to npm runner --- .husky/pre-commit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From c3aaa585fd877dcdfe5353788c53f6199cd0369c Mon Sep 17 00:00:00 2001 From: omid2007hope Date: Wed, 10 Dec 2025 10:43:50 +0100 Subject: [PATCH 3/3] Just a quick fix following the new update --- src/Redux/Store/index.jsx | 2 +- src/Redux/reducer/index.jsx | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Redux/Store/index.jsx b/src/Redux/Store/index.jsx index 14be073fa2..c7115b77cb 100644 --- a/src/Redux/Store/index.jsx +++ b/src/Redux/Store/index.jsx @@ -3,7 +3,7 @@ // The "list" slice is handled by the default export from ../reducer/index.jsx import { configureStore } from '@reduxjs/toolkit'; -import index from '../reducer/index.jsx'; +import index from '../Reducer/index.jsx'; export const store = configureStore({ reducer: { diff --git a/src/Redux/reducer/index.jsx b/src/Redux/reducer/index.jsx index 0c9efdd8f9..4d39748130 100644 --- a/src/Redux/reducer/index.jsx +++ b/src/Redux/reducer/index.jsx @@ -23,9 +23,6 @@ const reduxReducer = createSlice({ // Spread the payload into state (works if payload is an array). state.push(...item); - - // Persist basket items to localStorage so they survive page reloads. - localStorage.setItem('BasketItems', JSON.stringify(state)); }, // removeItem: removes an item by id.