Skip to content
This repository was archived by the owner on Dec 19, 2024. It is now read-only.

Commit df709c9

Browse files
author
haad
committed
Refactoring and clean ups
1 parent 92f1b30 commit df709c9

File tree

10 files changed

+14
-122
lines changed

10 files changed

+14
-122
lines changed

src/App.js

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Route, Switch } from 'react-router-dom'
44

55
import { actions, loadingState, StateProvider } from './state'
66

7-
import Status from './components/Status'
7+
import Systems from './components/Systems'
88
import Header from './components/Header'
99

1010
import DatabaseView from './views/Database'
@@ -30,21 +30,6 @@ function App () {
3030

3131
const reducer = (state, action) => {
3232
switch (action.type) {
33-
case actions.AUTH.OPEN_LOGIN_DIALOG:
34-
return {
35-
...state,
36-
loginDialogOpen: true
37-
}
38-
case actions.AUTH.CLOSE_LOGIN_DIALOG:
39-
return {
40-
...state,
41-
loginDialogOpen: false
42-
}
43-
case actions.AUTH.SET_USER:
44-
return {
45-
...state,
46-
user: action.user
47-
}
4833
case actions.SYSTEMS.SET_ORBITDB:
4934
return {
5035
...state,
@@ -110,7 +95,7 @@ function App () {
11095
<StateProvider initialState={initialState} reducer={reducer}>
11196
<Pane background='tint1' height='100%'>
11297
<Header />
113-
<Status />
98+
<Systems />
11499
<Switch>
115100
<Route path='/search'>
116101
<SearchResultsView />

src/components/AddDialog.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React from 'react'
22
import {
33
Dialog,
4-
Select,
54
TextInput
65
} from 'evergreen-ui'
76

src/components/Header.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,14 @@ import React from 'react'
22
import { useHistory } from 'react-router-dom'
33
import {
44
majorScale,
5-
minorScale,
65
Heading,
7-
Icon,
86
Link,
9-
Menu,
107
Pane,
11-
Popover,
12-
Position,
13-
SearchInput,
14-
Text
8+
SearchInput
159
} from 'evergreen-ui'
1610

17-
import { actions, useStateValue } from '../state'
18-
1911
function Header () {
2012
const history = useHistory()
21-
const [appState, dispatch] = useStateValue()
2213

2314
function handleKeyUp (event) {
2415
// TODO: Do not use "ENTER" key as the trigger, maybe onSubmit of a form

src/components/LogStoreControls.js

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,17 @@
1-
import React, { useState, useEffect } from 'react'
2-
import { useHistory, useParams } from 'react-router-dom'
1+
import React from 'react'
32
import {
43
majorScale,
54
Button,
6-
Code,
75
Heading,
8-
Icon,
9-
IconButton,
10-
Link,
116
Pane,
12-
Paragraph,
13-
Pre,
14-
Spinner,
15-
Strong,
16-
Text,
177
TextInput
188
} from 'evergreen-ui'
199

20-
import { getDB } from '../database'
21-
import { useStateValue, actions, loadingState } from '../state'
22-
import formatDistance from 'date-fns/formatDistance'
23-
24-
const colors = {
25-
eventlog: '#47B881',
26-
feed: '#14B5D0',
27-
keyvalue: '#1070CA',
28-
docstore: '#D9822B',
29-
counter: '#735DD0',
30-
}
10+
import { useStateValue, actions } from '../state'
3111

3212
function EventLogControls () {
33-
const { programName, dbName } = useParams()
3413
const [appState, dispatch] = useStateValue()
35-
const history = useHistory()
3614
const [value, setValue] = React.useState('')
37-
const [entry, setEntry] = React.useState(null)
38-
const [address] = React.useState(`/orbitdb/${programName}/${dbName}`)
3915

4016
function handleValueChange (event) {
4117
setValue(event.target.value)

src/components/ProgramList.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import React from 'react'
22

33
import {
4-
majorScale,
5-
Button,
64
IconButton,
75
Table
86
} from 'evergreen-ui'
97

108
import { useHistory } from 'react-router-dom'
11-
import {formatDistanceToNow, formatRFC7231} from 'date-fns'
9+
import { formatDistanceToNow } from 'date-fns'
1210

1311
const colors = {
1412
eventlog: '#47B881',

src/components/Status.js renamed to src/components/Systems.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,18 @@
11
import React from 'react'
2-
import { useHistory } from 'react-router-dom'
32
import {
43
majorScale,
54
minorScale,
6-
Heading,
75
Icon,
86
Link,
9-
Menu,
107
Pane,
11-
Popover,
12-
Position,
13-
SearchInput,
14-
Spinner,
158
Text
169
} from 'evergreen-ui'
1710

1811
import { initIPFS, initOrbitDB, getAllDatabases } from '../database'
1912
import { actions, useStateValue } from '../state'
2013

21-
function Status () {
22-
const history = useHistory()
14+
function Systems () {
2315
const [appState, dispatch] = useStateValue()
24-
const [loading, setLoading] = React.useState(false)
2516

2617

2718
React.useEffect(() => {
@@ -38,7 +29,7 @@ function Status () {
3829
dispatch({ type: actions.PROGRAMS.SET_PROGRAMS_LOADING, loading: false })
3930
})
4031
})
41-
}, [])
32+
}, [dispatch])
4233

4334
const statusIconSize = 8
4435

@@ -81,4 +72,4 @@ function Status () {
8172
)
8273
}
8374

84-
export default Status
75+
export default Systems

src/config/index.js

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

src/database/index.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
import IPFS from 'ipfs'
22
import OrbitDB from 'orbit-db'
3-
import config from '../config'
4-
5-
const get = async url => {
6-
const response = await fetch(url)
7-
const json = await response.json()
8-
return json
9-
}
103

4+
// OrbitDB instance
115
let orbitdb
126

137
// Databases

src/state/index.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ export const StateProvider = ({ reducer, initialState, children }) => (
1111
export const useStateValue = () => useContext(StateContext)
1212

1313
export const actions = {
14-
AUTH: {
15-
OPEN_LOGIN_DIALOG: 'OPEN_LOGIN_DIALOG',
16-
CLOSE_LOGIN_DIALOG: 'CLOSE_LOGIN_DIALOG',
17-
SET_USER: 'SET_USER'
18-
},
1914
DB: {
2015
OPEN_CREATEDB_DIALOG: 'OPEN_CREATEDB_DIALOG',
2116
CLOSE_CREATEDB_DIALOG: 'CLOSE_CREATEDB_DIALOG',
@@ -30,12 +25,6 @@ export const actions = {
3025
PROGRAMS: {
3126
SET_PROGRAMS: 'SET_PROGRAMS',
3227
SET_PROGRAMS_LOADING: 'SET_PROGRAMS_LOADING',
33-
SET_POPULAR: 'SET_POPULAR',
34-
SET_POPULAR_LOADING: 'SET_POPULAR_LOADING',
35-
SET_STATS: 'SET_STATS',
36-
SET_STATS_LOADING: 'SET_STATS_LOADING',
37-
SET_CATEGORIES: 'SET_CATEGORIES',
38-
SET_CATEGORIES_LOADING: 'SET_CATEGORIES_LOADING',
3928
SET_PROGRAM: 'SET_PROGRAM',
4029
SET_PROGRAM_LOADING: 'SET_PROGRAM_LOADING'
4130
}

src/views/Database.js

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
1-
import React, { useState, useEffect } from 'react'
1+
import React, { useEffect } from 'react'
22
import { useHistory, useParams } from 'react-router-dom'
33
import {
44
majorScale,
5-
Button,
6-
Code,
75
Heading,
8-
Icon,
96
IconButton,
10-
Link,
117
Pane,
12-
Paragraph,
138
Pre,
149
Spinner,
15-
Strong,
16-
Text,
17-
TextInput
10+
Text
1811
} from 'evergreen-ui'
1912

2013
import LogStoreControls from '../components/LogStoreControls'
@@ -23,8 +16,7 @@ import DocumentStoreControls from '../components/DocumentStoreControls'
2316
import CounterStoreControls from '../components/CounterStoreControls'
2417

2518
import { getDB } from '../database'
26-
import { useStateValue, actions, loadingState } from '../state'
27-
import formatDistance from 'date-fns/formatDistance'
19+
import { useStateValue, actions } from '../state'
2820

2921
const colors = {
3022
eventlog: '#47B881',
@@ -38,15 +30,10 @@ function ProgramView () {
3830
const { programName, dbName } = useParams()
3931
const [appState, dispatch] = useStateValue()
4032
const history = useHistory()
41-
const [value, setValue] = React.useState('')
4233
const [entry, setEntry] = React.useState(null)
4334
const [loading, setLoading] = React.useState(false)
4435
const [address] = React.useState(`/orbitdb/${programName}/${dbName}`)
4536

46-
function handleValueChange (event) {
47-
setValue(event.target.value)
48-
}
49-
5037
const handleSelect = (entry) => {
5138
setEntry(entry)
5239
}
@@ -84,22 +71,7 @@ function ProgramView () {
8471
fetchDB(address)
8572
const program = appState.programs.find(p => p.payload.value.address === address)
8673
dispatch({ type: actions.PROGRAMS.SET_PROGRAM, program })
87-
}, [dispatch, programName, dbName])
88-
89-
function renderDbType (db) {
90-
if (db && db.type === 'eventlog')
91-
return 'EVENT LOG'
92-
else if (db && db.type === 'feed')
93-
return 'FEED'
94-
else if (db && db.type === 'keyvalue')
95-
return 'KEY-VALUE STORE'
96-
else if (db && db.type === 'docstore')
97-
return 'DOCUMENT STORE'
98-
else if (db && db.type === 'counter')
99-
return 'COUNTER'
100-
else
101-
return ''
102-
}
74+
}, [dispatch, address, appState.programs])
10375

10476
function renderProgram () {
10577
const program = appState.program ? appState.program.payload.value : null

0 commit comments

Comments
 (0)