Skip to content

Commit 780ec26

Browse files
committed
Refactor visualization, search and info with redux
Refactor types, clean up + reorganize files
1 parent d763ab1 commit 780ec26

35 files changed

+766
-914
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"@types/react-dom": "^17.0.0",
2222
"@types/react-modal": "^3.12.1",
2323
"@types/react-redux": "^7.1.18",
24+
"@types/redux-watch": "^1.1.0",
2425
"@types/styled-components": "^5.1.11",
2526
"bulma": "^0.9.3",
2627
"classnames": "^2.3.1",
@@ -39,6 +40,7 @@
3940
"react-modal": "^3.14.3",
4041
"react-redux": "^7.2.5",
4142
"react-scripts": "4.0.3",
43+
"redux-watch": "^1.2.0",
4244
"rehype-katex": "^5.0.0",
4345
"remark-math": "^4.0.0",
4446
"source-map-explorer": "^2.5.2",

src/App.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React, { useEffect } from 'react'
22
import Layout from './components/Layout'
3-
import DataContainer from './components/DataContainer'
43
import { init as initLogin } from './features/login/loginSlice'
54
import { useAppDispatch } from './app/hooks'
65

@@ -10,11 +9,7 @@ const App: React.FC = () => {
109
dispatch(initLogin())
1110
}, [dispatch])
1211

13-
return (
14-
<DataContainer>
15-
<Layout />
16-
</DataContainer>
17-
)
12+
return <Layout />
1813
}
1914

2015
export default App

src/app/store.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,34 @@
11
import { configureStore, ThunkAction, Action } from '@reduxjs/toolkit'
22
import loginReducer from '../features/login/loginSlice'
3+
import mathReducer, { addGraph } from '../features/math/mathSlice'
4+
import watch from 'redux-watch'
5+
import { addDocuments } from '../features/math/mathSlice'
36

47
export const store = configureStore({
58
reducer: {
69
login: loginReducer,
10+
math: mathReducer,
711
},
812
})
913

14+
// when userId changes, we want to fetch math documents of that new user
15+
const watchLogin = watch(store.getState, 'login.webId')
16+
store.subscribe(
17+
watchLogin((webId: string) => {
18+
store.dispatch(addDocuments(webId))
19+
}),
20+
)
21+
22+
// when documents change, we want to fetch the new document
23+
// TODO also remove the old documents
24+
const watchDocuments = watch(store.getState, 'math.entities.document.allIds')
25+
store.subscribe(
26+
watchDocuments((newDocs: string[], oldDocs: string[]) => {
27+
const diff = newDocs.filter((d: string) => !oldDocs.includes(d))
28+
diff.forEach(uri => store.dispatch(addGraph(uri)))
29+
}),
30+
)
31+
1032
export type AppDispatch = typeof store.dispatch
1133
export type RootState = ReturnType<typeof store.getState>
1234
export type AppThunk<ReturnType = void> = ThunkAction<

src/app/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export interface Dictionary<T> {
2+
[key: string]: T
3+
}

src/components/DataContainer.tsx

Lines changed: 0 additions & 72 deletions
This file was deleted.

src/components/Layout.tsx

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import React from 'react'
22
import Login from '../features/login/Login'
3-
import VisualizationContainer from './VisualizationContainer'
3+
import VisualizationContainer from '../features/math/visualization/VisualizationContainer'
44
import styled from 'styled-components'
5-
import { PeopleListContainer } from './PeopleList'
65
import About from './About'
76

87
const PositionedLogin = styled(Login)`
@@ -18,15 +17,6 @@ const PositionedAbout = styled(About)`
1817
right: 1rem;
1918
`
2019

21-
const PositionedPeopleList = styled(PeopleListContainer)`
22-
position: fixed;
23-
top: 1rem;
24-
left: 1rem;
25-
display: block;
26-
background-color: white;
27-
padding: 0.25rem;
28-
`
29-
3020
const FullSizeVisualization = styled(VisualizationContainer)`
3121
height: 100vh;
3222
width: 100vw;
@@ -36,8 +26,6 @@ const FullSizeVisualization = styled(VisualizationContainer)`
3626
const Layout: React.FC = () => {
3727
return (
3828
<>
39-
<PositionedPeopleList />
40-
4129
<PositionedLogin />
4230

4331
<PositionedAbout />

src/components/PeopleList.tsx

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/components/Search.tsx

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/components/SessionGate.tsx

Lines changed: 0 additions & 46 deletions
This file was deleted.

src/components/SessionPrompt.tsx

Lines changed: 0 additions & 59 deletions
This file was deleted.

0 commit comments

Comments
 (0)