Added: Device load support for Pushbullet

Co-Authored-By: Mark McDowall <markus101@users.noreply.github.com>
This commit is contained in:
Qstick 2018-09-04 22:41:22 -04:00
parent e41f884153
commit 23bc5b11cf
19 changed files with 439 additions and 27 deletions

View file

@ -0,0 +1,83 @@
import { createAction } from 'redux-actions';
import requestAction from 'Utilities/requestAction';
import updateSectionState from 'Utilities/State/updateSectionState';
import { createThunk, handleThunks } from 'Store/thunks';
import createHandleActions from './Creators/createHandleActions';
import { set } from './baseActions';
//
// Variables
export const section = 'devices';
//
// State
export const defaultState = {
items: [],
isFetching: false,
isPopulated: false,
error: false
};
//
// Actions Types
export const FETCH_DEVICES = 'devices/fetchDevices';
export const CLEAR_DEVICES = 'devices/clearDevices';
//
// Action Creators
export const fetchDevices = createThunk(FETCH_DEVICES);
export const clearDevices = createAction(CLEAR_DEVICES);
//
// Action Handlers
export const actionHandlers = handleThunks({
[FETCH_DEVICES]: function(getState, payload, dispatch) {
const actionPayload = {
action: 'getDevices',
...payload
};
dispatch(set({
section,
isFetching: true
}));
const promise = requestAction(actionPayload);
promise.done((data) => {
dispatch(set({
section,
isFetching: false,
isPopulated: true,
error: null,
items: data.devices || []
}));
});
promise.fail((xhr) => {
dispatch(set({
section,
isFetching: false,
isPopulated: false,
error: xhr
}));
});
}
});
//
// Reducers
export const reducers = createHandleActions({
[CLEAR_DEVICES]: function(state) {
return updateSectionState(state, section, defaultState);
}
}, defaultState, section);

View file

@ -2,6 +2,7 @@ import * as addArtist from './addArtistActions';
import * as app from './appActions';
import * as blacklist from './blacklistActions';
import * as captcha from './captchaActions';
import * as devices from './deviceActions';
import * as calendar from './calendarActions';
import * as commands from './commandActions';
import * as albums from './albumActions';
@ -34,6 +35,7 @@ export default [
captcha,
calendar,
commands,
devices,
albums,
trackFiles,
albumHistory,