Skip to content

Commit

Permalink
[FEAT] #16 - Add tableSlice
Browse files Browse the repository at this point in the history
  • Loading branch information
kingyong9169 committed Dec 4, 2021
1 parent c9f1e51 commit 90cf940
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 10 deletions.
20 changes: 12 additions & 8 deletions client/src/App.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { BrowserRouter, Route, Routes } from "react-router-dom";
import { Provider } from "react-redux";
import { store } from "./store";
import Login from "./pages/Login";
import AllDataBases from "./pages/AllDataBases";
import InsideDataBase from "./pages/InsideDataBase";
Expand All @@ -7,18 +9,20 @@ function App() {
const isAuthorized = localStorage.getItem("isAuthorized");

return (
<BrowserRouter>
{/* {!isAuthorized ? (
<Provider store={store}>
<BrowserRouter>
{/* {!isAuthorized ? (
<Navigate replace to="/login" />
) : (
<Navigate replace to="/" />
)} */}
<Routes>
<Route path="/login" element={<Login />} />
<Route exact path="/" element={<AllDataBases />} />
<Route path="/:dbName" element={<InsideDataBase />} />
</Routes>
</BrowserRouter>
<Routes>
<Route path="/login" element={<Login />} />
<Route exact path="/" element={<AllDataBases />} />
<Route path="/:dbName" element={<InsideDataBase />} />
</Routes>
</BrowserRouter>
</Provider>
);
}

Expand Down
1 change: 0 additions & 1 deletion client/src/__mocks/TableMocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const tables = [
{
id: 1,
title: "user",
name: "name",
},
{
id: 2,
Expand Down
5 changes: 4 additions & 1 deletion client/src/store/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { configureStore, MiddlewareArray } from "@reduxjs/toolkit";
import logger from "./loggerMiddleware";
import { tableSlice } from "./tableSlice";

export const store = configureStore({
reducer: {},
reducer: {
table: tableSlice.reducer,
},
middleware: new MiddlewareArray().concat(logger),
devTools: process.env.NODE_ENV !== "production",
});
26 changes: 26 additions & 0 deletions client/src/store/tableSlice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* eslint-disable no-param-reassign */
import { createSlice, PayloadAction, createAsyncThunk } from "@reduxjs/toolkit";
import axios from "../common/axios";

const name = "table";

const initialState = {
isAddClick: false,
tables: [],
};

export const tableSlice = createSlice({
name,
initialState,
reducers: {
getTables: (state, action) => {
state.tables = [...action.payload];
},
add: (state, action) => {
state.isAddClick = action.payload; // 상태 변경 예시 1
},
},
extraReducers: {},
});

export const { getTables, add } = tableSlice.actions;

0 comments on commit 90cf940

Please sign in to comment.