-
-
Notifications
You must be signed in to change notification settings - Fork 798
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: initial implementation of album lists
- Loading branch information
Showing
5 changed files
with
105 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,60 @@ | ||
const ALBUM_GRID_MODE = 'ALBUM_GRID_MODE' | ||
const ALBUM_LIST_MODE = 'ALBUM_LIST_MODE' | ||
|
||
const ALBUM_MODE_GRID = 'ALBUM_GRID_MODE' | ||
const ALBUM_MODE_LIST = 'ALBUM_LIST_MODE' | ||
const selectViewMode = (mode) => ({ type: mode }) | ||
|
||
const ALBUM_LIST_ALL = 'ALBUM_LIST_ALL' | ||
const ALBUM_LIST_RANDOM = 'ALBUM_LIST_RANDOM' | ||
const ALBUM_LIST_NEWEST = 'ALBUM_LIST_NEWEST' | ||
const ALBUM_LIST_RECENT = 'ALBUM_LIST_RECENT' | ||
const ALBUM_LIST_STARRED = 'ALBUM_LIST_STARRED' | ||
|
||
const albumListParams = { | ||
ALBUM_LIST_ALL: { sort: { field: 'name', order: 'ASC' } }, | ||
ALBUM_LIST_RANDOM: { sort: { field: 'random' } }, | ||
ALBUM_LIST_NEWEST: { sort: { field: 'created_at', order: 'DESC' } }, | ||
ALBUM_LIST_RECENT: { | ||
sort: { field: 'starred_at', order: 'DESC' }, | ||
filter: { starred: true } | ||
} | ||
} | ||
|
||
const selectAlbumList = (mode) => ({ type: mode }) | ||
|
||
const albumViewReducer = ( | ||
previousState = { | ||
mode: localStorage.getItem('albumViewMode') || ALBUM_LIST_MODE | ||
mode: localStorage.getItem('albumViewMode') || ALBUM_MODE_LIST, | ||
list: localStorage.getItem('albumListType') || ALBUM_LIST_ALL, | ||
params: { sort: {}, filter: {} } | ||
}, | ||
payload | ||
) => { | ||
const { type } = payload | ||
switch (type) { | ||
case ALBUM_GRID_MODE: | ||
case ALBUM_LIST_MODE: | ||
case ALBUM_MODE_GRID: | ||
case ALBUM_MODE_LIST: | ||
localStorage.setItem('albumViewMode', type) | ||
return { mode: type } | ||
return { ...previousState, mode: type } | ||
case ALBUM_LIST_ALL: | ||
case ALBUM_LIST_RANDOM: | ||
case ALBUM_LIST_NEWEST: | ||
case ALBUM_LIST_RECENT: | ||
case ALBUM_LIST_STARRED: | ||
localStorage.setItem('albumListType', type) | ||
return { ...previousState, list: type, params: albumListParams[type] } | ||
default: | ||
return previousState | ||
} | ||
} | ||
|
||
export { ALBUM_LIST_MODE, ALBUM_GRID_MODE, albumViewReducer, selectViewMode } | ||
export { | ||
ALBUM_MODE_LIST, | ||
ALBUM_MODE_GRID, | ||
ALBUM_LIST_ALL, | ||
ALBUM_LIST_RANDOM, | ||
ALBUM_LIST_NEWEST, | ||
ALBUM_LIST_RECENT, | ||
ALBUM_LIST_STARRED, | ||
albumViewReducer, | ||
selectViewMode, | ||
selectAlbumList | ||
} |