diff --git a/Client/src/Components/BasicTable/index.jsx b/Client/src/Components/BasicTable/index.jsx index af71ee3a5..8b6cafd91 100644 --- a/Client/src/Components/BasicTable/index.jsx +++ b/Client/src/Components/BasicTable/index.jsx @@ -15,6 +15,7 @@ import { Stack, } from "@mui/material"; import { useDispatch, useSelector } from "react-redux"; +import { useLocation, useParams } from "react-router-dom"; import { setRowsPerPage } from "../../Features/UI/uiSlice"; import LeftArrowDouble from "../../assets/icons/left-arrow-double.svg?react"; import RightArrowDouble from "../../assets/icons/right-arrow-double.svg?react"; @@ -142,11 +143,13 @@ const TablePaginationActions = (props) => { * */ -const BasicTable = ({ data, paginated, reversed, rows = 5 }) => { +const BasicTable = ({ data, paginated, reversed }) => { const theme = useTheme(); + const location = useLocation(); const dispatch = useDispatch(); - const { table } = useSelector((state) => state.ui); - let rowsPerPage = table.rowsPerPage; + const uiState = useSelector((state) => state.ui); + let table = location.pathname.split("/").pop(); + let rowsPerPage = uiState[table].rowsPerPage; const [page, setPage] = useState(0); useEffect(() => { @@ -158,7 +161,12 @@ const BasicTable = ({ data, paginated, reversed, rows = 5 }) => { }; const handleChangeRowsPerPage = (event) => { - dispatch(setRowsPerPage(parseInt(event.target.value, 10))); + dispatch( + setRowsPerPage({ + value: parseInt(event.target.value, 10), + table: table, + }) + ); setPage(0); }; diff --git a/Client/src/Features/UI/uiSlice.js b/Client/src/Features/UI/uiSlice.js index 1ae7f5c74..ebea20bf1 100644 --- a/Client/src/Features/UI/uiSlice.js +++ b/Client/src/Features/UI/uiSlice.js @@ -3,7 +3,10 @@ import { createSlice } from "@reduxjs/toolkit"; // Initial state for UI settings. // Add more settings as needed (e.g., theme preferences, user settings) const initialState = { - table: { + monitors: { + rowsPerPage: 5, + }, + team: { rowsPerPage: 5, }, sidebar: { @@ -16,7 +19,7 @@ const uiSlice = createSlice({ initialState, reducers: { setRowsPerPage: (state, action) => { - state.table.rowsPerPage = action.payload; + state[action.payload.table].rowsPerPage = action.payload.value; }, toggleSidebar: (state) => { state.sidebar.collapsed = !state.sidebar.collapsed;