This repository has been archived by the owner on Oct 23, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: preget albums covers before rendering them (#192)
- Loading branch information
Showing
20 changed files
with
215 additions
and
110 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
14 changes: 14 additions & 0 deletions
14
src/renderer/sagas/startApp/startServices/startIPFSCachingService.js
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { fork } from 'redux-saga/effects' | ||
import startCachedIPFSFilesReciever from './startIPFSCachingService/startCachedIPFSFilesReciever' | ||
import startIPFSFilesCatch from './startIPFSCachingService/startIPFSFilesCatch' | ||
|
||
function * startIPFSCachingService (api) { | ||
try { | ||
yield fork(startCachedIPFSFilesReciever, api) | ||
yield fork(startIPFSFilesCatch, api) | ||
} catch (e) { | ||
console.error(e) | ||
} | ||
} | ||
|
||
export default startIPFSCachingService |
18 changes: 18 additions & 0 deletions
18
...erer/sagas/startApp/startServices/startIPFSCachingService/startCachedIPFSFilesReciever.js
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { call, put, take } from 'redux-saga/effects' | ||
import { systemIPFSFileCached } from '~actions/system' | ||
|
||
function * startCachedIPFSFilesReciever (api) { | ||
const { getCachedIPFSFilesChannel, openCachedIPFSFilesStream } = api | ||
yield call(openCachedIPFSFilesStream) | ||
const channel = yield call(getCachedIPFSFilesChannel) | ||
while (true) { | ||
const { errorMessage, payload } = yield take(channel) | ||
if (!errorMessage) { | ||
yield put(systemIPFSFileCached(payload)) | ||
} else { | ||
console.error(new Error(errorMessage)) | ||
} | ||
} | ||
} | ||
|
||
export default startCachedIPFSFilesReciever |
16 changes: 16 additions & 0 deletions
16
src/renderer/sagas/startApp/startServices/startIPFSCachingService/startIPFSFilesCatch.js
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { call, takeEvery } from 'redux-saga/effects' | ||
import { systemPlayedTracksRecieved, systemQueuedTracksRecieved, systemDiscoverAlbumsFetchSucceed } from '~actions/system' | ||
import cachePlaylistTracks from './startIPFSFilesCatch/cachePlaylistTracks' | ||
import cacheDiscoverAlbumsCovers from './startIPFSFilesCatch/cacheDiscoverAlbumsCovers' | ||
|
||
function * startIPFSFilesCatch (api) { | ||
yield call(cachePlaylistTracks, api) | ||
yield takeEvery( | ||
[ systemPlayedTracksRecieved, systemQueuedTracksRecieved ], cachePlaylistTracks, api | ||
) | ||
yield takeEvery( | ||
systemDiscoverAlbumsFetchSucceed, cacheDiscoverAlbumsCovers, api | ||
) | ||
} | ||
|
||
export default startIPFSFilesCatch |
19 changes: 19 additions & 0 deletions
19
...pp/startServices/startIPFSCachingService/startIPFSFilesCatch/cacheDiscoverAlbumsCovers.js
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { call } from 'redux-saga/effects' | ||
|
||
const handleMap = ({ albumCoverCid }) => albumCoverCid | ||
|
||
const getAlbumsCoversCIDs = (albums) => { | ||
return albums.map(handleMap) | ||
} | ||
|
||
function * cacheDiscoverAlbumsCovers (api, { payload }) { | ||
const { cacheIPFSFilesByCIDs } = api | ||
const uncachedCIDs = getAlbumsCoversCIDs(payload) | ||
try { | ||
yield call(cacheIPFSFilesByCIDs, uncachedCIDs) | ||
} catch (e) { | ||
console.error(e) | ||
} | ||
} | ||
|
||
export default cacheDiscoverAlbumsCovers |
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
22 changes: 0 additions & 22 deletions
22
src/renderer/sagas/startApp/startServices/startTracksCache/startCachedCIDsReciever.js
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { systemPlayedTracksRecieved, systemIPFSFileCached, systemQueuedTracksRecieved } from '~actions/system' | ||
import { uiPlaylistCleared } from '~actions/ui' | ||
|
||
const DOMAIN = 'localAudiosCIDs' | ||
|
||
const initialState = {} | ||
|
||
export const getLocalAudiosCIDs = state => state[DOMAIN] | ||
|
||
const handleReduceTracks = (acc, track) => { | ||
acc[track.audio] = false | ||
return acc | ||
} | ||
|
||
const reducer = (state = initialState, action) => { | ||
const { type, payload } = action | ||
switch (type) { | ||
case systemIPFSFileCached.toString(): | ||
if (state[payload] === false) { | ||
return { ...state, [payload]: true } | ||
} | ||
return state | ||
case systemPlayedTracksRecieved.toString(): | ||
return payload.reduce(handleReduceTracks, {}) | ||
case systemQueuedTracksRecieved.toString(): | ||
const newCids = payload.reduce(handleReduceTracks, {}) | ||
return { | ||
...newCids, | ||
...state | ||
} | ||
case uiPlaylistCleared.toString(): | ||
return {} | ||
default: | ||
return state | ||
} | ||
} | ||
|
||
export default reducer |
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { | ||
systemIPFSFileCached, systemDiscoverAlbumsFetchSucceed | ||
} from '~actions/system' | ||
import { | ||
uiDiscoverPageClosed | ||
} from '~actions/ui' | ||
|
||
const DOMAIN = 'localCoversCIDs' | ||
|
||
const initialState = {} | ||
|
||
export const getLocalCoversCIDs = state => state[DOMAIN] | ||
|
||
const handleReduce = (acc, album) => { | ||
acc[album.albumCoverCid] = false | ||
return acc | ||
} | ||
|
||
const reducer = (state = initialState, action) => { | ||
const { type, payload } = action | ||
switch (type) { | ||
case systemIPFSFileCached.toString(): | ||
if (state[payload] === false) { | ||
return { ...state, [payload]: true } | ||
} | ||
return state | ||
case systemDiscoverAlbumsFetchSucceed.toString(): | ||
return payload.reduce(handleReduce, {}) | ||
case uiDiscoverPageClosed.toString(): | ||
return {} | ||
default: | ||
return state | ||
} | ||
} | ||
|
||
export default reducer |
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
Oops, something went wrong.