From 2474c26b612f8964e8df80a20821b836a4fc3d1f Mon Sep 17 00:00:00 2001 From: Joey Payne Date: Tue, 15 Mar 2016 07:58:08 -0600 Subject: [PATCH] Move menu items and state to navigation reducer All the state is now initialized in one place for the menu items instead of in both LibraryNav and the navigation reducer. Simplifies life and code. --- app/reducers/navigation.jsx | 120 ++++++++++++++++++++++++++++++++---- 1 file changed, 109 insertions(+), 11 deletions(-) diff --git a/app/reducers/navigation.jsx b/app/reducers/navigation.jsx index 704f42c..198b435 100644 --- a/app/reducers/navigation.jsx +++ b/app/reducers/navigation.jsx @@ -12,26 +12,124 @@ import { REFRESH } from '../constants/navigation' +import React from 'react' +import Styles from 'material-ui/lib/styles' +import ActionGrade from 'material-ui/lib/svg-icons/action/grade' +import History from 'material-ui/lib/svg-icons/action/history' +import Folder from 'material-ui/lib/svg-icons/file/folder' +import Delete from 'material-ui/lib/svg-icons/action/delete' + import * as utils from '../utils' import glob from 'glob' import jsfile from 'jsonfile' import path from 'path-extra' +import mkdirp from 'mkdirp' -// Load default selection -utils.createNotebookDir('Entries') +const Colors = Styles.Colors -const initialState = -{ - selection: utils.loadNotebookByName('Entries'), - selectionIndex: 0, - selectionType: MENU_TYPE, - menuItems: [], - notebooks: [], - callback: () => {} -} +const initialState = getInitialState() var emptyFunc = () => {} +function initDefaultNotebookPath(notebook){ + var nbPath = utils.getNotebookPath(notebook) + var dir = mkdirp.sync(nbPath) + + var notePath = utils.getNotebookPath(notebook) + + var meta = { + 'name': notebook.title, + 'uuid': notebook.uuid + } + + var metaPath = path.join(nbPath, 'meta.json') + jsfile.writeFileSync(metaPath, meta) + +} + +function getInitialState(){ + var menuItems = [ + { + 'name': 'Entries', + 'isNotebook': true, + 'icon': , + }, + { + 'name': 'Starred', + 'notes': 0, + 'icon': , + }, + { + 'name': 'Recents', + 'notes': 0, + 'icon': , + 'glob': '*.qvnotebook/*.qvnote', + 'filter': (notes) => { + // Get the 10 most recent notes + notes.sort(utils.compareNotes()) + return notes.slice(0, 10) + } + }, + { + 'name': 'Trash', + 'isNotebook': true, + 'icon': , + }, + { + 'name': 'All Notes', + 'notes': 0, + 'glob': '*.qvnotebook/*.qvnote', + 'icon': , + } + + ] + + for(var i=0; i {} + } + + return state +} + + function findIndexGeneric(array, notebook, type){ for(var i=0; i