mirror of
https://github.com/fazo96/ipfs-boards
synced 2025-01-09 12:19:49 +01:00
can now kinda create a board
This commit is contained in:
parent
27cde7efe5
commit
29a876c193
@ -3,6 +3,8 @@
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"ipfs": "^0.27.7",
|
||||
"orbit-db": "^0.19.4",
|
||||
"react": "^16.2.0",
|
||||
"react-dom": "^16.2.0",
|
||||
"react-hot-loader": "^3.1.3",
|
||||
|
@ -1,3 +1,5 @@
|
||||
|
||||
export const ADD_POST = 'ADD_POST'
|
||||
export const CREATE_BOARD = 'CREATE_BOARD'
|
||||
export const CREATING_BOARD = 'CREATING_BOARD'
|
||||
export const CREATED_BOARD = 'CREATED_BOARD'
|
@ -1,4 +1,8 @@
|
||||
import { CREATE_BOARD } from './actionTypes'
|
||||
import {
|
||||
CREATE_BOARD,
|
||||
CREATING_BOARD,
|
||||
CREATED_BOARD
|
||||
} from './actionTypes'
|
||||
|
||||
export function createBoard(board) {
|
||||
return {
|
||||
@ -6,3 +10,17 @@ export function createBoard(board) {
|
||||
board
|
||||
}
|
||||
}
|
||||
|
||||
export function creatingBoard(board) {
|
||||
return {
|
||||
type: CREATING_BOARD,
|
||||
board
|
||||
}
|
||||
}
|
||||
|
||||
export function createdBoard(board) {
|
||||
return {
|
||||
type: CREATED_BOARD,
|
||||
board
|
||||
}
|
||||
}
|
@ -15,7 +15,7 @@ export default class BoardForm extends Component {
|
||||
|
||||
render() {
|
||||
const { title, content } = this.state
|
||||
const { onSave } = this.props
|
||||
const { onSave, creating } = this.props
|
||||
return <Form>
|
||||
<Form.Field>
|
||||
<label>Title</label>
|
||||
@ -28,7 +28,9 @@ export default class BoardForm extends Component {
|
||||
<Button
|
||||
type='submit'
|
||||
onClick={() => onSave({ title, content })}
|
||||
disabled={creating}
|
||||
>Create</Button>
|
||||
{creating ? 'Creating the board...' : ''}
|
||||
</Form>
|
||||
}
|
||||
}
|
@ -1,12 +1,12 @@
|
||||
import React from 'react'
|
||||
import { List } from 'semantic-ui-react'
|
||||
|
||||
export default function BoardsItem(props) {
|
||||
export default function BoardsItem({ title }) {
|
||||
return <List.Item>
|
||||
<List.Icon name='board' size='large' verticalAlign='middle' />
|
||||
<List.Icon name='comments' size='large' verticalAlign='middle' />
|
||||
<List.Content>
|
||||
<List.Header>Board Name</List.Header>
|
||||
<List.Description>Updated 10 mins ago</List.Description>
|
||||
<List.Header>{title}</List.Header>
|
||||
<List.Description>Experimental</List.Description>
|
||||
</List.Content>
|
||||
</List.Item>
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
|
||||
class BoardIndex {
|
||||
constructor(id) {
|
||||
super(id);
|
||||
// this._index = []
|
||||
}
|
||||
|
||||
get() {
|
||||
throw new Error('Not implemented yet')
|
||||
}
|
||||
|
||||
updateIndex(oplog, entries) {
|
||||
throw new Error('Not implemented yet')
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
const Store = require('orbit-db-store')
|
||||
const BoardIndex = require('./BoardIndex')
|
||||
|
||||
class Board extends Store {
|
||||
constructor(ipfs, id, dbname, options) {
|
||||
if (!options) options = {}
|
||||
if (!options.indexBy) Object.assign(options, { indexBy: '_id' })
|
||||
if (!options.Index) Object.assign(options, { Index: BoardIndex })
|
||||
super(ipfs, id, dbname, options)
|
||||
this._type = 'board'
|
||||
}
|
||||
|
||||
get type() {
|
||||
return 'discussion-board'
|
||||
}
|
||||
|
||||
updateMetadata() {
|
||||
throw new Error('Not implemented yet')
|
||||
}
|
||||
|
||||
getPosts() {
|
||||
throw new Error('Not implemented yet')
|
||||
}
|
||||
|
||||
addPost(title, content) {
|
||||
this._addOperation({
|
||||
title,
|
||||
content
|
||||
})
|
||||
}
|
||||
|
||||
updatePost() {
|
||||
throw new Error('Not implemented yet')
|
||||
}
|
||||
|
||||
addComment() {
|
||||
throw new Error('Not implemented yet')
|
||||
}
|
||||
|
||||
updateComment() {
|
||||
throw new Error('Not implemented yet')
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Board
|
@ -1,17 +1,46 @@
|
||||
import BoardStore from './BoardStore'
|
||||
import BoardStore from 'orbit-db-discussion-board'
|
||||
|
||||
export async function open(address, options = {}) {
|
||||
export async function open(address, metadata, options = {}) {
|
||||
if (!window.ipfs) {
|
||||
window.ipfs = await import('ipfs')
|
||||
const IPFS = await import('ipfs')
|
||||
window.ipfs = new IPFS({
|
||||
repo: 'ipfs-v6-boards-v0',
|
||||
EXPERIMENTAL: {
|
||||
pubsub: true
|
||||
},
|
||||
config: {
|
||||
Addresses: {
|
||||
Swarm: [
|
||||
'/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star',
|
||||
'/dns4/ws-star-signal-1.servep2p.com/tcp/443/wss/p2p-websocket-star',
|
||||
'/dns4/ws-star-signal-2.servep2p.com/tcp/443/wss/p2p-websocket-star'
|
||||
]
|
||||
}
|
||||
}
|
||||
});
|
||||
await new Promise(fullfill => {
|
||||
window.ipfs.on('ready', () => fullfill())
|
||||
})
|
||||
}
|
||||
if (!window.orbitDb) {
|
||||
const OrbitDB = await import('orbit-db')
|
||||
OrbitDB.addDatabaseType(BoardStore.type, BoardStore)
|
||||
window.orbitDb = new OrbitDB(window.ipfs)
|
||||
window.orbitDb.addDatabaseType(BoardStore.type, BoardStore)
|
||||
}
|
||||
const defaultOptions = {
|
||||
create: true,
|
||||
create: address === undefined,
|
||||
type: BoardStore.type
|
||||
}
|
||||
return await window.orbitDb.open(address, Object.assign(defaultOptions, options))
|
||||
if (!address) {
|
||||
address = 'board-v0'
|
||||
} else if (!address.indexOf('/orbitdb/') < 0 || address.indexOf('/board-v0') < 0) {
|
||||
throw new Error('invalid address')
|
||||
}
|
||||
const db = await window.orbitDb.open(address, Object.assign(defaultOptions, options))
|
||||
if (metadata) {
|
||||
await db.updateMetadata(metadata)
|
||||
}
|
||||
if (!window.dbs) window.dbs = {}
|
||||
window.dbs[db.address.toString()] = db
|
||||
return db
|
||||
}
|
||||
|
@ -1,17 +1,26 @@
|
||||
import { CREATE_BOARD } from '../actions/actionTypes'
|
||||
import {
|
||||
CREATE_BOARD,
|
||||
CREATING_BOARD,
|
||||
CREATED_BOARD
|
||||
} from '../actions/actionTypes'
|
||||
|
||||
function getInitialState() {
|
||||
return {
|
||||
board: {
|
||||
title: ''
|
||||
}
|
||||
},
|
||||
creating: false
|
||||
}
|
||||
}
|
||||
|
||||
export default function BoardEditorReducer(state = getInitialState(), action) {
|
||||
switch (action.type) {
|
||||
case CREATE_BOARD:
|
||||
return Object.assign({}, state, { board: action.board })
|
||||
return Object.assign({}, state, { board: action.board, creating: false })
|
||||
case CREATING_BOARD:
|
||||
return Object.assign({}, state, { creating: true })
|
||||
case CREATED_BOARD:
|
||||
return Object.assign({}, state, { creating: false })
|
||||
default:
|
||||
return state
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { CREATED_BOARD } from '../actions/actionTypes'
|
||||
|
||||
function getInitialState() {
|
||||
return {
|
||||
@ -7,6 +8,8 @@ function getInitialState() {
|
||||
|
||||
export default function BoardsReducer(state = getInitialState(), action) {
|
||||
switch (action.type) {
|
||||
case CREATED_BOARD:
|
||||
return Object.assign({}, state, { boards: state.boards.concat(action.board) })
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
@ -1,4 +1,13 @@
|
||||
import { put, call } from 'redux-saga/effects'
|
||||
import { open } from '../orbitdb'
|
||||
import { creatingBoard, createdBoard } from '../actions/board'
|
||||
|
||||
export default function* boards() {
|
||||
|
||||
export function* createBoard({ board }) {
|
||||
yield put(creatingBoard(board))
|
||||
const db = yield call(open, board.address)
|
||||
const dbInfo = {
|
||||
address: db.address.toString()
|
||||
}
|
||||
// TODO watch db status
|
||||
yield put(createdBoard(Object.assign({}, board, dbInfo)))
|
||||
}
|
@ -1,4 +1,7 @@
|
||||
import { takeEvery } from 'redux-saga/effects'
|
||||
import { CREATE_BOARD } from '../actions/actionTypes'
|
||||
import { createBoard } from './boards'
|
||||
|
||||
export default function* saga(){
|
||||
|
||||
yield takeEvery(CREATE_BOARD, createBoard)
|
||||
}
|
Loading…
Reference in New Issue
Block a user