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 React, { Component } from "react";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { RemoteService } from "../../remote"; import { RemoteService } from "../../remote";
import { Grid } from "semantic-ui-react";
import Device from "./devices/Device";
import NewSceneDevice from "./NewSceneDevice";
class HostsPanel extends Component { class HostsPanel extends Component {
constructor(props) { constructor(props) {
@ -11,7 +14,7 @@ class HostsPanel extends Component {
return ( return (
<Grid doubling columns={2} divided="vertically"> <Grid doubling columns={2} divided="vertically">
{!this.props.isActiveDefaultHost {!this.props.isActiveDefaultHost
? this.props.hostDevices.map((e, i) => { ? Object.values(this.props.hostDevices).map((e, i) => {
return ( return (
<Grid.Column key={i}> <Grid.Column key={i}>
<Device tab={this.props.tab} id={e} /> <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. * Fetches all hosts of a particular user.
* 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
* @returns {Promise<Undefined, RemoteError>} promise that resolves to void and rejects * @returns {Promise<Undefined, RemoteError>} promise that resolves to void and rejects
* with user-fiendly errors as a RemoteError * with user-fiendly errors as a RemoteError
*/ */
@ -359,13 +356,31 @@ export const RemoteService = {
return Endpoint.get(`/user`) return Endpoint.get(`/user`)
.then((res) => void dispatch(actions.getHosts(res.data))) .then((res) => void dispatch(actions.getHosts(res.data)))
.catch((err) => { .catch((err) => {
// TODO CHANGE ERROR MESSAGE
console.error(`Fetch hosts error`, err); console.error(`Fetch hosts error`, err);
throw new RemoteError(["Network error"]); 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 * Creates/Updates a room with the given data
* @param {String} data.name the room's name, * @param {String} data.name the room's name,

View file

@ -495,6 +495,25 @@ function reducer(previousState, action) {
} }
newState = update(previousState, change); newState = update(previousState, change);
break; 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: default:
console.warn(`Action type ${action.type} unknown`, action); console.warn(`Action type ${action.type} unknown`, action);
return previousState; return previousState;

View file

@ -95,7 +95,28 @@ const actions = {
getHosts: (hosts) => ({ getHosts: (hosts) => ({
type: "GET_HOSTS", type: "GET_HOSTS",
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 = { export const appActions = {