1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-14 02:06:29 +00:00

fix: 新しい記事を書く時に発生するバグ一体

This commit is contained in:
Rokt33r
2015-11-22 15:03:48 +09:00
parent 7d9894bef7
commit 954b3e9fc5
7 changed files with 89 additions and 56 deletions

View File

@@ -15,6 +15,7 @@ import {
// Article action type
ARTICLE_UPDATE,
ARTICLE_DESTROY,
CLEAR_NEW_ARTICLE,
// Folder action type
FOLDER_CREATE,
@@ -23,8 +24,7 @@ import {
FOLDER_REPLACE,
// view mode
IDLE_MODE,
CREATE_MODE
IDLE_MODE
} from './actions'
import dataStore from 'boost/dataStore'
import keygen from 'boost/keygen'
@@ -43,6 +43,9 @@ let data = dataStore.getData()
let initialArticles = data.articles
let initialFolders = data.folders
let isStatusLocked = false
let isCreatingNew = false
function folders (state = initialFolders, action) {
state = state.slice()
switch (action.type) {
@@ -121,10 +124,41 @@ function folders (state = initialFolders, action) {
return state
}
}
let isCleaned = true
function articles (state = initialArticles, action) {
state = state.slice()
if (!isCreatingNew && !isCleaned) {
state = state.filter(article => article.status !== 'NEW')
isCleaned = true
}
switch (action.type) {
case SWITCH_ARTICLE:
if (action.data.isNew) {
isCleaned = false
}
if (!isStatusLocked && !action.data.isNew) {
isCreatingNew = false
if (!isCleaned) {
state = state.filter(article => article.status !== 'NEW')
isCleaned = true
}
}
return state
case SWITCH_FOLDER:
case SET_SEARCH_FILTER:
case SET_TAG_FILTER:
case CLEAR_SEARCH:
if (!isStatusLocked) {
isCreatingNew = false
if (!isCleaned) {
state = state.filter(article => article.status !== 'NEW')
isCleaned = true
}
}
return state
case CLEAR_NEW_ARTICLE:
return state.filter(article => article.status !== 'NEW')
case ARTICLE_UPDATE:
{
let article = action.data.article
@@ -133,7 +167,8 @@ function articles (state = initialArticles, action) {
if (targetIndex < 0) state.unshift(article)
else state.splice(targetIndex, 1, article)
dataStore.setArticles(null, state)
if (article.status !== 'NEW') dataStore.setArticles(null, state)
else isCreatingNew = true
return state
}
case ARTICLE_DESTROY:
@@ -162,16 +197,15 @@ function articles (state = initialArticles, action) {
function status (state = initialStatus, action) {
state = Object.assign({}, state)
switch (action.type) {
case TOGGLE_TUTORIAL:
state.isTutorialOpen = !state.isTutorialOpen
return state
case LOCK_STATUS:
state.isStatusLocked = true
isStatusLocked = state.isStatusLocked = true
return state
case UNLOCK_STATUS:
state.isStatusLocked = false
isStatusLocked = state.isStatusLocked = false
return state
}
@@ -188,11 +222,10 @@ function status (state = initialStatus, action) {
return state
case SWITCH_MODE:
state.mode = action.data
if (state.mode === CREATE_MODE) state.articleKey = null
return state
case SWITCH_ARTICLE:
state.articleKey = action.data
state.articleKey = action.data.key
state.mode = IDLE_MODE
return state