Skip to content

Commit

Permalink
Widget list sort by focus time, not open time
Browse files Browse the repository at this point in the history
  • Loading branch information
HyunmoAhn committed Aug 4, 2018
1 parent 11966f8 commit d0ce7b2
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 44 deletions.
1 change: 1 addition & 0 deletions app/actions/actionTypes.js
Expand Up @@ -16,6 +16,7 @@ export const REGISTER_NEW_WIDGET = 'REGISTER_NEW_WIDGET';
export const SHOW_TARGET_WIDGET = 'SHOW_TARGET_WIDGET';
export const UPDATE_TARGET_WIDGET_INFO = 'UPDATE_TARGET_WIDGET_INFO';
export const SET_ALL_WIDGET_ISOPEN_FALSE = 'SET_ALL_WIDGET_ISOPEN_FALSE';
export const FOCUS_WIDGET = 'FOCUS_WIDGET';

export const MODAL_OPEN = 'MODAL_OPEN';
export const MODAL_CLOSE = 'MODAL_CLOSE';
Expand Down
7 changes: 6 additions & 1 deletion app/actions/widget/index.js
Expand Up @@ -20,6 +20,7 @@ export const {
closeTargetWidget,
closeTargetWidgetForced,
deleteTargetWidget,
focusWidget,
registerNewWidget,
showTargetWidget,
updateTargetWidgetInfo,
Expand All @@ -36,12 +37,16 @@ export const {
id => ({ id }),
() => ({ category: CATEGORY.BROADCAST }),
],
[TYPES.FOCUS_WIDGET]: [
id => ({ id, time: moment().toISOString() }),
() => ({ category: CATEGORY.BROADCAST }),
],
[TYPES.REGISTER_NEW_WIDGET]: [
(id, info) => ({ id, info }),
() => ({ category: CATEGORY.BROADCAST }),
],
[TYPES.SHOW_TARGET_WIDGET]: [
(id, isFocus) => ({ id, time: moment().toISOString(), isFocus }),
(id, isFocus) => ({ id, isFocus }),
() => ({ category: CATEGORY.BROADCAST }),
],
[TYPES.UPDATE_TARGET_WIDGET_INFO]: [
Expand Down
13 changes: 13 additions & 0 deletions app/actions/widget/widget.spec.js
Expand Up @@ -69,6 +69,19 @@ describe('test action about widget', () => {
.toEqual(mockAction);
});

it('should handle focusWidget', () => {
const mockAction = {
type: TYPES.FOCUS_WIDGET,
payload: {
id: mockId,
},
meta: broadcastMeta,
};

expect(actions.focusWidget(mockId))
.toEqual(mockAction);
});

it('should handle registerNewWidget', () => {
const mockAction = {
type: TYPES.REGISTER_NEW_WIDGET,
Expand Down
25 changes: 24 additions & 1 deletion app/store/share/widgets/__test__/reducers/byId.spec.js
Expand Up @@ -37,7 +37,6 @@ describe('test widgets byId reducer', () => {
name: 'mock-name',
url: 'mock-url',
isOpen: true,
resentOpenTime: 'mockISO',
};
const initialState = {
[mockId]: mockInfo,
Expand All @@ -50,6 +49,30 @@ describe('test widgets byId reducer', () => {
.toEqual(Immutable.fromJS(resultState));
});

it('should handle FOUCS_WIDGET', () => {
const mockId = 'mock-id';
const mockInfo = {
name: 'mock-name',
url: 'mock-url',
isOpen: false,
};
const resultInfo = {
name: 'mock-name',
url: 'mock-url',
isOpen: false,
resentFocusTime: 'mockISO',
};
const initialState = {
[mockId]: mockInfo,
};
const resultState = {
[mockId]: resultInfo,
};

expect(byId(Immutable.fromJS(initialState), widgetActions.focusWidget(mockId)))
.toEqual(Immutable.fromJS(resultState));
});

it('should handle CLOSE_TARGET_WIDGET', () => {
const mockId = 'mock-id';
const initialState = {
Expand Down
72 changes: 36 additions & 36 deletions app/store/share/widgets/__test__/selectors.spec.js
Expand Up @@ -31,15 +31,15 @@ describe('test widgets selector', () => {
byId: {
mock1: {
a: 'aa',
resentOpenTime: moment('2018-01-01').toISOString(),
resentFocusTime: moment('2018-01-01').toISOString(),
},
mock2: {
2: '22',
resentOpenTime: moment('2017-01-02').toISOString(),
resentFocusTime: moment('2017-01-02').toISOString(),
},
mock3: {
3: '33',
resentOpenTime: moment('2018-01-03').toISOString(),
resentFocusTime: moment('2018-01-03').toISOString(),
},
},
},
Expand All @@ -50,15 +50,15 @@ describe('test widgets selector', () => {
.toEqual(Immutable.fromJS([
{
3: '33',
resentOpenTime: moment('2018-01-03').toISOString(),
resentFocusTime: moment('2018-01-03').toISOString(),
},
{
a: 'aa',
resentOpenTime: moment('2018-01-01').toISOString(),
resentFocusTime: moment('2018-01-01').toISOString(),
},
{
2: '22',
resentOpenTime: moment('2017-01-02').toISOString(),
resentFocusTime: moment('2017-01-02').toISOString(),
},
]));
});
Expand Down Expand Up @@ -164,22 +164,22 @@ describe('test widgets selector', () => {
mock1: {
a: 'aa',
favorites: true,
resentOpenTime: moment('2018-01-04').toISOString(),
resentFocusTime: moment('2018-01-04').toISOString(),
},
mock2: {
b: 'bb',
favorites: true,
resentOpenTime: moment('2018-01-03').toISOString(),
resentFocusTime: moment('2018-01-03').toISOString(),
},
mock3: {
c: 'cc',
favorites: false,
resentOpenTime: moment('2018-01-02').toISOString(),
resentFocusTime: moment('2018-01-02').toISOString(),
},
mock4: {
d: 'dd',
favorites: true,
resentOpenTime: moment('2018-01-01').toISOString(),
resentFocusTime: moment('2018-01-01').toISOString(),
},
},
},
Expand All @@ -191,22 +191,22 @@ describe('test widgets selector', () => {
{
a: 'aa',
favorites: true,
resentOpenTime: moment('2018-01-04').toISOString(),
resentFocusTime: moment('2018-01-04').toISOString(),
},
{
b: 'bb',
favorites: true,
resentOpenTime: moment('2018-01-03').toISOString(),
resentFocusTime: moment('2018-01-03').toISOString(),
},
{
c: 'cc',
favorites: false,
resentOpenTime: moment('2018-01-02').toISOString(),
resentFocusTime: moment('2018-01-02').toISOString(),
},
{
d: 'dd',
favorites: true,
resentOpenTime: moment('2018-01-01').toISOString(),
resentFocusTime: moment('2018-01-01').toISOString(),
},
]));
});
Expand All @@ -224,22 +224,22 @@ describe('test widgets selector', () => {
mock1: {
a: 'aa',
favorites: true,
resentOpenTime: moment('2018-01-04').toISOString(),
resentFocusTime: moment('2018-01-04').toISOString(),
},
mock2: {
b: 'bb',
favorites: true,
resentOpenTime: moment('2018-01-03').toISOString(),
resentFocusTime: moment('2018-01-03').toISOString(),
},
mock3: {
c: 'cc',
favorites: false,
resentOpenTime: moment('2018-01-02').toISOString(),
resentFocusTime: moment('2018-01-02').toISOString(),
},
mock4: {
d: 'dd',
favorites: true,
resentOpenTime: moment('2018-01-01').toISOString(),
resentFocusTime: moment('2018-01-01').toISOString(),
},
},
},
Expand All @@ -251,17 +251,17 @@ describe('test widgets selector', () => {
{
a: 'aa',
favorites: true,
resentOpenTime: moment('2018-01-04').toISOString(),
resentFocusTime: moment('2018-01-04').toISOString(),
},
{
b: 'bb',
favorites: true,
resentOpenTime: moment('2018-01-03').toISOString(),
resentFocusTime: moment('2018-01-03').toISOString(),
},
{
d: 'dd',
favorites: true,
resentOpenTime: moment('2018-01-01').toISOString(),
resentFocusTime: moment('2018-01-01').toISOString(),
},
]));
});
Expand All @@ -282,25 +282,25 @@ describe('test widgets selector', () => {
name: 'search-name',
url: 'not-target-url',
favorites: true,
resentOpenTime: moment('2018-01-04').toISOString(),
resentFocusTime: moment('2018-01-04').toISOString(),
},
mock2: {
name: 'not-target-name',
url: 'search-url',
favorites: true,
resentOpenTime: moment('2018-01-03').toISOString(),
resentFocusTime: moment('2018-01-03').toISOString(),
},
mock3: {
name: 'not-target-name',
url: 'not-target-url',
favorites: false,
resentOpenTime: moment('2018-01-02').toISOString(),
resentFocusTime: moment('2018-01-02').toISOString(),
},
mock4: {
name: 'search-name',
url: 'search-url',
favorites: true,
resentOpenTime: moment('2018-01-01').toISOString(),
resentFocusTime: moment('2018-01-01').toISOString(),
},
},
},
Expand All @@ -313,25 +313,25 @@ describe('test widgets selector', () => {
name: 'search-name',
url: 'not-target-url',
favorites: true,
resentOpenTime: moment('2018-01-04').toISOString(),
resentFocusTime: moment('2018-01-04').toISOString(),
},
{
name: 'not-target-name',
url: 'search-url',
favorites: true,
resentOpenTime: moment('2018-01-03').toISOString(),
resentFocusTime: moment('2018-01-03').toISOString(),
},
{
name: 'not-target-name',
url: 'not-target-url',
favorites: false,
resentOpenTime: moment('2018-01-02').toISOString(),
resentFocusTime: moment('2018-01-02').toISOString(),
},
{
name: 'search-name',
url: 'search-url',
favorites: true,
resentOpenTime: moment('2018-01-01').toISOString(),
resentFocusTime: moment('2018-01-01').toISOString(),
},
]));
});
Expand All @@ -351,25 +351,25 @@ describe('test widgets selector', () => {
name: 'search-name',
url: 'not-target-url',
favorites: true,
resentOpenTime: moment('2018-01-04').toISOString(),
resentFocusTime: moment('2018-01-04').toISOString(),
},
mock2: {
name: 'not-target-name',
url: 'search-url',
favorites: true,
resentOpenTime: moment('2018-01-03').toISOString(),
resentFocusTime: moment('2018-01-03').toISOString(),
},
mock3: {
name: 'not-target-name',
url: 'not-target-url',
favorites: true,
resentOpenTime: moment('2018-01-02').toISOString(),
resentFocusTime: moment('2018-01-02').toISOString(),
},
mock4: {
name: 'search-name',
url: 'search-url',
favorites: true,
resentOpenTime: moment('2018-01-01').toISOString(),
resentFocusTime: moment('2018-01-01').toISOString(),
},
},
},
Expand All @@ -383,21 +383,21 @@ describe('test widgets selector', () => {
url: 'search-url',
favorites: true,
searched: 'both',
resentOpenTime: moment('2018-01-01').toISOString(),
resentFocusTime: moment('2018-01-01').toISOString(),
},
{
name: 'search-name',
url: 'not-target-url',
favorites: true,
searched: 'name',
resentOpenTime: moment('2018-01-04').toISOString(),
resentFocusTime: moment('2018-01-04').toISOString(),
},
{
name: 'not-target-name',
url: 'search-url',
favorites: true,
searched: 'url',
resentOpenTime: moment('2018-01-03').toISOString(),
resentFocusTime: moment('2018-01-03').toISOString(),
},
]));
});
Expand Down
10 changes: 8 additions & 2 deletions app/store/share/widgets/reducers/byId.js
Expand Up @@ -13,10 +13,10 @@ const byIdReducer = handleActions({
return state.set(id, Immutable.fromJS(widgetInfo));
},
[TYPES.SHOW_TARGET_WIDGET]: (state, action) => {
const { id, time } = action.payload;
const { id } = action.payload;
const widget = state.get(id);

return state.set(id, widget.set('isOpen', true).set('resentOpenTime', time));
return state.set(id, widget.set('isOpen', true));
},
[combineActions(
TYPES.CLOSE_TARGET_WIDGET,
Expand All @@ -32,6 +32,12 @@ const byIdReducer = handleActions({

return state.delete(id);
},
[TYPES.FOCUS_WIDGET]: (state, action) => {
const { id, time } = action.payload;
const widget = state.get(id);

return state.set(id, widget.set('resentFocusTime', time));
},
[TYPES.UPDATE_TARGET_WIDGET_INFO]: (state, action) => {
const { id, info } = action.payload;

Expand Down
4 changes: 2 additions & 2 deletions app/store/share/widgets/selectors.js
Expand Up @@ -22,8 +22,8 @@ export const getWidgetArray = createSelector(
(byId) => {
const array = byId.toArray();
array.sort((lItem, rItem) => {
const lTime = lItem.get('resentOpenTime');
const rTime = rItem.get('resentOpenTime');
const lTime = lItem.get('resentFocusTime');
const rTime = rItem.get('resentFocusTime');

return moment(rTime).unix() - moment(lTime).unix();
});
Expand Down

0 comments on commit d0ce7b2

Please sign in to comment.