Skip to content

Commit

Permalink
Move showTrash from appState to Redux (#1901)
Browse files Browse the repository at this point in the history
Move showTrash from appState to Redux
  • Loading branch information
belcherj authored Feb 18, 2020
1 parent a9b36ff commit f5d3033
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 17 deletions.
8 changes: 0 additions & 8 deletions lib/flux/app-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ const initialState: AppState = {
notes: null,
tags: [],
revision: null,
showTrash: false,
showNavigation: false,
dialogs: [],
nextDialogKey: 0,
Expand Down Expand Up @@ -85,7 +84,6 @@ export const actionMap = new ActionMap({
showAllNotes(state: AppState) {
return update(state, {
showNavigation: { $set: false },
showTrash: { $set: false },
tag: { $set: null },
previousIndex: { $set: -1 },
});
Expand All @@ -94,7 +92,6 @@ export const actionMap = new ActionMap({
selectTrash(state: AppState) {
return update(state, {
showNavigation: { $set: false },
showTrash: { $set: true },
tag: { $set: null },
previousIndex: { $set: -1 },
});
Expand All @@ -116,7 +113,6 @@ export const actionMap = new ActionMap({
selectTag(state: AppState, { tag }: { tag: T.TagEntity }) {
return update(state, {
showNavigation: { $set: false },
showTrash: { $set: false },
tag: { $set: tag },
previousIndex: { $set: -1 },
});
Expand Down Expand Up @@ -176,10 +172,6 @@ export const actionMap = new ActionMap({
const { appState: state, settings } = getState();
const timestamp = new Date().getTime() / 1000;

if (state.showTrash) {
dispatch(this.action('showAllNotes'));
}

// insert a new note into the store and select it
noteBucket.add(
{
Expand Down
4 changes: 2 additions & 2 deletions lib/navigation-bar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ export class NavigationBar extends Component {
}
}

const mapStateToProps = ({ appState: state, settings }) => ({
const mapStateToProps = ({ appState: state, settings, ui: { showTrash } }) => ({
autoHideMenuBar: settings.autoHideMenuBar,
dialogs: state.dialogs,
selectedTag: state.tag,
showNavigation: state.showNavigation,
showTrash: state.showTrash,
showTrash,
});

const {
Expand Down
4 changes: 2 additions & 2 deletions lib/note-list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ const { recordEvent } = tracks;

const mapStateToProps: S.MapState<StateProps> = ({
appState: state,
ui: { filteredNotes, note, searchQuery },
ui: { filteredNotes, note, searchQuery, showTrash },
settings: { noteDisplay },
}) => {
const tagResultsFound = getMatchingTags(state.tags, searchQuery).length;
Expand Down Expand Up @@ -535,7 +535,7 @@ const mapStateToProps: S.MapState<StateProps> = ({
selectedNotePreview,
selectedNoteContent: get(selectedNote, 'data.content'),
selectedNoteId,
showTrash: state.showTrash,
showTrash,
tagResultsFound,
};
};
Expand Down
3 changes: 1 addition & 2 deletions lib/search-bar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ export const SearchBar: FunctionComponent<Props> = ({
);

const mapStateToProps: S.MapState<StateProps> = ({
appState: { showTrash },
ui: { searchQuery },
ui: { searchQuery, showTrash },
}) => ({
searchQuery,
showTrash,
Expand Down
1 change: 0 additions & 1 deletion lib/state/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export type AppState = {
revision: T.NoteEntity | null;
searchFocus: boolean;
showNavigation: boolean;
showTrash: boolean;
tags: T.TagEntity[];
tag?: T.TagEntity;
unsyncedNoteIds: T.EntityId[];
Expand Down
15 changes: 15 additions & 0 deletions lib/state/ui/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,20 @@ const showRevisions: A.Reducer<boolean> = (state = false, action) => {
}
};

const showTrash: A.Reducer<boolean> = (state = false, action) => {
switch (action.type) {
case 'App.selectTrash':
return true;
case 'CREATE_NOTE':
case 'App.selectTag':
case 'App.showAllNotes': {
return false;
}
default:
return state;
}
};

const note: A.Reducer<T.NoteEntity | null> = (state = null, action) => {
switch (action.type) {
case 'App.selectNote':
Expand Down Expand Up @@ -133,6 +147,7 @@ export default combineReducers({
showNoteInfo,
showNoteList,
showRevisions,
showTrash,
simperiumConnected,
unsyncedNoteIds,
});
4 changes: 2 additions & 2 deletions lib/utils/filter-notes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ export default function filterNotes(
notesArray: T.NoteEntity[] | null = null
) {
const {
appState: { notes, showTrash, tag },
ui: { searchQuery },
appState: { notes, tag },
ui: { searchQuery, showTrash },
} = state;

const notesToFilter = notesArray ? notesArray : notes;
Expand Down

0 comments on commit f5d3033

Please sign in to comment.