Skip to content

Commit

Permalink
fix(ui): Notice marked read when UI closed (#346)
Browse files Browse the repository at this point in the history
* refactor(read): rename read to markRead

* fix(markRead): mark read when ui is closed

* feat(ui): add close cause to close action

* feat(ui): send close action to background

* feat(ui): add cause to closed action, given from close action

* feat(ui): only mark notices read if closed from button

* refactor(migrations): refactor V3-V4 migration

* fix(migrations): fix Migration 3->4

* test(migrations): add unit tests for migration 4

* style: fix ESLint issues
  • Loading branch information
bmenant authored and JalilArfaoui committed Aug 29, 2019
1 parent 5fa9952 commit c2cc908
Show file tree
Hide file tree
Showing 46 changed files with 568 additions and 297 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
},
"project": "tsconfig.json"
},
"env": {
"mocha": true
},
"settings": {
"react": {
"version": "detect" // React version. "detect" automatically picks the version you have installed.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
"svg-url-loader": "^2.0.2",
"ts-node": "^8.3.0",
"tsconfig-paths": "^3.8.0",
"ramda-adjunct": "^2.19.0",
"typeface-lato": "^0.0.54",
"typeface-sedgwick-ave": "^0.0.54",
"typescript": "^3.5.3",
Expand Down
4 changes: 2 additions & 2 deletions src/app/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { CloseAction, ClosedAction, OpenAction, OpenedAction } from './ui';
import {
FeedbackOnNoticeAction,
NoticesFoundAction,
ReadNoticeAction
MarkNoticeReadAction
} from './notices';
import { Action } from 'redux';
import Tab from 'app/lmem/Tab';
Expand Down Expand Up @@ -102,7 +102,7 @@ export type AppAction =
| ClosedAction
| NoticesFoundAction
| FeedbackOnNoticeAction
| ReadNoticeAction
| MarkNoticeReadAction
| SetUITitleAction
| RemoveUITitleAction
| (LocationChangeAction & { meta?: ActionMeta });
8 changes: 4 additions & 4 deletions src/app/actions/notices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ export const undislikeNotice = (id: number): FeedbackOnNoticeAction => ({
meta: { sendToBackground: true }
});

export interface ReadNoticeAction extends BaseAction {
type: 'READ_NOTICE';
export interface MarkNoticeReadAction extends BaseAction {
type: 'MARK_NOTICE_READ';
payload: number;
}

export const readNotice = (id: number): ReadNoticeAction => ({
type: 'READ_NOTICE',
export const markNoticeRead = (id: number): MarkNoticeReadAction => ({
type: 'MARK_NOTICE_READ',
payload: id,
meta: { sendToBackground: true }
});
Expand Down
15 changes: 13 additions & 2 deletions src/app/actions/ui.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BaseAction, ErrorAction } from '.';
import { CloseCause } from '../lmem/ui';

export interface OpenAction extends BaseAction {
type: 'OPEN';
Expand All @@ -21,8 +22,13 @@ export const openFailed = (e: Error): OpenFailedAction => ({

export interface CloseAction extends BaseAction {
type: 'CLOSE';
payload: { cause: CloseCause };
}
export const close = (): CloseAction => ({ type: 'CLOSE' });
export const close = (cause: CloseCause): CloseAction => ({
type: 'CLOSE',
payload: { cause },
meta: { sendToBackground: true }
});

export interface CloseFailedAction extends ErrorAction {
type: 'CLOSE_FAILED';
Expand All @@ -35,5 +41,10 @@ export const closeFailed = (e: Error): CloseFailedAction => ({

export interface ClosedAction extends BaseAction {
type: 'CLOSED';
payload: { cause: CloseCause };
}
export const closed = (): ClosedAction => ({ type: 'CLOSED' });
export const closed = (cause: CloseCause): ClosedAction => ({
type: 'CLOSED',
payload: { cause },
meta: { sendToBackground: true }
});
6 changes: 5 additions & 1 deletion src/app/background/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ import { combineReducers } from 'redux';
import prefs, { PrefsState } from './prefs';
import resources, { ResourcesState } from './resources';
import tabs, { TabsState } from './tabs';
import { PersistedState } from 'redux-persist/es/types';

export interface BackgroundState {
export interface PersistedBackgroundState extends PersistedState {
prefs: PrefsState;
}

export interface BackgroundState extends PersistedBackgroundState {
resources: ResourcesState;
tabs: TabsState;
}
Expand Down
15 changes: 10 additions & 5 deletions src/app/background/reducers/prefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@ export interface PrefsState {
dismissedNotices: number[];
likedNotices: number[];
dislikedNotices: number[];
readNotices: number[];
markedReadNotices: number[];
}

const initialPrefs: PrefsState = {
installationDetails: { version },
dismissedNotices: [],
likedNotices: [],
dislikedNotices: [],
readNotices: []
markedReadNotices: []
};

export function prefs(state: PrefsState = initialPrefs, action: AppAction) {
export function prefs(
state: PrefsState = initialPrefs,
action: AppAction
): PrefsState {
switch (action.type) {
case 'INSTALLED': {
return { ...state, installationDetails: action.payload.details };
Expand Down Expand Up @@ -71,10 +74,12 @@ export function prefs(state: PrefsState = initialPrefs, action: AppAction) {
}
return state;

case 'READ_NOTICE':
case 'MARK_NOTICE_READ':
return {
...state,
readNotices: R.uniq(R.concat(state.readNotices, [action.payload]))
markedReadNotices: R.uniq(
R.concat(state.markedReadNotices, [action.payload])
)
};

default:
Expand Down
7 changes: 4 additions & 3 deletions src/app/background/selectors/prefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export const getLiked = (state: BackgroundState) =>
getPrefs(state).likedNotices;
export const getDisliked = (state: BackgroundState) =>
getPrefs(state).dislikedNotices;
export const getRead = (state: BackgroundState) => getPrefs(state).readNotices;
export const getMarkedRead = (state: BackgroundState) =>
getPrefs(state).markedReadNotices;

export const getInitialContent = (state: BackgroundState) => ({
installationDetails: getInstallationDetails(state)
Expand All @@ -26,15 +27,15 @@ export const getAddStateToNotice = (state: BackgroundState) => {
const dismissed = getDismissed(state);
const liked = getLiked(state);
const disliked = getDisliked(state);
const read = getRead(state);
const markedRead = getMarkedRead(state);

return (notice: Notice): StatefulNotice => ({
...notice,
state: {
dismissed: dismissed.includes(notice.id),
liked: liked.includes(notice.id),
disliked: disliked.includes(notice.id),
read: read.includes(notice.id)
markedRead: markedRead.includes(notice.id)
}
});
};
Expand Down
9 changes: 0 additions & 9 deletions src/app/background/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,3 @@ persistStore(store);
listenTabs(store);

sagaMiddleware.run(rootSaga);

// FIXME
// if (process.env.NODE_ENV !== 'production') {
// if (module.hot) {
// module.hot.accept('../reducers', () =>
// store.replaceReducer(require('../reducers'))
// );
// }
//
155 changes: 0 additions & 155 deletions src/app/background/store/migrations.ts

This file was deleted.

57 changes: 57 additions & 0 deletions src/app/background/store/migrations/1.2017-01-26.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { PersistedState } from 'redux-persist/es/types';
import * as R from 'ramda';
import { StateV1orV2 } from './StateV1';
import { StateV0V1orV2 } from './StateV0';

export const migration1 = (persistedState: PersistedState): StateV1orV2 => {
const previousState: StateV0V1orV2 = persistedState as StateV0V1orV2;

return R.compose(
R.compose(
R.assocPath(
['prefs', 'websites'],
previousState && previousState.prefs
? previousState.prefs.websites
: previousState.websites || []
),
R.assocPath(
['prefs', 'criteria'],
previousState && previousState.prefs
? previousState.prefs.criteria
: previousState.criteria || []
),
R.assocPath(
['prefs', 'editors'],
previousState && previousState.prefs
? previousState.prefs.editors
: previousState.editors || []
),
R.assocPath(
['prefs', 'dismissedRecos'],
previousState && previousState.prefs
? previousState.prefs.dismissedRecos
: previousState.dismissedRecos || []
),
R.assocPath(
['prefs', 'approvedRecos'],
previousState && previousState.prefs
? previousState.prefs.approvedRecos
: previousState.approvedRecos || []
),
R.assocPath(
['prefs', 'onInstalledDetails'],
previousState && previousState.prefs
? previousState.prefs.onInstalledDetails
: previousState.onInstalledDetails || []
)
),
R.compose(
R.dissoc('websites'),
R.dissoc('criteria'),
R.dissoc('editors'),
R.dissoc('dismissedRecos'),
R.dissoc('approvedRecos'),
R.dissoc('onInstalledDetails')
)
)(previousState) as StateV1orV2;
};
Loading

0 comments on commit c2cc908

Please sign in to comment.