Fixing routing and api for media
This commit is contained in:
parent
2dd56ed8c5
commit
9628899d26
|
@ -188,12 +188,12 @@ def es_search_text(body):
|
|||
|
||||
''' Get all chapters '''
|
||||
@api.route('/chapters/')
|
||||
def get_chapters():
|
||||
def get_chapter_list():
|
||||
return jsonify(es_document_list('chapters'))
|
||||
|
||||
''' Get specific chapter '''
|
||||
@api.route('/chapters/<string:id>')
|
||||
def get_chapter(id):
|
||||
def get_chapter_doc(id):
|
||||
data = es_get_document('chapters', id)
|
||||
return jsonify(data)
|
||||
|
||||
|
@ -222,28 +222,28 @@ def delete_chapter(id):
|
|||
|
||||
''' Get all notes '''
|
||||
@api.route('/notes/')
|
||||
def get_notes():
|
||||
def get_note_list():
|
||||
return jsonify(es_document_list('notes'))
|
||||
|
||||
''' Get specific chapter '''
|
||||
''' Get specific note '''
|
||||
@api.route('/notes/<string:id>')
|
||||
def get_note(id):
|
||||
def get_note_doc(id):
|
||||
data = es_get_document('notes', id)
|
||||
return jsonify(data)
|
||||
|
||||
''' New chapter '''
|
||||
''' New note '''
|
||||
@api.route('/notes/', methods=['PUT'])
|
||||
def create_note():
|
||||
es_create_document('notes', request.data)
|
||||
return jsonify(es_document_list('notes'))
|
||||
|
||||
''' Write chapter '''
|
||||
''' Write note '''
|
||||
@api.route('/notes/<string:id>', methods=['POST'])
|
||||
def write_note(id):
|
||||
es_index_document('notes', id, request.data)
|
||||
return jsonify(es_document_list('notes'))
|
||||
|
||||
''' Delete chapter '''
|
||||
''' Delete note '''
|
||||
@api.route('/notes/<string:id>', methods=['DELETE'])
|
||||
def delete_note(id):
|
||||
es_delete_document('notes', id)
|
||||
|
@ -255,33 +255,66 @@ def delete_note(id):
|
|||
|
||||
''' Get all tags '''
|
||||
@api.route('/tags/')
|
||||
def get_tags():
|
||||
def get_tag_list():
|
||||
return jsonify(es_document_list('tags'))
|
||||
|
||||
''' Get specific chapter '''
|
||||
''' Get specific tag '''
|
||||
@api.route('/tags/<string:id>')
|
||||
def get_tag(id):
|
||||
def get_tag_doc(id):
|
||||
data = es_get_document('tags', id)
|
||||
return jsonify(data)
|
||||
|
||||
''' New chapter '''
|
||||
''' New tag '''
|
||||
@api.route('/tags/', methods=['PUT'])
|
||||
def create_tag():
|
||||
es_create_document('tags', request.data)
|
||||
return jsonify(es_document_list('tags'))
|
||||
|
||||
''' Write chapter '''
|
||||
''' Write tag '''
|
||||
@api.route('/tags/<string:id>', methods=['POST'])
|
||||
def write_tag(id):
|
||||
es_index_document('tags', id, request.data)
|
||||
return jsonify(es_document_list('tags'))
|
||||
|
||||
''' Delete chapter '''
|
||||
''' Delete tag '''
|
||||
@api.route('/tags/<string:id>', methods=['DELETE'])
|
||||
def delete_tag(id):
|
||||
es_delete_document('tags', id)
|
||||
return jsonify(es_document_list('tags'))
|
||||
|
||||
#
|
||||
# Media API Routes
|
||||
#
|
||||
|
||||
''' Get all media '''
|
||||
@api.route('/media/')
|
||||
def get_media_list():
|
||||
return jsonify(es_document_list('media'))
|
||||
|
||||
''' Get specific media '''
|
||||
@api.route('/media/<string:id>')
|
||||
def get_media_doc(id):
|
||||
data = es_get_document('media', id)
|
||||
return jsonify(data)
|
||||
|
||||
''' New media '''
|
||||
@api.route('/media/', methods=['PUT'])
|
||||
def create_media():
|
||||
es_create_document('media', request.data)
|
||||
return jsonify(es_document_list('media'))
|
||||
|
||||
''' Write media '''
|
||||
@api.route('/media/<string:id>', methods=['POST'])
|
||||
def write_media(id):
|
||||
es_index_document('media', id, request.data)
|
||||
return jsonify(es_document_list('media'))
|
||||
|
||||
''' Delete media '''
|
||||
@api.route('/media/<string:id>', methods=['DELETE'])
|
||||
def delete_media(id):
|
||||
es_delete_document('media', id)
|
||||
return jsonify(es_document_list('media'))
|
||||
|
||||
#
|
||||
# Search API Routes
|
||||
#
|
||||
|
|
|
@ -44,6 +44,13 @@ export const TagButton = ({tag, currentTag, onClick}) =>
|
|||
</button>
|
||||
</div>
|
||||
|
||||
export const MediaButton = ({media, currentMedia, onClick}) =>
|
||||
<div className ='media_button'>
|
||||
<button onClick={onClick} className={currentMedia.id === media.id ? 'btn btn-info' : 'btn btn-outline-info inactive_button'}>
|
||||
{media.title}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
export const HighlightButton = ({toggle, onClick, size='lg'}) =>
|
||||
<div>
|
||||
<div id='highlight_button' className='text-center'>
|
||||
|
|
|
@ -20,7 +20,7 @@ export const EditorEditModeRichTextOptions = ({editorState, onToolButtonClick, d
|
|||
<EditorToolButton glyph='bold' onClick={()=>onToolButtonClick(editorState, 'BOLD')}/>
|
||||
<EditorToolButton glyph='italic' onClick={()=>onToolButtonClick(editorState, 'ITALIC')}/>
|
||||
<EditorToolButton glyph='underline' onClick={()=>onToolButtonClick(editorState, 'UNDERLINE')}/>
|
||||
<EditorToolButton glyph='header' onClick={()=>onToolButtonClick(editorState, 'header-two')}/>
|
||||
<EditorToolButton glyph='heading' onClick={()=>onToolButtonClick(editorState, 'header-two')}/>
|
||||
</div>
|
||||
</div>
|
||||
<div className='col-5 offset-2'>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
|
||||
import { ChapterButton, NoteButton, TagButton } from './button'
|
||||
import { ChapterButton, NoteButton, TagButton, MediaButton } from './button'
|
||||
|
||||
export const DocumentList = ({docs, currentDocument, onDocumentClick, docType}) =>
|
||||
<div id='document_list'>
|
||||
|
@ -13,6 +13,9 @@ export const DocumentList = ({docs, currentDocument, onDocumentClick, docType})
|
|||
}
|
||||
{(docType === 'tags' && docs.length > 0) &&
|
||||
<TagList tags={docs} currentTag={currentDocument} onTagClick={onDocumentClick}/>
|
||||
}
|
||||
{(docType === 'media' && docs.length > 0) &&
|
||||
<MediaList media={docs} currentMedia={currentDocument} onMediaClick={onDocumentClick}/>
|
||||
}
|
||||
</div>
|
||||
|
||||
|
@ -37,6 +40,13 @@ export const TagList = ({tags, currentTag, onTagClick}) =>
|
|||
)}
|
||||
</div>
|
||||
|
||||
export const MediaList = ({media, currentMedia, onMediaClick}) =>
|
||||
<div>
|
||||
{media.map(media =>
|
||||
<MediaButton key={media.id} currentMedia={currentMedia} media={media} onClick={()=>onMediaClick(media.id, 'media')} />
|
||||
)}
|
||||
</div>
|
||||
|
||||
DocumentList.propTypes = {
|
||||
notes: PropTypes.arrayOf(PropTypes.object),
|
||||
chapters: PropTypes.arrayOf(PropTypes.object),
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { connect } from 'react-redux'
|
||||
import { push } from 'react-router-redux'
|
||||
import actions from '../actions'
|
||||
import { DocumentList } from '../components/list'
|
||||
import { NewDocumentButton } from '../components/button'
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { connect } from 'react-redux'
|
||||
import { push } from 'react-router-redux'
|
||||
import actions from '../actions'
|
||||
import { DocumentList } from '../components/list'
|
||||
import { HighlightButton } from '../components/button'
|
||||
|
|
13
src/joyce.js
13
src/joyce.js
|
@ -4,7 +4,7 @@ import ReactDOM from 'react-dom'
|
|||
import { createStore, applyMiddleware } from 'redux'
|
||||
import { Provider } from 'react-redux'
|
||||
import { Route, Redirect, Switch } from 'react-router'
|
||||
import { ConnectedRouter, routerReducer, routerMiddleware, push } from 'react-router-redux'
|
||||
import { ConnectedRouter, routerReducer, routerMiddleware } from 'react-router-redux'
|
||||
import createHistory from 'history/createBrowserHistory'
|
||||
import 'bootstrap'
|
||||
|
||||
|
@ -27,6 +27,7 @@ const state = store.getState()
|
|||
store.dispatch(actions.getDocumentList({docType: 'chapters'}))
|
||||
store.dispatch(actions.getDocumentList({docType: 'notes'}))
|
||||
store.dispatch(actions.getDocumentList({docType: 'tags'}))
|
||||
store.dispatch(actions.getDocumentList({docType: 'media'}))
|
||||
|
||||
ReactDOM.render(
|
||||
<Provider store={store}>
|
||||
|
@ -38,6 +39,9 @@ ReactDOM.render(
|
|||
<Route exact path='/' render={() =>
|
||||
<Redirect to={'/:id'}/>
|
||||
}/>
|
||||
<Route exact path='/notes' render={() =>
|
||||
<Redirect to={'/notes/:id'}/>
|
||||
}/>
|
||||
<Route exact path='/edit' render={() =>
|
||||
<Redirect to={'/edit/:id'}/>
|
||||
}/>
|
||||
|
@ -46,14 +50,15 @@ ReactDOM.render(
|
|||
}/>
|
||||
<Route exact path='/edit/tags' render={() =>
|
||||
<Redirect to={'/edit/tags/:id'}/>
|
||||
}/>
|
||||
<Route exact path='/notes' render={() =>
|
||||
<Redirect to={'/notes/:id'}/>
|
||||
}/>
|
||||
<Route exact path='/edit/media' render={() =>
|
||||
<Redirect to={'/edit/media/:id'}/>
|
||||
}/>
|
||||
<Route exact path='/notes/:id' component={ReaderPageContainer} />
|
||||
<Route exact path='/edit/:id' component={EditorPageContainer} />
|
||||
<Route exact path='/edit/notes/:id' component={EditorPageContainer} />
|
||||
<Route exact path='/edit/tags/:id' component={EditorPageContainer} />
|
||||
<Route exact path='/edit/media/:id' component={EditorPageContainer} />
|
||||
<Route exact path='/search/' component={SearchPageContainer} />
|
||||
<Route exact path='/:id' component={ReaderPageContainer} />
|
||||
</Switch>
|
||||
|
|
|
@ -28,7 +28,7 @@ const joyceInterface = store => next => action => {
|
|||
search_text: convertToSearchText(textContent)
|
||||
}
|
||||
if (action.docType === 'tags') {
|
||||
data.color = action.inputs.color
|
||||
data.color = action.inputs.colorPicker
|
||||
}
|
||||
if (action.currentDocument.id) {
|
||||
data.id = action.currentDocument.id
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { go, push } from 'react-router-redux'
|
||||
import { push } from 'react-router-redux'
|
||||
|
||||
import actions from '../actions'
|
||||
import helpers from '../modules/helpers'
|
||||
|
@ -35,9 +35,11 @@ const joyceRouter = store => next => action => {
|
|||
if (currentDocument.hasOwnProperty('id')) {
|
||||
store.dispatch(push(docType === 'chapters' ? String(currentDocument.number) : currentDocument.id))
|
||||
}
|
||||
// And path is /:id and chapters are loaded, set currentDocument to first chapter
|
||||
// And path is /:id or /edit/:id and chapters are loaded, set currentDocument to first chapter
|
||||
else if (regex.checkIfRootPath(path) && chapters.length > 0) {
|
||||
console.log('THIS IS HAPPENING')
|
||||
store.dispatch(actions.setCurrentDocument(chapters[0].id, 'chapters'))
|
||||
}
|
||||
else if (regex.checkEditRoute(path) && !checkIfDocTypePath(path) && chapters.length > 0 ) {
|
||||
store.dispatch(actions.setCurrentDocument(chapters[0].id, 'chapters'))
|
||||
}
|
||||
// And path has a docType and docs are loaded, set currentDocument to first doc of that type
|
||||
|
|
|
@ -32,12 +32,20 @@ const inputs = (state=initialState, action) => {
|
|||
}
|
||||
// Color Picker
|
||||
case 'GET_DOCUMENT_TEXT':
|
||||
if (action.status === 'success' && action.state === 'currentDocument' && action.docType === 'tags') {
|
||||
if (action.status === 'success' && action.docType === 'tags') {
|
||||
console.log('SOMETHING!')
|
||||
return {
|
||||
...state,
|
||||
colorPicker: action.data.color
|
||||
}
|
||||
} else { return state }
|
||||
case 'SAVE_DOCUMENT':
|
||||
if (action.status === 'success' && action.docType === 'tags') {
|
||||
return {
|
||||
...state,
|
||||
colorPicker: ''
|
||||
}
|
||||
} else { return state }
|
||||
case 'CREATE_DOCUMENT':
|
||||
return {
|
||||
...state,
|
||||
|
|
Loading…
Reference in New Issue