Skip to content

Commit

Permalink
Collapse/expand all collections
Browse files Browse the repository at this point in the history
  • Loading branch information
Rustem Mussabekov committed Jun 24, 2024
1 parent 3399c82 commit 701ff50
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "app",
"version": "5.6.37",
"version": "5.6.38",
"description": "All-in-one bookmark manager",
"author": "Rustem Mussabekov",
"license": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions src/data/actions/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
COLLECTION_ADD_BLANK, COLLECTION_CREATE_FROM_BLANK, COLLECTION_REMOVE_BLANK,
COLLECTION_TOGGLE, COLLECTION_REORDER, COLLECTION_CHANGE_VIEW, COLLECTIONS_CHANGE_VIEW, COLLECTION_EMPTY_TRASH,
COLLECTION_COVER_UPLOAD_REQ,
COLLECTIONS_DEFAULTS_CHANGE, COLLECTIONS_EXPAND_TO, COLLECTIONS_COLLAPSE_ALL,
COLLECTIONS_DEFAULTS_CHANGE, COLLECTIONS_EXPAND_TO, COLLECTIONS_TOGGLE_ALL,
GROUP_CREATE, GROUP_TOGGLE, GROUP_REORDER, GROUP_REMOVE, GROUP_RENAME,
COLLECTIONS_SELECT_ONE, COLLECTIONS_UNSELECT_ONE, COLLECTIONS_SELECT_ALL, COLLECTIONS_UNSELECT_ALL,
COLLECTIONS_SELECTED_MERGE, COLLECTIONS_SELECTED_REMOVE,
Expand Down Expand Up @@ -199,7 +199,7 @@ export const expandTo = (_id, self)=>({

//Toggle all collections
export const toggle = ()=>({
type: COLLECTIONS_COLLAPSE_ALL
type: COLLECTIONS_TOGGLE_ALL
})

//Select mode
Expand Down
2 changes: 1 addition & 1 deletion src/data/constants/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const
COLLECTIONS_DEFAULTS_CHANGE = 'COLLECTIONS_DEFAULTS_CHANGE',
COLLECTIONS_REORDER = 'COLLECTIONS_REORDER',
COLLECTIONS_EXPAND_TO = 'COLLECTIONS_EXPAND_TO',
COLLECTIONS_COLLAPSE_ALL = 'COLLECTIONS_COLLAPSE_ALL',
COLLECTIONS_TOGGLE_ALL = 'COLLECTIONS_TOGGLE_ALL',
COLLECTIONS_CHANGE_VIEW = 'COLLECTIONS_CHANGE_VIEW',

//Single helpers
Expand Down
8 changes: 5 additions & 3 deletions src/data/reducers/collections/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
COLLECTIONS_LOAD_PRE, COLLECTIONS_LOAD_REQ, COLLECTIONS_LOAD_SUCCESS, COLLECTIONS_LOAD_ERROR,
COLLECTIONS_REFRESH_REQ,
COLLECTIONS_REORDER,
COLLECTIONS_EXPAND_TO, COLLECTIONS_COLLAPSE_ALL,
COLLECTIONS_EXPAND_TO, COLLECTIONS_TOGGLE_ALL,
COLLECTIONS_CLEAN_SUCCESS, COLLECTIONS_CLEAN_ERROR,
COLLECTIONS_CHANGE_VIEW
} from '../../constants/collections'
Expand Down Expand Up @@ -117,9 +117,11 @@ export default function(state, action) {switch (action.type) {
return state
}

case COLLECTIONS_COLLAPSE_ALL:{
case COLLECTIONS_TOGGLE_ALL:{
action.expanded = Object.entries(state.items).some(([_id])=>_id > 0 && !state.getIn(['items', _id, 'expanded']))

Object.entries(state.items).forEach(([_id])=>{
state = state.setIn(['items', _id, 'expanded'], false)
state = state.setIn(['items', _id, 'expanded'], action.expanded)
})

return state
Expand Down
8 changes: 4 additions & 4 deletions src/data/sagas/collections/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import _ from 'lodash-es'
import {
COLLECTIONS_LOAD_PRE, COLLECTIONS_LOAD_REQ, COLLECTIONS_LOAD_SUCCESS, COLLECTIONS_LOAD_ERROR,
COLLECTIONS_REFRESH_REQ,
COLLECTIONS_COLLAPSE_ALL,
COLLECTIONS_TOGGLE_ALL,
COLLECTIONS_REORDER,
COLLECTIONS_REMOVE_ALL,
COLLECTIONS_CLEAN_REQ,
Expand All @@ -23,7 +23,7 @@ export default function* () {
yield takeEvery([ COLLECTIONS_LOAD_PRE, COLLECTIONS_REFRESH_REQ ], preLoadCollections)
yield takeEvery([ COLLECTIONS_LOAD_REQ, COLLECTION_DRAFT_LOAD_REQ ], loadCollections)

yield takeEvery(COLLECTIONS_COLLAPSE_ALL, collapseAll)
yield takeEvery(COLLECTIONS_TOGGLE_ALL, toggleAll)
yield takeEvery(COLLECTIONS_REORDER, reorderAll)
yield takeEvery(COLLECTIONS_CHANGE_VIEW, changeView)

Expand Down Expand Up @@ -84,10 +84,10 @@ export function* loadCollections({ ignore=false, onSuccess, onFail }) {
}
}

function* collapseAll({ ignore=false }){
function* toggleAll({ ignore=false, expanded=false }){
if (ignore) return

yield call(Api.put, 'collections', { expanded: false })
yield call(Api.put, 'collections', { expanded })
}

function* reorderAll({ ignore=false, method }){
Expand Down

0 comments on commit 701ff50

Please sign in to comment.