diff --git a/src/components/Room.js b/src/components/Room.js
index 0d77da5..2e7ee24 100644
--- a/src/components/Room.js
+++ b/src/components/Room.js
@@ -1,16 +1,19 @@
import React, { PropTypes } from "react";
import { Link } from "react-router";
+import ImmutablePropTypes from "react-immutable-proptypes";
import md5 from "md5";
-const Room = ({ name, membership, userCount }) => {
+const Room = ({ name, data }) => {
+ const membership = data.get("membership");
+ const user_count = data.get("user_count");
+
const classes = ["room"];
if (membership == "Member") {
classes.push("room-joined");
}
- const hash = md5(name);
- const path = `/app/rooms/${hash}`;
+ const path = `/app/rooms/${md5(name)}`;
return (
{
className={classes.join(" ")}
>
{name}
- ({userCount})
+ ({user_count})
);
};
Room.propTypes = {
name: PropTypes.string.isRequired,
- membership: PropTypes.string.isRequired,
- userCount: PropTypes.number.isRequired
+ data: ImmutablePropTypes.map.isRequired
};
export default Room;
diff --git a/src/components/RoomList.js b/src/components/RoomList.js
index 5b6c17b..7b02dab 100644
--- a/src/components/RoomList.js
+++ b/src/components/RoomList.js
@@ -2,45 +2,17 @@ import React, { PropTypes } from "react";
import ImmutablePropTypes from "react-immutable-proptypes";
import Room from "./Room";
-import RoomListHeader from "./RoomListHeader";
+import SearchableList from "./SearchableList";
-class RoomList extends React.Component {
- constructor(props) {
- super(props);
- }
+const ComposedSearchableList = SearchableList(Room);
- componentDidMount() {
- const { rooms, roomActions } = this.props;
- if (rooms.shouldUpdate()) {
- roomActions.getList();
- }
- }
-
- render() {
- const { rooms, roomActions } = this.props;
-
- const children = [];
-
- for (const [roomName, roomData] of rooms.byName) {
- children.push(
-
-
-
- );
- }
-
- return (
-
- );
- }
-}
+const RoomList = ({ rooms, roomActions }) => (
+
+);
RoomList.propTypes = {
rooms: ImmutablePropTypes.record.isRequired,
diff --git a/src/components/SearchableList.js b/src/components/SearchableList.js
new file mode 100644
index 0000000..d7452fb
--- /dev/null
+++ b/src/components/SearchableList.js
@@ -0,0 +1,65 @@
+import React, { PropTypes } from "react";
+import ImmutablePropTypes from "react-immutable-proptypes";
+
+const SearchableList = (ItemComponent) => {
+ class ComposedSearchableList extends React.Component {
+ constructor(props) {
+ super(props);
+ }
+
+ componentDidMount() {
+ const { itemMap, refresh } = this.props;
+ if (itemMap.shouldUpdate()) {
+ refresh();
+ }
+ }
+
+
+ render() {
+ const { id, itemMap, refresh } = this.props;
+
+ const children = [];
+
+ for (const [itemName, itemData] of itemMap.byName) {
+ children.push(
+
+
+
+ );
+ }
+
+ const onClick = (event) => {
+ event.preventDefault();
+ refresh();
+ };
+
+ return (
+
+ );
+ }
+ }
+
+ ComposedSearchableList.propTypes = {
+ id: PropTypes.string.isRequired,
+ itemMap: ImmutablePropTypes.record.isRequired,
+ refresh: PropTypes.func.isRequired
+ };
+
+ return ComposedSearchableList;
+};
+
+export default SearchableList;
diff --git a/src/components/UserList.js b/src/components/UserList.js
index ca8068e..213f5c7 100644
--- a/src/components/UserList.js
+++ b/src/components/UserList.js
@@ -1,46 +1,18 @@
import React, { PropTypes } from "react";
import ImmutablePropTypes from "react-immutable-proptypes";
+import SearchableList from "./SearchableList";
import User from "./User";
-class UserList extends React.Component {
- constructor(props) {
- super(props);
- }
+const ComposedSearchableList = SearchableList(User);
- componentDidMount() {
- const { users, userActions } = this.props;
- if (users.shouldUpdate()) {
- userActions.getList();
- }
- }
-
- render() {
- const { users, userActions } = this.props;
- let children = [];
- for (const [ userName, userData ] of users.byName) {
- children.push(
-
-
-
- );
- }
-
- const onClick = (event) => {
- event.preventDefault();
- userActions.getList();
- };
-
- return (
-
- );
- }
-}
+const UserList = ({ users, userActions }) => (
+
+);
UserList.propTypes = {
users: ImmutablePropTypes.record.isRequired,