Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn pre-commit
npm run pre-commit
8 changes: 0 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -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 (
<main className="app-body">
<Outlet />
</main>
<Provider store={store}>
<main className="app-body">
<Outlet />
</main>
</Provider>
);
}

Expand Down
14 changes: 14 additions & 0 deletions src/Redux/Store/index.jsx
Original file line number Diff line number Diff line change
@@ -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
});
43 changes: 43 additions & 0 deletions src/Redux/reducer/index.jsx
Original file line number Diff line number Diff line change
@@ -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;