2017-04-07 07:15:22 +02:00
|
|
|
import * as types from 'constants/action_types'
|
2017-04-29 11:50:29 +02:00
|
|
|
import lbry from 'lbry'
|
2017-04-07 07:15:22 +02:00
|
|
|
|
|
|
|
const reducers = {}
|
|
|
|
const defaultState = {
|
|
|
|
isLoaded: false,
|
2017-04-24 09:25:27 +02:00
|
|
|
currentPath: 'discover',
|
2017-04-07 07:15:22 +02:00
|
|
|
platform: process.platform,
|
2017-04-22 15:17:01 +02:00
|
|
|
upgradeSkipped: sessionStorage.getItem('upgradeSkipped'),
|
|
|
|
daemonReady: false,
|
2017-04-29 11:50:29 +02:00
|
|
|
obscureNsfw: !lbry.getClientSetting('showNsfw'),
|
|
|
|
hasSignature: false,
|
2017-04-07 07:15:22 +02:00
|
|
|
}
|
|
|
|
|
2017-05-02 05:57:50 +02:00
|
|
|
reducers[types.DAEMON_READY] = function(state, action) {
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
daemonReady: true,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-05-06 09:25:14 +02:00
|
|
|
reducers[types.CHANGE_PATH] = function(state, action) {
|
2017-04-07 07:15:22 +02:00
|
|
|
return Object.assign({}, state, {
|
2017-04-24 09:25:27 +02:00
|
|
|
currentPath: action.data.path,
|
2017-04-07 07:15:22 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
reducers[types.UPGRADE_CANCELLED] = function(state, action) {
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
downloadProgress: null,
|
2017-05-25 22:07:32 +02:00
|
|
|
upgradeDownloadComplete: false,
|
2017-04-07 07:15:22 +02:00
|
|
|
modal: null,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
reducers[types.UPGRADE_DOWNLOAD_COMPLETED] = function(state, action) {
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
downloadDir: action.data.dir,
|
2017-05-25 22:07:32 +02:00
|
|
|
upgradeDownloading: false,
|
|
|
|
upgradeDownloadCompleted: true
|
2017-04-07 07:15:22 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
reducers[types.UPGRADE_DOWNLOAD_STARTED] = function(state, action) {
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
upgradeDownloading: true
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
reducers[types.SKIP_UPGRADE] = function(state, action) {
|
|
|
|
sessionStorage.setItem('upgradeSkipped', true);
|
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
upgradeSkipped: true,
|
|
|
|
modal: null
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
reducers[types.UPDATE_VERSION] = function(state, action) {
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
version: action.data.version
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
reducers[types.OPEN_MODAL] = function(state, action) {
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
modal: action.data.modal,
|
2017-05-24 23:53:03 +02:00
|
|
|
modalExtraContent: action.data.extraContent
|
2017-04-07 07:15:22 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
reducers[types.CLOSE_MODAL] = function(state, action) {
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
modal: undefined,
|
2017-05-24 23:53:03 +02:00
|
|
|
modalExtraContent: undefined
|
2017-04-07 07:15:22 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
reducers[types.UPGRADE_DOWNLOAD_PROGRESSED] = function(state, action) {
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
downloadProgress: action.data.percent
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-04-22 15:17:01 +02:00
|
|
|
reducers[types.DAEMON_READY] = function(state, action) {
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
daemonReady: true
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-05-23 09:21:21 +02:00
|
|
|
reducers[types.SHOW_SNACKBAR] = function(state, action) {
|
|
|
|
const {
|
|
|
|
message,
|
|
|
|
linkText,
|
|
|
|
linkTarget,
|
|
|
|
isError,
|
|
|
|
} = action.data
|
|
|
|
const snackBar = Object.assign({}, state.snackBar)
|
|
|
|
const snacks = Object.assign([], snackBar.snacks)
|
|
|
|
snacks.push({
|
|
|
|
message,
|
|
|
|
linkText,
|
|
|
|
linkTarget,
|
|
|
|
isError,
|
|
|
|
})
|
|
|
|
const newSnackBar = Object.assign({}, snackBar, {
|
|
|
|
snacks,
|
|
|
|
})
|
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
snackBar: newSnackBar,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
reducers[types.REMOVE_SNACKBAR_SNACK] = function(state, action) {
|
|
|
|
const snackBar = Object.assign({}, state.snackBar)
|
|
|
|
const snacks = Object.assign([], snackBar.snacks)
|
|
|
|
snacks.shift()
|
|
|
|
|
|
|
|
const newSnackBar = Object.assign({}, snackBar, {
|
|
|
|
snacks,
|
|
|
|
})
|
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
snackBar: newSnackBar,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-04-07 07:15:22 +02:00
|
|
|
export default function reducer(state = defaultState, action) {
|
|
|
|
const handler = reducers[action.type];
|
|
|
|
if (handler) return handler(state, action);
|
|
|
|
return state;
|
|
|
|
}
|