Skip to content

Instantly share code, notes, and snippets.

@jaygraygray
Created April 25, 2017 22:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaygraygray/f1cac6024cb8f9a470f8d7295e3d17cb to your computer and use it in GitHub Desktop.
Save jaygraygray/f1cac6024cb8f9a470f8d7295e3d17cb to your computer and use it in GitHub Desktop.
Template for a single room inside an apartment
import React, { Component } from 'react';
import Bed from './Bed';
import "../../styles/dndbed.scss";
import { removeStudentFromApt } from '../../actions/action_student'
import { connect } from "react-redux"
class Room extends Component {
render() {
let listBeds = []
const props = this.props
//
// For every student ...
//
for (var i = 0; i < this.props.all_student_info.length; i++) {
(function(i, props) {
//
// Find which ones live in a
//
if (props.all_student_info[i].room_id == props.room_id) {
let studentObj = {
student_id : props.all_student_info[i].id,
room_id : props.room_id
}
//
// Populate each bed that's occupied with correct student info.
// Include the icon and dispatch to remove each student
//
listBeds.push(
<div className="bed-holder">
<img src={require("../../styles/icons/error.svg")}
className="remove-icon"
onClick= { () => props.dispatch(removeStudentFromApt(studentObj)) }/>
<Bed key={i}
allowedDropEffect='move'
roomID={props.room_id}
studentID={props}>
{props.all_student_info[i].first_name}
</Bed>
</div>
)}})(i, props)
}
//
// For the remaining, empty beds,
// Display an empty room ready to accept an occupant
//
for (var i = listBeds.length; i < this.props.number_of_beds; i++) {
listBeds.push(<Bed key={i}
allowedDropEffect='move'
roomID={this.props.room_id}
studentID={this.props}>
Empty
</Bed>)}
return (
<div className="dnd-room">
Room
{listBeds}
</div>
);
}
}
export default connect()(Room);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment