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

Commit 0dd5363

Browse files
author
haad
committed
Support db replication, add separate feed input controls
1 parent 18f5f58 commit 0dd5363

File tree

8 files changed

+95
-11
lines changed

8 files changed

+95
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
> UI for managing [OrbitDB](https://github.com/orbitdb/orbit-db) databases.
44
5-
**Run the [Control Center](https://ipfs.io/ipfs/Qme9bwgUYgdLTA9ZpZnHqNHRXGfJ5QHw4BCzgrFQMB59T8) in your browser.**
5+
**Run the [Control Center](https://ipfs.io/ipfs/QmPoqRhSX2rMy6NR7Y3pnkC2z1kK9TH9fZa6wyfXLEptw9) in your browser.**
66

77
<img width="80%" src="https://raw.githubusercontent.com/haadcode/orbit-db-control-center/master/screenshot1.png"/>
88

src/components/CounterStoreControls.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function KeyValueStoreControls () {
4444
<Pane
4545
flex='1'
4646
>
47-
<Heading marginBottom={majorScale(1)}>Increment the value of the counter database</Heading>
47+
<Heading marginBottom={majorScale(1)}>Increment the value of the counter</Heading>
4848
<TextInput
4949
onChange={handleValueChange}
5050
name='value'

src/components/FeedStoreControls.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import React from 'react'
2+
import {
3+
majorScale,
4+
Button,
5+
Heading,
6+
Pane,
7+
TextInput
8+
} from 'evergreen-ui'
9+
10+
import { useStateValue, actions } from '../state'
11+
12+
function FeedStoreControls () {
13+
const [appState, dispatch] = useStateValue()
14+
const [value, setValue] = React.useState('')
15+
16+
function handleValueChange (event) {
17+
setValue(event.target.value)
18+
}
19+
20+
function handleAdd (event) {
21+
if (event) event.preventDefault()
22+
if (value.length === 0) return
23+
addToDB()
24+
}
25+
26+
const addToDB = async () => {
27+
const db = appState.db
28+
29+
if (db.type !== 'feed') {
30+
throw new Error('This component can only handle Feed databases')
31+
}
32+
33+
await db.add(value)
34+
35+
const entries = await db.iterator({ limit: 10 }).collect().reverse()
36+
dispatch({ type: actions.DB.SET_DB, db, entries })
37+
}
38+
39+
return (
40+
<Pane
41+
flex='1'
42+
>
43+
<Heading marginBottom={majorScale(1)}>Add an entry to the feed</Heading>
44+
<TextInput
45+
onChange={handleValueChange}
46+
name='value'
47+
placeholder='Data'
48+
height={24}
49+
width='30%'
50+
></TextInput>
51+
<Button
52+
iconBefore='plus'
53+
appearance='default'
54+
height={24}
55+
marginLeft={majorScale(1)}
56+
onClick={handleAdd}
57+
>
58+
Add
59+
</Button>
60+
</Pane>
61+
)
62+
}
63+
64+
export default FeedStoreControls

src/components/KeyValueStoreControls.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function KeyValueStoreControls () {
4646
<Pane
4747
flex='1'
4848
>
49-
<Heading marginBottom={majorScale(1)}>Set a value for a key in the database</Heading>
49+
<Heading marginBottom={majorScale(1)}>Set a value for a key</Heading>
5050
<TextInput
5151
onChange={handleKeyChange}
5252
name='key'

src/components/LogStoreControls.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99

1010
import { useStateValue, actions } from '../state'
1111

12-
function EventLogControls () {
12+
function LogStoreControls () {
1313
const [appState, dispatch] = useStateValue()
1414
const [value, setValue] = React.useState('')
1515

@@ -26,8 +26,8 @@ function EventLogControls () {
2626
const addToDB = async () => {
2727
const db = appState.db
2828

29-
if (db.type !== 'eventlog' && db.type !== 'feed') {
30-
throw new Error('This component can only handle Log and Feed databases')
29+
if (db.type !== 'eventlog') {
30+
throw new Error('This component can only handle Log databases')
3131
}
3232

3333
await db.add(value)
@@ -40,7 +40,7 @@ function EventLogControls () {
4040
<Pane
4141
flex='1'
4242
>
43-
<Heading marginBottom={majorScale(1)}>Add an event to the log database</Heading>
43+
<Heading marginBottom={majorScale(1)}>Add an event to the log</Heading>
4444
<TextInput
4545
onChange={handleValueChange}
4646
name='value'
@@ -61,4 +61,4 @@ function EventLogControls () {
6161
)
6262
}
6363

64-
export default EventLogControls
64+
export default LogStoreControls

src/config/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const config = {
2+
ipfs: {
3+
preload: {
4+
enabled: false
5+
},
6+
config: {
7+
Addresses: {
8+
Swarm: ['/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star']
9+
}
10+
}
11+
}
12+
}
13+
14+
export default config

src/database/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import IPFS from 'ipfs'
22
import OrbitDB from 'orbit-db'
3+
import Config from '../config'
34

45
// OrbitDB instance
56
let orbitdb
@@ -9,7 +10,7 @@ let programs
910

1011
// Start IPFS
1112
export const initIPFS = async () => {
12-
return await IPFS.create()
13+
return await IPFS.create(Config.ipfs)
1314
}
1415

1516
// Start OrbitDB

src/views/Database.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from 'evergreen-ui'
1212

1313
import LogStoreControls from '../components/LogStoreControls'
14+
import FeedStoreControls from '../components/FeedStoreControls'
1415
import KeyValueStoreControls from '../components/KeyValueStoreControls'
1516
import DocumentStoreControls from '../components/DocumentStoreControls'
1617
import CounterStoreControls from '../components/CounterStoreControls'
@@ -80,7 +81,9 @@ function ProgramView () {
8081
const db = appState.program ? appState.program.payload.value : null
8182
if (!db) return
8283

83-
if (db.type === 'eventlog' || db.type === 'feed')
84+
if (db.type === 'eventlog')
85+
return "Latest 10 events"
86+
else if (db.type === 'feed')
8487
return "Latest 10 entries"
8588
else if (db.type === 'docstore')
8689
return "All Documents"
@@ -162,8 +165,10 @@ function ProgramView () {
162165
const db = appState.db
163166
if (!db) return
164167

165-
if (db.type === 'eventlog' || db.type === 'feed')
168+
if (db.type === 'eventlog')
166169
return <LogStoreControls />
170+
else if (db.type === 'feed')
171+
return <FeedStoreControls />
167172
else if (db.type === 'docstore')
168173
return <DocumentStoreControls />
169174
else if (db.type === 'keyvalue')

0 commit comments

Comments
 (0)