Skip to content

Commit c947043

Browse files
useSelector getting called twice, idk why. Setting up the Cell Lists.
1 parent 16ce6d0 commit c947043

File tree

10 files changed

+102
-16
lines changed

10 files changed

+102
-16
lines changed

.vscode/launch.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "pwa-chrome",
9+
"request": "launch",
10+
"name": "Launch Chrome against localhost",
11+
"url": "http://localhost:8080",
12+
"webRoot": "${workspaceFolder}"
13+
}
14+
]
15+
}

package-lock.json

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
]
6060
},
6161
"devDependencies": {
62-
"gh-pages": "^3.1.0"
62+
"gh-pages": "^3.1.0",
63+
"redux-devtools-extension": "^2.13.9"
6364
}
6465
}

src/App.tsx

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React, { useEffect } from "react";
22
import * as esbuild from "esbuild-wasm";
3-
import Cell from "./components/CodeCell/Cell";
4-
import MarkdownEditor from "./components/MarkdownEditor/MarkdownEditor";
5-
3+
import CellList from "./components/CellList/CellList";
64
import makeStyles from "./styles";
5+
import { CssBaseline, ThemeProvider } from "@material-ui/core";
6+
import theme from "./theme";
77

88
const App: React.FC = () => {
99
const classes = makeStyles();
@@ -30,10 +30,12 @@ const App: React.FC = () => {
3030
}, []);
3131

3232
return (
33-
<div className={classes.wrapper}>
34-
<MarkdownEditor />
35-
<Cell />
36-
</div>
33+
<ThemeProvider theme={theme}>
34+
<div className={classes.wrapper}>
35+
<CssBaseline />
36+
<CellList />
37+
</div>
38+
</ThemeProvider>
3739
);
3840
};
3941

src/Redux/store.ts

+22
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,31 @@
11
import { createStore, applyMiddleware, compose } from "redux";
22
import thunk from "redux-thunk";
33
import rootReducer from "./reducers";
4+
import { composeWithDevTools } from "redux-devtools-extension";
5+
6+
// Testing
7+
import { ActionType } from "./action-types";
48

59
export const Store = createStore(
610
rootReducer,
711
{},
812
compose(applyMiddleware(thunk))
913
);
14+
15+
console.log(Store.getState());
16+
17+
Store.dispatch({
18+
type: ActionType.INSERT_CELL_BEFORE,
19+
payload: {
20+
id: null,
21+
type: "text",
22+
},
23+
});
24+
25+
Store.dispatch({
26+
type: ActionType.INSERT_CELL_BEFORE,
27+
payload: {
28+
id: null,
29+
type: "code",
30+
},
31+
});

src/components/CellList/CellList.tsx

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from "react";
2+
import { useTypedSelector } from "../../hooks/useTypedSelector";
3+
import CellItem from "./CellListItem/CellItem";
4+
5+
const CellList: React.FC = () => {
6+
// sort data according to order from state
7+
const cells = useTypedSelector(({ cell: { data, order } }) =>
8+
order.map((id) => data[id])
9+
);
10+
11+
console.log(cells);
12+
13+
const renderedCells = cells.map((cell) => (
14+
<CellItem key={cell.id} cell={cell} />
15+
));
16+
17+
return <div>{renderedCells}</div>;
18+
};
19+
20+
export default CellList;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React from "react";
2+
import { CellListItemInterface } from "../../../interfaces/index";
3+
4+
import Cell from "../../CodeCell/Cell";
5+
import Editor from "../../MarkdownEditor/MarkdownEditor";
6+
7+
const CellItem: React.FC<CellListItemInterface> = ({ cell }) => {
8+
let child: JSX.Element;
9+
10+
if (cell.type === "code") {
11+
child = <Cell />;
12+
} else {
13+
child = <Editor />;
14+
}
15+
16+
return <div>{child}</div>;
17+
};
18+
19+
export default CellItem;

src/hooks/useTypedSelector.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { TypedUseSelectorHook, useSelector } from "react-redux";
2+
import { RootState } from "../Redux/reducers";
3+
4+
export const useTypedSelector: TypedUseSelectorHook<RootState> = useSelector;

src/index.tsx

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
import reactDom from "react-dom";
22
import App from "./App";
3-
import theme from "./theme";
4-
import { ThemeProvider } from "@material-ui/core/styles";
5-
import { CssBaseline } from "@material-ui/core";
6-
73
import { Provider } from "react-redux";
84
import { Store } from "./Redux";
95

106
reactDom.render(
117
<Provider store={Store}>
12-
<ThemeProvider theme={theme}>
13-
<CssBaseline />
14-
<App />
15-
</ThemeProvider>
8+
<App />
169
</Provider>,
1710
document.getElementById("root")
1811
);

src/interfaces/Cell/CellInterface.ts

+4
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ export interface CellInterface {
66
content: string;
77
type: CellType;
88
}
9+
10+
export interface CellListItemInterface {
11+
cell: CellInterface;
12+
}

0 commit comments

Comments
 (0)