Skip to content

Commit

Permalink
finished crude search bar
Browse files Browse the repository at this point in the history
  • Loading branch information
rchhong committed Jul 6, 2018
1 parent 0f026aa commit cc5e7ef
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 76 deletions.
66 changes: 66 additions & 0 deletions imports/ui/admin/List.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import React, {Component} from 'react';
import {createContainer} from 'meteor/react-meteor-data';
import Checkbox from 'material-ui/Checkbox';
import UserLink from '../UserLink.jsx';
import TextField from 'material-ui/TextField';

class UserItem extends Component {
handleConsistentCheck = () => {
var {user} = this.props;
var {_id} = user;
var {consistent} = user;
Meteor.call('users.setConsistent', _id, !consistent);
}

render() {
var {user} = this.props;
var {username} = user;
var consistent = user.consistent;

return (
<div style={{margin: '15px 0'}}>
<UserLink username={username} />
<Checkbox
label="Consistent"
checked={consistent}
onCheck={this.handleConsistentCheck} />
</div>

);
}
}
//TODO: place this component/userlink in a separate file, use sessions with search data, call createContainer
class List extends Component {
render()
{
if(!this.props.ready) {
return <div className="container">loading</div>
}

if(this.props.users.length === 0) {
return <div className="container">No tutors currently</div>
}

return (
<div className="container">
{this.props.users.map((user) => (
<UserItem key={user._id} user={user} />
))}
</div>
);
}
}

export default createContainer((props) => {
var query = {};
query.username = Session.get("Admin.query");
query.role = 1;

var subscription = Meteor.subscribe('users.all', query);
var users = Meteor.users.find(query).fetch();
return {
ready: subscription.ready(),
query: query,
users: users
};
}, List)
86 changes: 10 additions & 76 deletions imports/ui/admin/UsersList.jsx
Original file line number Diff line number Diff line change
@@ -1,89 +1,29 @@
import React, {Component} from 'react';
import {createContainer} from 'meteor/react-meteor-data';
import Checkbox from 'material-ui/Checkbox';
import UserLink from '../UserLink.jsx';
import TextField from 'material-ui/TextField';
import List from './List.jsx'

class UserItem extends Component {
handleConsistentCheck = () => {
var {user} = this.props;
var {_id} = user;
var {consistent} = user;
Meteor.call('users.setConsistent', _id, !consistent);
}

render() {
var {user} = this.props;
var {username} = user;
var consistent = user.consistent;

return (
<div style={{margin: '15px 0'}}>
<UserLink username={username} />
<Checkbox
label="Consistent"
checked={consistent}
onCheck={this.handleConsistentCheck} />
</div>

);
}
}
//TODO: place this component/userlink in a separate file, use sessions with search data, call createContainer
class List extends Component {
constructor(props)
{
super(props)
}
render()
{
return (
<div className="container">
{this.props.results.map((user) => (
<UserItem key={user._id} user={user} />
))}
</div>
);
}
}

class UserList extends Component {
export default class UsersList extends Component {
constructor(props)
{
super(props)
super(props);
this.state = {
text : '',
results : []
}
};
Session.set('Admin.query', this.state.text);
}

handleChange(e)
{
var query = e.target.value
this.state.text = query
if(this.state.text.length >= 2)
var query = e.target.value;
if(query.length >= 2)
{
this.findResults()
Session.set('Admin.query', query);
this.state.text = query;
}
}

findResults()
{
//console.log(this.props.users);
let result = Meteor.users.find({role: 1, username: this.state.text}).fetch()
this.state.results = result;
//console.log(result)
}

render() {
if(!this.props.ready) {
return <div className="container">loading</div>
}

if(this.props.users.length === 0) {
return <div className="container">No tutors currently</div>
}

return (
<div className="container">
<TextField
Expand All @@ -92,15 +32,9 @@ class UserList extends Component {
fullWidth={true}
onChange = {this.handleChange.bind(this)}/>
<div className="container">
<List results = {this.state.results}/>
<List />
</div>
</div>
);
}
}

export default createContainer((props) => {
var subscription = Meteor.subscribe('users.all');
var users = Meteor.users.find({role: 1}).fetch();
return {ready: subscription.ready(), users};
}, UserList)

0 comments on commit cc5e7ef

Please sign in to comment.