0.2.3 #99
2 changed files with 29 additions and 29 deletions
|
|
@ -12,33 +12,6 @@ import {
|
||||||
import { MARK_POST_READ } from '../actions/posts.js';
|
import { MARK_POST_READ } from '../actions/posts.js';
|
||||||
import { MARK_SECTION_READ } from '../actions/selected.js';
|
import { MARK_SECTION_READ } from '../actions/selected.js';
|
||||||
|
|
||||||
const markCategoryRead = (action, state) => {
|
|
||||||
const category = { ...state.items[action.section.id] };
|
|
||||||
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
items: {
|
|
||||||
...state.items,
|
|
||||||
[category.id]: { ...category, unread: 0 },
|
|
||||||
},
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const markCategoryByRule = (action, state) => {
|
|
||||||
const category = { ...state.items[action.section.category] };
|
|
||||||
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
items: {
|
|
||||||
...state.items,
|
|
||||||
[category.id]: {
|
|
||||||
...category,
|
|
||||||
unread: category.unread - action.section.unread,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const defaultState = { items: {}, isFetching: false };
|
const defaultState = { items: {}, isFetching: false };
|
||||||
|
|
||||||
export const categories = (state = { ...defaultState }, action) => {
|
export const categories = (state = { ...defaultState }, action) => {
|
||||||
|
|
@ -83,11 +56,32 @@ export const categories = (state = { ...defaultState }, action) => {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
case MARK_SECTION_READ:
|
case MARK_SECTION_READ:
|
||||||
|
category = {};
|
||||||
|
|
||||||
switch (action.section.type) {
|
switch (action.section.type) {
|
||||||
case CATEGORY_TYPE:
|
case CATEGORY_TYPE:
|
||||||
return markCategoryRead(action, state);
|
category = { ...state.items[action.section.id] };
|
||||||
|
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
items: {
|
||||||
|
...state.items,
|
||||||
|
[category.id]: { ...category, unread: 0 },
|
||||||
|
},
|
||||||
|
};
|
||||||
case RULE_TYPE:
|
case RULE_TYPE:
|
||||||
return markCategoryByRule(action, state);
|
category = { ...state.items[action.section.category] };
|
||||||
|
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
items: {
|
||||||
|
...state.items,
|
||||||
|
[category.id]: {
|
||||||
|
...category,
|
||||||
|
unread: category.unread - action.section.unread,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import {
|
||||||
} from '../actions/posts.js';
|
} from '../actions/posts.js';
|
||||||
|
|
||||||
import { MARK_SECTION_READ } from '../actions/selected.js';
|
import { MARK_SECTION_READ } from '../actions/selected.js';
|
||||||
|
import { MARK_POST_READ } from '../actions/posts.js';
|
||||||
|
|
||||||
const defaultState = { item: {}, next: false, lastReached: false, post: {} };
|
const defaultState = { item: {}, next: false, lastReached: false, post: {} };
|
||||||
|
|
||||||
|
|
@ -75,6 +76,11 @@ export const selected = (state = { ...defaultState }, action) => {
|
||||||
...state,
|
...state,
|
||||||
post: {},
|
post: {},
|
||||||
};
|
};
|
||||||
|
case MARK_POST_READ:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
item: { ...action.section, unread: action.section.unread - 1 },
|
||||||
|
};
|
||||||
case MARK_SECTION_READ:
|
case MARK_SECTION_READ:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue