Skip to content

Commit

Permalink
Merge pull request #279 from nickbarry/furniture
Browse files Browse the repository at this point in the history
feat(frontend): Prevent users from ever seeing non-price placeholder
  • Loading branch information
Bpatalano authored Aug 20, 2016
2 parents 58979ca + 9533c61 commit 1501042
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
16 changes: 9 additions & 7 deletions src/furniture/actions/furniture.action.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ export function addFurniture(roomName, furnitureProps) {
let furnitureName = furnitureProps.itemName;
delete furnitureProps.itemName;

// If there is no price, create a placeholder field
if (!furnitureProps.price) {
furnitureProps.price = 'literally priceless';
}

//create new Obj to pass to database
let furnitureObj = {};
//only pass over defined variables to stop undefined from interrupting database call
Expand All @@ -32,8 +27,12 @@ export function addFurniture(roomName, furnitureProps) {
furnitureObj[prop] = furnitureProps[prop];
}
}
//database call
databaseAPI.updateFurniture(roomName, furnitureName, furnitureObj)

//database call; make sure price isn't falsy
const dbFurnitureObj = furnitureProps.price ?
furnitureObj :
Object.assign(_.cloneDeep(furnitureObj), { price: 'literally priceless' });
databaseAPI.updateFurniture(roomName, furnitureName, dbFurnitureObj);

//send the expected value to the reducer
return {
Expand Down Expand Up @@ -63,6 +62,9 @@ export function updateFurniture(originalFurnitureName, roomName, currentFurnitur
controlsClick(null, 'submit');
}

// If there is no price, create a placeholder field
newProps.price = newProps.price || 'literally priceless';

// Iterate through the new furniture properties, and merge them with the current
// furniture properties. The new object should not any undefined values. We also want to ignore the 'itemName'
// property, which shouldn't be stored as a property of the furniture.
Expand Down
2 changes: 1 addition & 1 deletion src/rooms/actions/rooms.action.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export function selectRoom(roomName) {
export const GET_ROOMS = 'GET_ROOMS';
export function getRooms() {
//database call with promise stored in rooms
let rooms = databaseAPI.getRooms();
const rooms = databaseAPI.getRooms();

return {
type: GET_ROOMS,
Expand Down
22 changes: 19 additions & 3 deletions src/rooms/reducers/rooms.reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,28 @@ const roomsReducer = (state = {}, action) => {
newState = _.cloneDeep(state);
newState[action.room].design = action.design;
return newState;

//handles initial pull from db
case GET_ROOMS:
let rooms = action.payload.val();
for (var roomName in rooms) {
if (roomName) {
const rooms = action.payload.val();
//const roomNames = Object.keys(rooms);
//roomNames.forEach(room => {
// const roomFurniture = rooms[room].furniture;
// const furnitureNames = Object.keys(roomFurniture);
//});

for (let roomName in rooms) {
if (rooms.hasOwnProperty(roomName)) {
let room = rooms[roomName];

// Replace any furniture with price of 'literally priceless' with undefined
for (let furnitureName in room.furniture) {
if (room.furniture[furnitureName].price === 'literally priceless') {
rooms[roomName].furniture[furnitureName].price = undefined;
}
}

// Set up the room's design object
let design = room.design;
let designArr = [];
for (var designObjName in design) {
Expand Down

0 comments on commit 1501042

Please sign in to comment.