first commit
This commit is contained in:
21
lib/components/all/route.js
Normal file
21
lib/components/all/route.js
Normal file
@@ -0,0 +1,21 @@
|
||||
'use strict'
|
||||
|
||||
const all = (store, params, cb) => {
|
||||
let state = store.getState()
|
||||
cb({
|
||||
todos: state.todos,
|
||||
//shopping_list: state.shopping_list.items,
|
||||
//timeline: state.timeline.items,
|
||||
//network: state.network.network,
|
||||
//devices: state.devices.devices.devices,
|
||||
//household: state.household.household,
|
||||
//notifications: state.notifications.notifications.notifications,
|
||||
//user_data: state.user_data.userData.authentication,
|
||||
//wakewords: state.wakewords.wakewords,
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
'/': all,
|
||||
'/all': all,
|
||||
}
|
||||
5
lib/components/devices/action_constants.js
Normal file
5
lib/components/devices/action_constants.js
Normal file
@@ -0,0 +1,5 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = {
|
||||
RECEIVE_DEVICES: 'RECEIVE_DEVICES',
|
||||
}
|
||||
12
lib/components/devices/actions.js
Normal file
12
lib/components/devices/actions.js
Normal file
@@ -0,0 +1,12 @@
|
||||
'use strict'
|
||||
|
||||
const {RECEIVE_DEVICES} = require('./action_constants')
|
||||
|
||||
module.exports = {
|
||||
receivedDevices: devices => {
|
||||
return {
|
||||
type: RECEIVE_DEVICES,
|
||||
devices,
|
||||
}
|
||||
}
|
||||
}
|
||||
20
lib/components/devices/proxy.js
Normal file
20
lib/components/devices/proxy.js
Normal file
@@ -0,0 +1,20 @@
|
||||
'use strict'
|
||||
|
||||
const {receivedDevices} = require('./actions')
|
||||
|
||||
module.exports = {
|
||||
// urls that should be called for the remote actions
|
||||
urls: {
|
||||
fetch: 'https://layla.amazon.de/api/devices/device',
|
||||
},
|
||||
// called after an remote http call to the device API has been successfully executed
|
||||
postHooks: {
|
||||
// called after the devices data has been fetched
|
||||
fetch: (store, data) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
store.dispatch(receivedDevices(data))
|
||||
resolve(data)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
13
lib/components/devices/reducer.js
Normal file
13
lib/components/devices/reducer.js
Normal file
@@ -0,0 +1,13 @@
|
||||
'use strict'
|
||||
const {RECEIVE_DEVICES} = require('./action_constants')
|
||||
|
||||
module.exports = (state = {}, action) => {
|
||||
switch (action.type) {
|
||||
case RECEIVE_DEVICES:
|
||||
return Object.assign({}, state, {
|
||||
devices: action.devices
|
||||
})
|
||||
default:
|
||||
return state
|
||||
}
|
||||
}
|
||||
7
lib/components/devices/route.js
Normal file
7
lib/components/devices/route.js
Normal file
@@ -0,0 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = {
|
||||
'/devices': (store, params, cb) => {
|
||||
cb(store.getState().devices.devices.devices)
|
||||
}
|
||||
}
|
||||
5
lib/components/household/action_constants.js
Normal file
5
lib/components/household/action_constants.js
Normal file
@@ -0,0 +1,5 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = {
|
||||
RECEIVE_HOUSEHOLD: 'RECEIVE_HOUSEHOLD',
|
||||
}
|
||||
12
lib/components/household/actions.js
Normal file
12
lib/components/household/actions.js
Normal file
@@ -0,0 +1,12 @@
|
||||
'use strict'
|
||||
|
||||
const {RECEIVE_HOUSEHOLD} = require('./action_constants')
|
||||
|
||||
module.exports = {
|
||||
receivedHousehold: household => {
|
||||
return {
|
||||
type: RECEIVE_HOUSEHOLD,
|
||||
household,
|
||||
}
|
||||
}
|
||||
}
|
||||
20
lib/components/household/proxy.js
Normal file
20
lib/components/household/proxy.js
Normal file
@@ -0,0 +1,20 @@
|
||||
'use strict'
|
||||
|
||||
const {receivedHousehold} = require('./actions')
|
||||
|
||||
module.exports = {
|
||||
// urls that should be called for the remote actions
|
||||
urls: {
|
||||
fetch: 'https://layla.amazon.de/api/household',
|
||||
},
|
||||
// called after an remote http call to the household API has been successfully executed
|
||||
postHooks: {
|
||||
// called after the household items have been fetched
|
||||
fetch: (store, data) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
store.dispatch(receivedHousehold(data))
|
||||
resolve(data)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
13
lib/components/household/reducer.js
Normal file
13
lib/components/household/reducer.js
Normal file
@@ -0,0 +1,13 @@
|
||||
'use strict'
|
||||
const {RECEIVE_HOUSEHOLD} = require('./action_constants')
|
||||
|
||||
module.exports = (state = {}, action) => {
|
||||
switch (action.type) {
|
||||
case RECEIVE_HOUSEHOLD:
|
||||
return Object.assign({}, state, {
|
||||
household: action.household
|
||||
})
|
||||
default:
|
||||
return state
|
||||
}
|
||||
}
|
||||
7
lib/components/household/route.js
Normal file
7
lib/components/household/route.js
Normal file
@@ -0,0 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = {
|
||||
'/household': (store, params, cb) => {
|
||||
res.send(store.getState().household.household)
|
||||
}
|
||||
}
|
||||
5
lib/components/network/action_constants.js
Normal file
5
lib/components/network/action_constants.js
Normal file
@@ -0,0 +1,5 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = {
|
||||
RECEIVE_NETWORK: 'RECEIVE_NETWORK',
|
||||
}
|
||||
12
lib/components/network/actions.js
Normal file
12
lib/components/network/actions.js
Normal file
@@ -0,0 +1,12 @@
|
||||
'use strict'
|
||||
|
||||
const {RECEIVE_NETWORK} = require('./action_constants')
|
||||
|
||||
module.exports = {
|
||||
receivedNetwork: network => {
|
||||
return {
|
||||
type: RECEIVE_NETWORK,
|
||||
network,
|
||||
}
|
||||
}
|
||||
}
|
||||
21
lib/components/network/proxy.js
Normal file
21
lib/components/network/proxy.js
Normal file
@@ -0,0 +1,21 @@
|
||||
'use strict'
|
||||
|
||||
const {receivedNetwork} = require('./actions')
|
||||
|
||||
module.exports = {
|
||||
// urls that should be called for the remote actions
|
||||
urls: {
|
||||
fetch: 'https://layla.amazon.de/api/phoenix',
|
||||
discover: 'https://layla.amazon.de/api/phoenix/discovery',
|
||||
},
|
||||
// called after an remote http call to the network API has been successfully executed
|
||||
postHooks: {
|
||||
// called after the network data has been fetched
|
||||
fetch: (store, data) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
store.dispatch(receivedNetwork(JSON.parse(data.networkDetail)))
|
||||
resolve(data)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
13
lib/components/network/reducer.js
Normal file
13
lib/components/network/reducer.js
Normal file
@@ -0,0 +1,13 @@
|
||||
'use strict'
|
||||
const {RECEIVE_NETWORK} = require('./action_constants')
|
||||
|
||||
module.exports = (state = {}, action) => {
|
||||
switch (action.type) {
|
||||
case RECEIVE_NETWORK:
|
||||
return Object.assign({}, state, {
|
||||
network: action.network
|
||||
})
|
||||
default:
|
||||
return state
|
||||
}
|
||||
}
|
||||
7
lib/components/network/route.js
Normal file
7
lib/components/network/route.js
Normal file
@@ -0,0 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = {
|
||||
'/network': (store, params, cb) => {
|
||||
res.send(store.getState().network.network)
|
||||
}
|
||||
}
|
||||
5
lib/components/notifications/action_constants.js
Normal file
5
lib/components/notifications/action_constants.js
Normal file
@@ -0,0 +1,5 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = {
|
||||
RECEIVE_NOTIFICATIONS: 'RECEIVE_NOTIFICATIONS',
|
||||
}
|
||||
12
lib/components/notifications/actions.js
Normal file
12
lib/components/notifications/actions.js
Normal file
@@ -0,0 +1,12 @@
|
||||
'use strict'
|
||||
|
||||
const {RECEIVE_NOTIFICATIONS} = require('./action_constants')
|
||||
|
||||
module.exports = {
|
||||
receivedNotifications: notifications => {
|
||||
return {
|
||||
type: RECEIVE_NOTIFICATIONS,
|
||||
notifications,
|
||||
}
|
||||
}
|
||||
}
|
||||
20
lib/components/notifications/proxy.js
Normal file
20
lib/components/notifications/proxy.js
Normal file
@@ -0,0 +1,20 @@
|
||||
'use strict'
|
||||
|
||||
const {receivedNotifications} = require('./actions')
|
||||
|
||||
module.exports = {
|
||||
// urls that should be called for the remote actions
|
||||
urls: {
|
||||
fetch: 'https://layla.amazon.de/api/notifications',
|
||||
},
|
||||
// called after an remote http call to the notifications API has been successfully executed
|
||||
postHooks: {
|
||||
// called after the notifications have been fetched
|
||||
fetch:(store, data) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
store.dispatch(receivedNotifications(data))
|
||||
resolve(data)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
13
lib/components/notifications/reducer.js
Normal file
13
lib/components/notifications/reducer.js
Normal file
@@ -0,0 +1,13 @@
|
||||
'use strict'
|
||||
const {RECEIVE_NOTIFICATIONS} = require('./action_constants')
|
||||
|
||||
module.exports = (state = {}, action) => {
|
||||
switch (action.type) {
|
||||
case RECEIVE_NOTIFICATIONS:
|
||||
return Object.assign({}, state, {
|
||||
notifications: action.notifications
|
||||
})
|
||||
default:
|
||||
return state
|
||||
}
|
||||
}
|
||||
7
lib/components/notifications/route.js
Normal file
7
lib/components/notifications/route.js
Normal file
@@ -0,0 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = {
|
||||
'/notifications': (store, params, cb) => {
|
||||
cb(store.getState().notifications.notifications.notifications)
|
||||
}
|
||||
}
|
||||
5
lib/components/shopping_list/action_constants.js
Normal file
5
lib/components/shopping_list/action_constants.js
Normal file
@@ -0,0 +1,5 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = {
|
||||
RECEIVE_SHOPPING_LIST: 'RECEIVE_SHOPPING_LIST',
|
||||
}
|
||||
12
lib/components/shopping_list/actions.js
Normal file
12
lib/components/shopping_list/actions.js
Normal file
@@ -0,0 +1,12 @@
|
||||
'use strict'
|
||||
|
||||
const {RECEIVE_SHOPPING_LIST} = require('./action_constants')
|
||||
|
||||
module.exports = {
|
||||
receivedShoppingList: todos => {
|
||||
return {
|
||||
type: RECEIVE_SHOPPING_LIST,
|
||||
items: todos,
|
||||
}
|
||||
}
|
||||
}
|
||||
20
lib/components/shopping_list/proxy.js
Normal file
20
lib/components/shopping_list/proxy.js
Normal file
@@ -0,0 +1,20 @@
|
||||
'use strict'
|
||||
|
||||
const {receivedShoppingList} = require('./actions')
|
||||
|
||||
module.exports = {
|
||||
// urls that should be called for the remote actions
|
||||
urls: {
|
||||
fetch: 'https://layla.amazon.de/api/todos?type=SHOPPING_ITEM&size=100',
|
||||
},
|
||||
// called after an remote http call to the shopping_list API has been successfully executed
|
||||
postHooks: {
|
||||
// called after the shopping items have been fetched
|
||||
fetch:(store, data) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
store.dispatch(receivedShoppingList(data.values))
|
||||
resolve(data)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
13
lib/components/shopping_list/reducer.js
Normal file
13
lib/components/shopping_list/reducer.js
Normal file
@@ -0,0 +1,13 @@
|
||||
'use strict'
|
||||
const {RECEIVE_SHOPPING_LIST} = require('./action_constants')
|
||||
|
||||
module.exports = (state = {}, action) => {
|
||||
switch (action.type) {
|
||||
case RECEIVE_SHOPPING_LIST:
|
||||
return Object.assign({}, state, {
|
||||
items: action.items
|
||||
})
|
||||
default:
|
||||
return state
|
||||
}
|
||||
}
|
||||
7
lib/components/shopping_list/route.js
Normal file
7
lib/components/shopping_list/route.js
Normal file
@@ -0,0 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = {
|
||||
'/shopping_list': (store, params, cb) => {
|
||||
cb(store.getState().shopping_list.items)
|
||||
}
|
||||
}
|
||||
5
lib/components/timeline/action_constants.js
Normal file
5
lib/components/timeline/action_constants.js
Normal file
@@ -0,0 +1,5 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = {
|
||||
RECEIVE_TIMELINE: 'RECEIVE_TIMELINE',
|
||||
}
|
||||
12
lib/components/timeline/actions.js
Normal file
12
lib/components/timeline/actions.js
Normal file
@@ -0,0 +1,12 @@
|
||||
'use strict'
|
||||
|
||||
const {RECEIVE_TIMELINE} = require('./action_constants')
|
||||
|
||||
module.exports = {
|
||||
receivedTimeline: timeline => {
|
||||
return {
|
||||
type: RECEIVE_TIMELINE,
|
||||
items: timeline,
|
||||
}
|
||||
}
|
||||
}
|
||||
19
lib/components/timeline/proxy.js
Normal file
19
lib/components/timeline/proxy.js
Normal file
@@ -0,0 +1,19 @@
|
||||
'use strict'
|
||||
|
||||
const {receivedTimeline} = require('./actions')
|
||||
|
||||
module.exports = {
|
||||
// urls that should be called for the remote actions
|
||||
urls: {
|
||||
fetch: 'https://layla.amazon.de/api/cards?limit=50',
|
||||
},
|
||||
postHooks: {
|
||||
// called after the timeline has been fetched
|
||||
fetch: (store, data) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
store.dispatch(receivedTimeline(data.cards))
|
||||
resolve(data)
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
13
lib/components/timeline/reducer.js
Normal file
13
lib/components/timeline/reducer.js
Normal file
@@ -0,0 +1,13 @@
|
||||
'use strict'
|
||||
const {RECEIVE_TIMELINE} = require('./action_constants')
|
||||
|
||||
module.exports = (state = {}, action) => {
|
||||
switch (action.type) {
|
||||
case RECEIVE_TIMELINE:
|
||||
return Object.assign({}, state, {
|
||||
items: action.items
|
||||
})
|
||||
default:
|
||||
return state
|
||||
}
|
||||
}
|
||||
7
lib/components/timeline/route.js
Normal file
7
lib/components/timeline/route.js
Normal file
@@ -0,0 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = {
|
||||
'/timeline': (store, params, cb) => {
|
||||
cb(store.getState().timeline.items)
|
||||
}
|
||||
}
|
||||
19
lib/components/todo/action_constants.js
Normal file
19
lib/components/todo/action_constants.js
Normal file
@@ -0,0 +1,19 @@
|
||||
'use strict'
|
||||
|
||||
const RECEIVE_TODOS = 'RECEIVE_TODOS'
|
||||
const FETCH_TODOS = 'FETCH_TODOS'
|
||||
const ADD_TODO = 'ADD_TODO'
|
||||
const ADDED_TODO = 'ADDED_TODO'
|
||||
const UPDATE_TODO = 'UPDATE_TODO'
|
||||
const DELETE_TODO = 'DELETE_TODO'
|
||||
const COMPLETE_TODO = 'COMPLETE_TODO'
|
||||
|
||||
module.exports = {
|
||||
RECEIVE_TODOS,
|
||||
FETCH_TODOS,
|
||||
ADD_TODO,
|
||||
ADDED_TODO,
|
||||
UPDATE_TODO,
|
||||
DELETE_TODO,
|
||||
COMPLETE_TODO,
|
||||
}
|
||||
61
lib/components/todo/actions.js
Normal file
61
lib/components/todo/actions.js
Normal file
@@ -0,0 +1,61 @@
|
||||
'use strict'
|
||||
|
||||
const {FETCH_TODOS, RECEIVED_TODOS, ADD_TODO, ADDED_TODO, UPDATE_TODO, DELETE_TODO, COMPLETE_TODO} = require('./action_constants')
|
||||
|
||||
const fetchTodos = todos => {
|
||||
return {
|
||||
type: FETCH_TODOS,
|
||||
items: todos,
|
||||
}
|
||||
}
|
||||
|
||||
const receivedTodos = todos => {
|
||||
return {
|
||||
type: RECEIVED_TODOS,
|
||||
items: todos,
|
||||
}
|
||||
}
|
||||
|
||||
const addTodo = todo => {
|
||||
return {
|
||||
type: ADD_TODO,
|
||||
item: todo,
|
||||
}
|
||||
}
|
||||
|
||||
const addedTodo = todo => {
|
||||
return {
|
||||
type: ADDED_TODO,
|
||||
item: todo,
|
||||
}
|
||||
}
|
||||
|
||||
const updateTodo = todo => {
|
||||
return {
|
||||
type: UPDATE_TODO,
|
||||
item: todo,
|
||||
}
|
||||
}
|
||||
|
||||
const deleteTodo = todo => {
|
||||
return {
|
||||
type: DELETE_TODO,
|
||||
item: todo,
|
||||
}
|
||||
}
|
||||
|
||||
const completeTodo = todo => {
|
||||
return {
|
||||
type: COMPLETE_TODO,
|
||||
item: todo,
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
receivedTodos,
|
||||
addTodo,
|
||||
addedTodo,
|
||||
updateTodo,
|
||||
deleteTodo,
|
||||
completeTodo,
|
||||
}
|
||||
61
lib/components/todo/proxy.js
Normal file
61
lib/components/todo/proxy.js
Normal file
@@ -0,0 +1,61 @@
|
||||
'use strict'
|
||||
|
||||
const {receivedTodos, addTodo, addedTodo} = require('./actions')
|
||||
|
||||
module.exports = {
|
||||
// urls that should be called for the remote actions
|
||||
urls: {
|
||||
fetch: 'https://layla.amazon.de/api/todos?type=TASK&size=100',
|
||||
add: 'https://layla.amazon.de/api/todos',
|
||||
complete: 'https://layla.amazon.de/api/todos/{ID}',
|
||||
delete: 'https://layla.amazon.de/api/todos/{ID}',
|
||||
update: 'https://layla.amazon.de/api/todos/{ID}',
|
||||
},
|
||||
// called before an remote http call to the todos API gets executed
|
||||
preHooks: {
|
||||
fetch: async options => [{method: 'GET', url: options.url}],
|
||||
// adds a new TODO
|
||||
add: async options => {
|
||||
let todoTemplate = {
|
||||
text: options.text,
|
||||
type: 'TASK',
|
||||
itemId: null,
|
||||
lastLocalUpdatedDate: null,
|
||||
lastUpdatedDate: null,
|
||||
createdDate: Date.now(),
|
||||
utteranceId: null,
|
||||
nbestItems: null,
|
||||
complete: false,
|
||||
version: null,
|
||||
deleted: false,
|
||||
reminderTime: null
|
||||
}
|
||||
// dispatch data about the item to be added
|
||||
store.dispatch(addTodo(todoTemplate))
|
||||
// build request options
|
||||
// TODO: Add error handling
|
||||
return [{method: 'POST', url: options.url, body: JSON.stringify(todoTemplate)}]
|
||||
}
|
||||
},
|
||||
// called after an remote http call to the todos API has been successfully executed
|
||||
postHooks: {
|
||||
// called after the todo list has been fetched
|
||||
fetch: async (store, raw_data) => {
|
||||
let data = []
|
||||
try {
|
||||
data = JSON.parse(raw_data)
|
||||
store.dispatch(receivedTodos(data.values))
|
||||
} catch (error) {
|
||||
// TODO: Add error handling
|
||||
}
|
||||
return data
|
||||
},
|
||||
// called after the new todo has been created
|
||||
add: async (store, raw_data) => {
|
||||
// TODO: Add error handling
|
||||
const data = JSON.parse(raw_data)
|
||||
store.dispatch(addedTodo(data))
|
||||
return data
|
||||
}
|
||||
}
|
||||
}
|
||||
42
lib/components/todo/reducer.js
Normal file
42
lib/components/todo/reducer.js
Normal file
@@ -0,0 +1,42 @@
|
||||
'use strict'
|
||||
const {RECEIVE_TODOS, RECEIVED_TODOS, ADD_TODO, ADDED_TODO} = require('./action_constants')
|
||||
const INITIAL_STATE = {toBeAdded: [], items: [], size: 0, lastUpdated: null, fetching: false, error: null}
|
||||
|
||||
// create an array of todos that are still queued, but not yet added
|
||||
const removeToBeAdded = (current, itemToBeRemoved) => {
|
||||
if (current.length === 1) return []
|
||||
return current.map(item => {
|
||||
if (item.text !== itemToBeRemoved.text) return item
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = (state = INITIAL_STATE, action) => {
|
||||
switch (action.type) {
|
||||
// received all todos
|
||||
case RECEIVED_TODOS:
|
||||
return Object.assign({}, state, {
|
||||
items: action.items,
|
||||
size: action.items.length,
|
||||
lastUpdated: Date.now(),
|
||||
})
|
||||
// trying to add a todo (request to amazon not yet made)
|
||||
case ADD_TODO:
|
||||
return Object.assign({}, state, {
|
||||
toBeAdded: state.toBeAdded.push(action.item),
|
||||
lastUpdated: Date.now(),
|
||||
})
|
||||
// todo has been added successfully
|
||||
case ADDED_TODO:
|
||||
// remove the item from the toBeadded array
|
||||
const toBeAdded = removeToBeAdded(state.toBeAdded, action.item)
|
||||
state.items.push(action.item)
|
||||
return Object.assign({}, state, {
|
||||
items: state.items,
|
||||
size: state.size + 1,
|
||||
toBeAdded: toBeAdded,
|
||||
lastUpdated: Date.now(),
|
||||
})
|
||||
default:
|
||||
return state
|
||||
}
|
||||
}
|
||||
31
lib/components/todo/route.js
Normal file
31
lib/components/todo/route.js
Normal file
@@ -0,0 +1,31 @@
|
||||
'use strict'
|
||||
|
||||
const {receivedTodos, addTodo} = require('./actions')
|
||||
|
||||
module.exports = {
|
||||
// returns all todos
|
||||
'/todos': (store, params, cb) => cb(store.getState().todos),
|
||||
// adds a todo & returns all todos
|
||||
'/todos/add': (store, params, cb, Proxy) => Proxy.act('todo', 'add', params, result => {
|
||||
console.log('result', result)
|
||||
cb(result)
|
||||
}),
|
||||
// deletes a todo & returns all todos
|
||||
'/todos/delete': (store, params, cb, Proxy) => Proxy.act('todo', 'delete', params, async result => {
|
||||
const data = await Proxy.fetch('todo')
|
||||
store.dispatch(receivedTodos(data.todo.values))
|
||||
cb(data.todo.values)
|
||||
}),
|
||||
// completes a todo & returns all todos
|
||||
'/todos/complete': (store, params, cb, Proxy) => Proxy.act('todo', 'complete', params, async result => {
|
||||
const data = await Proxy.fetch('todo')
|
||||
store.dispatch(receivedTodos(data.todo.values))
|
||||
cb(data.todo.values)
|
||||
}),
|
||||
// updates a todo & returns all todos
|
||||
'/todos/update': (store, params, cb, Proxy) => Proxy.act('todo', 'update', params, async result => {
|
||||
const data = await Proxy.fetch('todo')
|
||||
store.dispatch(receivedTodos(data.todo.values))
|
||||
cb(data.todo.values)
|
||||
}),
|
||||
}
|
||||
5
lib/components/user_data/action_constants.js
Normal file
5
lib/components/user_data/action_constants.js
Normal file
@@ -0,0 +1,5 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = {
|
||||
RECEIVE_USER_DATA: 'RECEIVE_USER_DATA',
|
||||
}
|
||||
12
lib/components/user_data/actions.js
Normal file
12
lib/components/user_data/actions.js
Normal file
@@ -0,0 +1,12 @@
|
||||
'use strict'
|
||||
|
||||
const {RECEIVE_USER_DATA} = require('./action_constants')
|
||||
|
||||
module.exports = {
|
||||
receivedUserData: userData => {
|
||||
return {
|
||||
type: RECEIVE_USER_DATA,
|
||||
userData,
|
||||
}
|
||||
}
|
||||
}
|
||||
20
lib/components/user_data/proxy.js
Normal file
20
lib/components/user_data/proxy.js
Normal file
@@ -0,0 +1,20 @@
|
||||
'use strict'
|
||||
|
||||
const {receivedUserData} = require('./actions')
|
||||
|
||||
module.exports = {
|
||||
// urls that should be called for the remote actions
|
||||
urls: {
|
||||
fetch: 'https://layla.amazon.de/api/bootstrap?version=1.24.2445.0',
|
||||
},
|
||||
// called after an remote http call to the user data API has been successfully executed
|
||||
postHooks: {
|
||||
// called after the user data has been fetched
|
||||
fetch: (store, data) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
store.dispatch(receivedUserData(data))
|
||||
resolve(data)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
13
lib/components/user_data/reducer.js
Normal file
13
lib/components/user_data/reducer.js
Normal file
@@ -0,0 +1,13 @@
|
||||
'use strict'
|
||||
const {RECEIVE_USER_DATA} = require('./action_constants')
|
||||
|
||||
module.exports = (state = {}, action) => {
|
||||
switch (action.type) {
|
||||
case RECEIVE_USER_DATA:
|
||||
return Object.assign({}, state, {
|
||||
userData: action.userData
|
||||
})
|
||||
default:
|
||||
return state
|
||||
}
|
||||
}
|
||||
7
lib/components/user_data/route.js
Normal file
7
lib/components/user_data/route.js
Normal file
@@ -0,0 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = {
|
||||
'/user_data': (store, params, cb) => {
|
||||
cb(store.getState().user_data.userData)
|
||||
}
|
||||
}
|
||||
5
lib/components/wakewords/action_constants.js
Normal file
5
lib/components/wakewords/action_constants.js
Normal file
@@ -0,0 +1,5 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = {
|
||||
RECEIVE_WAKEWORDS: 'RECEIVE_WAKEWORDS',
|
||||
}
|
||||
12
lib/components/wakewords/actions.js
Normal file
12
lib/components/wakewords/actions.js
Normal file
@@ -0,0 +1,12 @@
|
||||
'use strict'
|
||||
|
||||
const {RECEIVE_WAKEWORDS} = require('./action_constants')
|
||||
|
||||
module.exports = {
|
||||
receivedWakewords: wakewords => {
|
||||
return {
|
||||
type: RECEIVE_WAKEWORDS,
|
||||
wakewords,
|
||||
}
|
||||
}
|
||||
}
|
||||
20
lib/components/wakewords/proxy.js
Normal file
20
lib/components/wakewords/proxy.js
Normal file
@@ -0,0 +1,20 @@
|
||||
'use strict'
|
||||
|
||||
const {receivedWakewords} = require('./actions')
|
||||
|
||||
module.exports = {
|
||||
// urls that should be called for the remote actions
|
||||
urls: {
|
||||
fetch: 'https://layla.amazon.de/api/wake-word',
|
||||
},
|
||||
// called after an remote http call to the user data API has been successfully executed
|
||||
postHooks: {
|
||||
// called after the user data has been fetched
|
||||
fetch: (store, data) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
store.dispatch(receivedWakewords(data.wakeWords))
|
||||
resolve(data)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
13
lib/components/wakewords/reducer.js
Normal file
13
lib/components/wakewords/reducer.js
Normal file
@@ -0,0 +1,13 @@
|
||||
'use strict'
|
||||
const {RECEIVE_WAKEWORDS} = require('./action_constants')
|
||||
|
||||
module.exports = (state = {}, action) => {
|
||||
switch (action.type) {
|
||||
case RECEIVE_WAKEWORDS:
|
||||
return Object.assign({}, state, {
|
||||
wakewords: action.wakewords
|
||||
})
|
||||
default:
|
||||
return state
|
||||
}
|
||||
}
|
||||
7
lib/components/wakewords/route.js
Normal file
7
lib/components/wakewords/route.js
Normal file
@@ -0,0 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = {
|
||||
'/wakewords': (store, params, cb) => {
|
||||
cb(store.getState().wakewords.wakewords)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user