added actions without working code

This commit is contained in:
Tommaso Rodolfo Masera 2020-04-25 17:46:52 +02:00 committed by Claudio Maggioni (maggicl)
parent 43615ba3b1
commit c5e1e1bd8d
4 changed files with 65 additions and 7 deletions

View file

@ -1,6 +1,9 @@
import React, { Component } from "react";
import { connect } from "react-redux";
import { RemoteService } from "../../remote";
import { Grid } from "semantic-ui-react";
import Device from "./devices/Device";
import NewSceneDevice from "./NewSceneDevice";
class HostsPanel extends Component {
constructor(props) {
@ -11,7 +14,7 @@ class HostsPanel extends Component {
return (
<Grid doubling columns={2} divided="vertically">
{!this.props.isActiveDefaultHost
? this.props.hostDevices.map((e, i) => {
? Object.values(this.props.hostDevices).map((e, i) => {
return (
<Grid.Column key={i}>
<Device tab={this.props.tab} id={e} />

View file

@ -347,10 +347,7 @@ export const RemoteService = {
},
/**
* Fetches all devices in a particular room, or fetches all devices.
* This also updates the devices attribute on values in the map rooms.
* @param {Number|null} roomId the room to which fetch devices
* from, null to fetch from all rooms
* Fetches all hosts of a particular user.
* @returns {Promise<Undefined, RemoteError>} promise that resolves to void and rejects
* with user-fiendly errors as a RemoteError
*/
@ -359,13 +356,31 @@ export const RemoteService = {
return Endpoint.get(`/user`)
.then((res) => void dispatch(actions.getHosts(res.data)))
.catch((err) => {
// TODO CHANGE ERROR MESSAGE
console.error(`Fetch hosts error`, err);
throw new RemoteError(["Network error"]);
});
};
},
/**
* Adds the current user as a guest to another user
* identified through a host id.
* @param {Number} hostId the host to add.
* @param {String} username the username of the guest to add.
* @returns {Promise<Undefined, RemoteError>} promise that resolves to void and rejects
* with user-fiendly errors as a RemoteError
*/
addUserAsGuest: (hostId, username) => {
return (dispatch) => {
return Endpoint.post(`/user/guest`)
.then((res) => void dispatch(actions.guestSave(res.data)))
.catch((err) => {
console.error(`Guest save error`, err);
throw new RemoteError(["Network Error"]);
});
};
},
/**
* Creates/Updates a room with the given data
* @param {String} data.name the room's name,

View file

@ -495,6 +495,25 @@ function reducer(previousState, action) {
}
newState = update(previousState, change);
break;
case "GET_HOST_DEVICES":
change = {};
// TODO ACTUAL WORKING CODE
break;
case "GUEST_SAVE":
change = {};
// TODO ACTUAL WORKING CODE
newState = update(previousState, change);
break;
case "GUEST_UPDATE":
change = {};
// TODO ACTUAL WORKING CODE
newState = update(previousState, change);
break;
case "GUEST_DELETE":
change = {};
// TODO ACTUAL WORKING CODE
newState = update(previousState, change);
break;
default:
console.warn(`Action type ${action.type} unknown`, action);
return previousState;

View file

@ -95,7 +95,28 @@ const actions = {
getHosts: (hosts) => ({
type: "GET_HOSTS",
hosts,
})
}),
getHostDevices: (host) => ({
type: "GET_HOST_DEVICES",
host,
}),
guestSave: (guest) => ({
type: "GUEST_SAVE",
guest,
}),
guestUpdate: (guest) => ({
type: "GUEST_UPDATE",
guest,
}),
guestDelete: (guest) => ({
type: "GUEST_DELETE",
guest,
}),
};
export const appActions = {