1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 09:46:22 +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

@@ -1,4 +1,5 @@
// Action types
export const CLEAR_NEW_ARTICLE = 'CLEAR_NEW_ARTICLE'
export const ARTICLE_UPDATE = 'ARTICLE_UPDATE'
export const ARTICLE_DESTROY = 'ARTICLE_DESTROY'
export const FOLDER_CREATE = 'FOLDER_CREATE'
@@ -18,13 +19,18 @@ export const TOGGLE_TUTORIAL = 'TOGGLE_TUTORIAL'
// Status - mode
export const IDLE_MODE = 'IDLE_MODE'
export const CREATE_MODE = 'CREATE_MODE'
export const EDIT_MODE = 'EDIT_MODE'
// Article status
export const NEW = 'NEW'
// DB
export function clearNewArticle () {
return {
type: CLEAR_NEW_ARTICLE
}
}
export function updateArticle (article) {
return {
type: ARTICLE_UPDATE,
@@ -84,10 +90,13 @@ export function switchMode (mode) {
}
}
export function switchArticle (articleKey) {
export function switchArticle (articleKey, isNew) {
return {
type: SWITCH_ARTICLE,
data: articleKey
data: {
key: articleKey,
isNew: isNew
}
}
}

View File

@@ -1,6 +1,6 @@
import React, { PropTypes } from 'react'
import store from 'boost/store'
import { unlockStatus } from 'boost/actions'
import { unlockStatus, clearNewArticle } from 'boost/actions'
export default class EditedAlert extends React.Component {
handleNoButtonClick (e) {
@@ -10,6 +10,7 @@ export default class EditedAlert extends React.Component {
handleYesButtonClick (e) {
store.dispatch(unlockStatus())
store.dispatch(this.props.action)
store.dispatch(clearNewArticle())
this.props.close()
}

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