From c5e1e1bd8d5a5498a684bcd075058f044c652a96 Mon Sep 17 00:00:00 2001 From: tommi27 Date: Sat, 25 Apr 2020 17:46:52 +0200 Subject: [PATCH] added actions without working code --- .../src/components/dashboard/HostsPanel.js | 5 +++- smart-hut/src/remote.js | 25 +++++++++++++++---- smart-hut/src/store.js | 19 ++++++++++++++ smart-hut/src/storeActions.js | 23 ++++++++++++++++- 4 files changed, 65 insertions(+), 7 deletions(-) diff --git a/smart-hut/src/components/dashboard/HostsPanel.js b/smart-hut/src/components/dashboard/HostsPanel.js index c019c10..5421fc9 100644 --- a/smart-hut/src/components/dashboard/HostsPanel.js +++ b/smart-hut/src/components/dashboard/HostsPanel.js @@ -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 ( {!this.props.isActiveDefaultHost - ? this.props.hostDevices.map((e, i) => { + ? Object.values(this.props.hostDevices).map((e, i) => { return ( diff --git a/smart-hut/src/remote.js b/smart-hut/src/remote.js index 8b508bc..42081d8 100644 --- a/smart-hut/src/remote.js +++ b/smart-hut/src/remote.js @@ -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} 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} 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, diff --git a/smart-hut/src/store.js b/smart-hut/src/store.js index d78bac8..62b34be 100644 --- a/smart-hut/src/store.js +++ b/smart-hut/src/store.js @@ -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; diff --git a/smart-hut/src/storeActions.js b/smart-hut/src/storeActions.js index 769ce8b..cf18ebb 100644 --- a/smart-hut/src/storeActions.js +++ b/smart-hut/src/storeActions.js @@ -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 = {