mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2025-12-16 18:28:47 +00:00
completed search page and redirect to user profile page
This commit is contained in:
parent
0aaa9014b9
commit
81749c19ce
@ -415,16 +415,15 @@ exports.unverifyUser = (req, res) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
exports.getUserHandles = (req, res) => {
|
exports.getUserHandles = (req, res) => {
|
||||||
admin
|
db.doc(`/users/${req.body.userHandle}`)
|
||||||
.firestore()
|
|
||||||
.collection("users")
|
|
||||||
.get()
|
.get()
|
||||||
.then(data => {
|
.then(doc => {
|
||||||
let users = [];
|
if (doc.exists) {
|
||||||
data.forEach(function(doc) {
|
let userHandle = doc.data().handle;
|
||||||
users.push(doc.data().handle);
|
return res.status(200).json(userHandle);
|
||||||
});
|
} else {
|
||||||
return res.status(200).json(users);
|
return res.status(404).json({ error: "user not found" });
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
|||||||
@ -56,7 +56,7 @@ app.post("/verifyUser", fbAuth, verifyUser);
|
|||||||
app.post("/unverifyUser", fbAuth, unverifyUser);
|
app.post("/unverifyUser", fbAuth, unverifyUser);
|
||||||
|
|
||||||
// get user handles with search phase
|
// get user handles with search phase
|
||||||
app.get("/getUserHandles", fbAuth, getUserHandles);
|
app.post("/getUserHandles", fbAuth, getUserHandles);
|
||||||
|
|
||||||
// get user's subscription
|
// get user's subscription
|
||||||
app.get("/getSubs", fbAuth, getSubs);
|
app.get("/getSubs", fbAuth, getSubs);
|
||||||
|
|||||||
@ -1,17 +1,17 @@
|
|||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from "react";
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from "react-router-dom";
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from "prop-types";
|
||||||
|
|
||||||
// Material UI stuff
|
// Material UI stuff
|
||||||
import AppBar from '@material-ui/core/AppBar';
|
import AppBar from "@material-ui/core/AppBar";
|
||||||
import ToolBar from '@material-ui/core/Toolbar';
|
import ToolBar from "@material-ui/core/Toolbar";
|
||||||
import Button from '@material-ui/core/Button';
|
import Button from "@material-ui/core/Button";
|
||||||
import withStyles from "@material-ui/core/styles/withStyles";
|
import withStyles from "@material-ui/core/styles/withStyles";
|
||||||
|
|
||||||
// Redux stuff
|
// Redux stuff
|
||||||
import { logoutUser } from '../../redux/actions/userActions';
|
import { logoutUser } from "../../redux/actions/userActions";
|
||||||
import { connect } from 'react-redux';
|
import { connect } from "react-redux";
|
||||||
|
|
||||||
const styles = {
|
const styles = {
|
||||||
form: {
|
form: {
|
||||||
@ -30,7 +30,7 @@ const styles = {
|
|||||||
progress: {
|
progress: {
|
||||||
position: "absolute"
|
position: "absolute"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export class Navbar extends Component {
|
export class Navbar extends Component {
|
||||||
render() {
|
render() {
|
||||||
@ -38,34 +38,47 @@ export class Navbar extends Component {
|
|||||||
return (
|
return (
|
||||||
<AppBar>
|
<AppBar>
|
||||||
<ToolBar>
|
<ToolBar>
|
||||||
<Button component={ Link } to='/'>
|
<Button component={Link} to="/">
|
||||||
Home
|
Home
|
||||||
</Button>
|
</Button>
|
||||||
{authenticated && <Button component={ Link } to='/user'>
|
{authenticated && (
|
||||||
|
<Button component={Link} to="/user">
|
||||||
Profile
|
Profile
|
||||||
</Button>}
|
</Button>
|
||||||
{!authenticated && <Button component={ Link } to='/login'>
|
)}
|
||||||
|
{!authenticated && (
|
||||||
|
<Button component={Link} to="/login">
|
||||||
Login
|
Login
|
||||||
</Button>}
|
</Button>
|
||||||
{!authenticated && <Button component={ Link } to='/signup'>
|
)}
|
||||||
|
{!authenticated && (
|
||||||
|
<Button component={Link} to="/signup">
|
||||||
Sign Up
|
Sign Up
|
||||||
</Button>}
|
</Button>
|
||||||
{authenticated && <Button component={ Link } to='/logout'>
|
)}
|
||||||
|
{authenticated && (
|
||||||
|
<Button component={Link} to="/search">
|
||||||
|
Search
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
{authenticated && (
|
||||||
|
<Button component={Link} to="/logout">
|
||||||
Logout
|
Logout
|
||||||
</Button>}
|
</Button>
|
||||||
|
)}
|
||||||
</ToolBar>
|
</ToolBar>
|
||||||
</AppBar>
|
</AppBar>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapStateToProps = (state) => ({
|
const mapStateToProps = state => ({
|
||||||
user: state.user
|
user: state.user
|
||||||
})
|
});
|
||||||
|
|
||||||
Navbar.propTypes = {
|
Navbar.propTypes = {
|
||||||
user: PropTypes.object.isRequired,
|
user: PropTypes.object.isRequired,
|
||||||
classes: PropTypes.object.isRequired
|
classes: PropTypes.object.isRequired
|
||||||
}
|
};
|
||||||
|
|
||||||
export default connect(mapStateToProps)(withStyles(styles)(Navbar));
|
export default connect(mapStateToProps)(withStyles(styles)(Navbar));
|
||||||
|
|||||||
@ -1,17 +1,10 @@
|
|||||||
import React, { Component } from "react";
|
import React, { Component } from "react";
|
||||||
// import props
|
// import props
|
||||||
import { TextField, Paper } from "@material-ui/core";
|
import { TextField, Button } from "@material-ui/core";
|
||||||
import Grid from "@material-ui/core/Grid";
|
import Grid from "@material-ui/core/Grid";
|
||||||
import Axios from "axios";
|
import Axios from "axios";
|
||||||
import user from "./user.js";
|
|
||||||
|
|
||||||
import {
|
import { BrowserRouter as Router } from "react-router-dom";
|
||||||
BrowserRouter as Router,
|
|
||||||
Switch,
|
|
||||||
Route,
|
|
||||||
Link,
|
|
||||||
useRouteMatch
|
|
||||||
} from "react-router-dom";
|
|
||||||
|
|
||||||
export class Search extends Component {
|
export class Search extends Component {
|
||||||
state = {
|
state = {
|
||||||
@ -19,20 +12,28 @@ export class Search extends Component {
|
|||||||
searchResult: null
|
searchResult: null
|
||||||
};
|
};
|
||||||
|
|
||||||
handleSearch(event) {
|
handleSearch = () => {
|
||||||
Axios.get("/getUserHandles").then(res => {
|
console.log(this.state.searchPhase);
|
||||||
|
Axios.post("/getUserHandles", {
|
||||||
|
userHandle: this.state.searchPhase
|
||||||
|
})
|
||||||
|
.then(res => {
|
||||||
|
console.log(res);
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
searchResult: res.data
|
searchResult: res.data
|
||||||
});
|
});
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err);
|
||||||
});
|
});
|
||||||
console.log(this.state.searchPhase);
|
};
|
||||||
}
|
|
||||||
|
|
||||||
handleInput(event) {
|
handleInput(event) {
|
||||||
this.setState({
|
this.setState({
|
||||||
searchPhase: event.target.value
|
searchPhase: event.target.value
|
||||||
});
|
});
|
||||||
this.handleSearch();
|
console.log(this.state.searchPhase);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleRedirect() {
|
handleRedirect() {
|
||||||
@ -41,16 +42,16 @@ export class Search extends Component {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
let resultMarkup = this.state.searchResult ? (
|
let resultMarkup = this.state.searchResult ? (
|
||||||
this.state.searchResult.map(result => (
|
|
||||||
<Router>
|
<Router>
|
||||||
<div>
|
<div>
|
||||||
<Link to={`/user`}>{result}</Link>
|
<a href={`/user/${this.state.searchResult}`}>
|
||||||
|
{this.state.searchResult}
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</Router>
|
</Router>
|
||||||
))
|
|
||||||
) : (
|
) : (
|
||||||
// console.log(this.state.searchResult)
|
// console.log(this.state.searchResult)
|
||||||
<p> searching... </p>
|
<p> No result </p>
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -65,6 +66,11 @@ export class Search extends Component {
|
|||||||
onChange={event => this.handleInput(event)}
|
onChange={event => this.handleInput(event)}
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
<Grid>
|
||||||
|
<Button color="primary" onClick={this.handleSearch}>
|
||||||
|
Search
|
||||||
|
</Button>
|
||||||
|
</Grid>
|
||||||
<Grid>{resultMarkup}</Grid>
|
<Grid>{resultMarkup}</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user