1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-15 18:56:22 +00:00

use new api for finder

This commit is contained in:
Dick Choi
2016-09-08 18:16:37 +09:00
parent 519ea1a33f
commit 40fc63ea0c
7 changed files with 76 additions and 52 deletions

View File

@@ -115,6 +115,7 @@ class NoteDetail extends React.Component {
</button>
</div>
})
let viewList = note.snippets.map((snippet, index) => {
let isActive = this.state.snippetIndex === index
let mode = snippet.mode === 'text'
@@ -133,7 +134,7 @@ class NoteDetail extends React.Component {
/>
<button styleName='tabView-top-mode'
>
{mode == null ? null : mode}
{mode == null ? null : mode.mode}
</button>
</div>
{snippet.mode === 'markdown'

View File

@@ -54,12 +54,12 @@ class NoteList extends React.Component {
}
render () {
let { storages, notes, index } = this.props
let { storageMap, notes, index } = this.props
let notesList = notes
.slice(0, 10 + 10 * this.state.range)
.map((note, _index) => {
let storage = _.find(storages, {key: note.storage})
let storage = storageMap[note.storage]
let folder = _.find(storage.folders, {key: note.folder})
return (
<NoteItem

View File

@@ -217,33 +217,51 @@ class FinderMain extends React.Component {
}
render () {
let { storages, notes, config } = this.props
let { data, config } = this.props
let { filter, search } = this.state
let storageList = storages
.map((storage) => <StorageSection
filter={filter}
storage={storage}
key={storage.key}
handleStorageButtonClick={(e, storage) => this.handleStorageButtonClick(e, storage)}
handleFolderButtonClick={(e, storage, folder) => this.handleFolderButtonClick(e, storage, folder)}
/>)
let storageList = []
for (let key in data.storageMap) {
let storage = data.storageMap[key]
let item = (
<StorageSection
filter={filter}
storage={storage}
key={storage.key}
handleStorageButtonClick={(e, storage) => this.handleStorageButtonClick(e, storage)}
handleFolderButtonClick={(e, storage, folder) => this.handleFolderButtonClick(e, storage, folder)}
/>
)
storageList.push(item)
}
let notes = []
let noteIds
switch (filter.type) {
case 'STORAGE':
noteIds = data.storageNoteMap[filter.storage]
break
case 'FOLDER':
noteIds = data.folderNoteMap[filter.storage + '-' + filter.folder]
break
case 'STARRED':
noteIds = data.starredSet
}
if (noteIds != null) {
noteIds.forEach((id) => {
notes.push(data.noteMap[id])
})
} else {
for (let key in data.noteMap) {
notes.push(data.noteMap[key])
}
}
if (!filter.includeSnippet && filter.includeMarkdown) {
notes = notes.filter((note) => note.type === 'MARKDOWN_NOTE')
} else if (filter.includeSnippet && !filter.includeMarkdown) {
notes = notes.filter((note) => note.type === 'SNIPPET_NOTE')
}
switch (filter.type) {
case 'STORAGE':
notes = notes.filter((note) => note.storage === filter.storage)
break
case 'FOLDER':
notes = notes.filter((note) => note.storage === filter.storage && note.folder === filter.folder)
break
case 'STARRED':
notes = notes.filter((note) => note.isStarred)
}
if (search.trim().length > 0) {
let needle = new RegExp(_.escapeRegExp(search.trim()), 'i')
notes = notes.filter((note) => note.title.match(needle))
@@ -302,7 +320,7 @@ class FinderMain extends React.Component {
</div>
</div>
<NoteList styleName='result-list'
storages={storages}
storageMap={data.storageMap}
notes={notes}
ref='list'
search={search}
@@ -323,14 +341,6 @@ class FinderMain extends React.Component {
}
FinderMain.propTypes = {
articles: PropTypes.array,
activeArticle: PropTypes.shape({
key: PropTypes.string,
tags: PropTypes.array,
title: PropTypes.string,
content: PropTypes.string
}),
status: PropTypes.shape(),
dispatch: PropTypes.func
}

View File

@@ -75,8 +75,7 @@ nodeIpc.connectTo(
console.log('Received data from Main renderer')
store.default.dispatch({
type: 'THROTTLE_DATA',
storages: payload.storages,
notes: payload.notes
data: payload
})
})

View File

@@ -30,17 +30,20 @@ const defaultConfig = {
}
}
function storages (state = [], action) {
switch (action.type) {
case 'THROTTLE_DATA':
state = action.storages
}
return state
let defaultData = {
storageMap: {},
noteMap: {},
starredSet: [],
storageNoteMap: {},
folderNoteMap: {},
tagNoteMap: {}
}
function notes (state = [], action) {
function data (state = defaultData, action) {
switch (action.type) {
case 'THROTTLE_DATA':
state = action.notes
console.log(action)
state = action.data
}
return state
}
@@ -66,8 +69,7 @@ function config (state = defaultConfig, action) {
}
let reducer = combineReducers({
storages,
notes,
data,
config,
routing: routerReducer
})