+
+ ,
+ document.getElementById('wrapper')
+)
+
+store.dispatch(getDocumentList({
+ docType: docType,
+ state: 'initialPageLoad'
+}))
+store.dispatch(getDocumentList({docType: 'notes'}))
\ No newline at end of file
diff --git a/src/middleware/joyceAPI.js b/src/middleware/joyceAPI.js
index 2685b6a..1c1ebf3 100644
--- a/src/middleware/joyceAPI.js
+++ b/src/middleware/joyceAPI.js
@@ -58,10 +58,17 @@ const selectChapterIDByNumber = (store, number) => {
}
const parseNumberFromPath = path => {
- const match = /^\/([0-9]*)/.exec(path)
- const number = Number(match[1])
- console.log('Hey!', number)
- return number
+ const match = /\/([0-9]*)$/.exec(path)
+ if (match) {
+ if (parseInt(match[1])) {
+ const number = Number(match[1])
+ return number
+ } else {
+ return null
+ }
+ } else {
+ return null
+ }
}
// API Middleware
@@ -75,12 +82,14 @@ export const joyceAPI = store => next => action => {
store.dispatch(getDocumentList(response))
)
}
- if (action.status === 'success' && action.state === 'initialPageLoad') {
- HTTPGetDocumentList(action.docType, action.state).then(response => {
- const pathName = store.getState().routerReducer.location.pathname
- store.dispatch(setCurrentDocument(selectChapterIDByNumber(store, parseNumberFromPath(pathName)), action.docType))
- })
- }
+ if (action.status === 'success' && action.docType === store.getState().docType && !store.getState().currentDocument.id) {
+ if (action.docType === 'chapters') {
+ const pathNumber = parseNumberFromPath(store.getState().routerReducer.location.pathname)
+ store.dispatch(setCurrentDocument(selectChapterIDByNumber(store, pathNumber), action.docType))
+ } else if (action.docType === 'notes') {
+ store.dispatch(setCurrentDocument(store.getState().notes[0].id, action.docType))
+ }
+ }
break
case 'GET_DOCUMENT_TEXT':
if (action.status === 'request') {
@@ -167,9 +176,10 @@ export const joyceAPI = store => next => action => {
}
break
case '@@router/LOCATION_CHANGE':
- if (/^\/[0-9]*/.test(action.payload.pathname)) {
+ const pathNumber = parseNumberFromPath(action.payload.pathname)
+ if (pathNumber) {
for (const chapter of store.getState().chapters) {
- if (action.payload.pathname === '/' + chapter.number) {
+ if (pathNumber === chapter.number) {
store.dispatch(setCurrentDocument(chapter.id, 'chapters'))
}
}
diff --git a/src/notes.js b/src/notes.js
deleted file mode 100644
index 72f39e6..0000000
--- a/src/notes.js
+++ /dev/null
@@ -1,39 +0,0 @@
-import React from 'react'
-import ReactDOM from 'react-dom'
-import { createStore, applyMiddleware } from 'redux'
-import { Provider } from 'react-redux'
-import 'bootstrap'
-
-import reduceReader from './reducers/reduceReader'
-import { getDocumentList } from './actions/apiActions'
-import { setCurrentDocument, setDocType } from './actions/userActions'
-import { logger, joyceAPI } from './middleware/'
-import { getFirstDocument } from './mixins/firstDocument'
-import JoyceReaderPageContainer from './containers/joyceReaderPageContainer'
-
-// TODO: Pass routing from Flask?
-
-let docType = 'notes'
-let store = createStore(reduceReader, applyMiddleware(logger, joyceAPI))
-store.dispatch(setDocType(docType))
-
-ReactDOM.render(
-
-
- ,
- document.getElementById('wrapper')
-)
-
-store.dispatch(getDocumentList({docType: docType}))
-
-// Hacky way to fetch first chapter after async call above has completed.
-// TODO: Add number lookup to API?
-setTimeout(
- () => {
- const firstDocument = getFirstDocument(store, docType)
- if (firstDocument) {
- store.dispatch(setCurrentDocument(firstDocument.id, docType))
- }
- },
- 1000
-)
\ No newline at end of file
diff --git a/src/reader.js b/src/reader.js
deleted file mode 100644
index 163ba4c..0000000
--- a/src/reader.js
+++ /dev/null
@@ -1,42 +0,0 @@
-// node_modules
-import React from 'react'
-import ReactDOM from 'react-dom'
-import { createStore, applyMiddleware } from 'redux'
-import { Provider } from 'react-redux'
-import { ConnectedRouter, routerReducer, routerMiddleware, push } from 'react-router-redux'
-import createHistory from 'history/createBrowserHistory'
-// import 'bootstrap'
-
-// src packages
-import reduceReader from './reducers/reduceReader'
-import { getDocumentList } from './actions/apiActions'
-import { setCurrentDocument, setDocType } from './actions/userActions'
-import { logger, joyceAPI } from './middleware/'
-import { getFirstDocument } from './mixins/firstDocument'
-import JoyceReaderPageContainer from './containers/joyceReaderPageContainer'
-import JoyceEditorPageContainer from './containers/joyceEditorPageContainer'
-
-// TODO: Pass routing from Flask?
-
-const history = createHistory()
-const router = routerMiddleware(history)
-
-const docType = 'chapters'
-const store = createStore(reduceReader, applyMiddleware(logger, joyceAPI, router))
-store.dispatch(setDocType(docType))
-
-ReactDOM.render(
-
-
-
-
-
-
- ,
- document.getElementById('wrapper')
-)
-
-store.dispatch(getDocumentList({
- docType: docType,
- state: 'initialPageLoad'
-}))
\ No newline at end of file
diff --git a/src/reducers/docType.js b/src/reducers/docType.js
index fe8f742..d67cb59 100644
--- a/src/reducers/docType.js
+++ b/src/reducers/docType.js
@@ -2,6 +2,11 @@ const docType = (state=null, action) => {
switch(action.type) {
case 'SET_DOC_TYPE':
return action.docType
+ case '@@router/LOCATION_CHANGE':
+ const path = action.payload.pathname
+ if (/^\/(notes).*/.exec(path)) {
+ return 'notes'
+ } else { return state }
default:
return state
}
diff --git a/src/reducers/reduceEditor.js b/src/reducers/reduceEditor.js
deleted file mode 100644
index 719772f..0000000
--- a/src/reducers/reduceEditor.js
+++ /dev/null
@@ -1,27 +0,0 @@
-import { combineReducers } from 'redux'
-
-import notes from './notes'
-import chapters from './chapters'
-import currentDocument from './currentDocument'
-import docType from './docType'
-import mode from './mode'
-import documentTitleInput from './documentTitleInput'
-import editorState from './editorState'
-import selectionState from './selectionState'
-import annotationNote from './annotationNote'
-import loadingToggle from './loadingToggle'
-
-const reduceDocuments = combineReducers({
- notes,
- chapters,
- currentDocument,
- annotationNote,
- mode,
- documentTitleInput,
- editorState,
- docType,
- selectionState,
- loadingToggle
-})
-
-export default reduceDocuments
\ No newline at end of file
diff --git a/src/reducers/reduceReader.js b/src/reducers/reduceReader.js
index 95baaeb..df6b295 100644
--- a/src/reducers/reduceReader.js
+++ b/src/reducers/reduceReader.js
@@ -9,7 +9,8 @@ import highlightToggle from './highlightToggle'
import loadingToggle from './loadingToggle'
import docType from './docType'
import { routerReducer } from 'react-router-redux'
-
+import mode from './mode'
+import documentTitleInput from './documentTitleInput'
const reduceReader = combineReducers({
chapters,
@@ -20,7 +21,9 @@ const reduceReader = combineReducers({
currentDocument,
highlightToggle,
loadingToggle,
- routerReducer
+ routerReducer,
+ mode,
+ documentTitleInput
})
export default reduceReader
\ No newline at end of file
diff --git a/src/stylesheets/editor.scss b/src/stylesheets/joyce.scss
similarity index 100%
rename from src/stylesheets/editor.scss
rename to src/stylesheets/joyce.scss
diff --git a/src/stylesheets/reader.scss b/src/stylesheets/reader.scss
deleted file mode 100644
index 1d6660b..0000000
--- a/src/stylesheets/reader.scss
+++ /dev/null
@@ -1,22 +0,0 @@
-@import "variables";
-@import "window";
-@import "navbar";
-@import "sidebar";
-@import "page";
-@import "node_modules/bootstrap/scss/bootstrap";
-
-$fa-font-path: "../../node_modules/font-awesome/fonts";
-@import "node_modules/font-awesome/scss/font-awesome";
-
-#joyce_reader {
- overflow: hidden;
- width: 95%;
- height: 100%;
- background-color: rgba(256,256,256,0.5);
- border-left: 1px solid $border_color;
- border-right: 1px solid $border_color;
-}
-
-#joyce_reader > div {
- margin-top: 0.5em;
-}
diff --git a/templates/editor.html b/templates/editor.html
deleted file mode 100644
index e990676..0000000
--- a/templates/editor.html
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
- Joyce - Editor
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/templates/reader.html b/templates/joyce.html
similarity index 86%
rename from templates/reader.html
rename to templates/joyce.html
index b6a3ec2..e902d82 100644
--- a/templates/reader.html
+++ b/templates/joyce.html
@@ -11,5 +11,5 @@
-
+
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/templates/notes.html b/templates/notes.html
deleted file mode 100644
index 39cb3e4..0000000
--- a/templates/notes.html
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-
Joyce - Notes
-
-
-
-
-
-
\ No newline at end of file
diff --git a/templates/search.html b/templates/search.html
deleted file mode 100644
index 55aad5e..0000000
--- a/templates/search.html
+++ /dev/null
@@ -1,14 +0,0 @@
-
-