Skip to content

Commit

Permalink
Styled user info
Browse files Browse the repository at this point in the history
  • Loading branch information
MinhPhan8803 committed Nov 26, 2022
1 parent 21ee58d commit 12163e5
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 36 deletions.
5 changes: 3 additions & 2 deletions src/backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ def register():


@app.route("/user/<username>", methods=["GET", "POST"])
def userpage():
def userpage(username):
"""Handles userpage requests"""
session["username"] = "Zongxian"
if session.get("username", None) is None:
return "user does not exist", 404
username = session.get("username")
Expand All @@ -78,7 +79,7 @@ def userpage():
return result, 201
user = page.get_user(username) # request.method == "GET"
data_dict = dataclasses.asdict(user)
return json.dumps(data_dict), username, 201
return json.dumps(data_dict), 201


@app.route("/logout")
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Header from './components/Header';
import Login from './pages/Login';
import MainPage from './pages/MainPage';
import Register from './pages/Register';
// import UserPage from './pages/UserPage';
import User from './pages/User';

function App() {
return (
Expand All @@ -25,7 +25,7 @@ function App() {
<Route index element={<MainPage />} />
</Route>
<Route path="/user">
{/* <Route index element={<UserPage />} /> */}
<Route index element={<User />} />
</Route>
</Routes>
</BrowserRouter>
Expand Down
7 changes: 5 additions & 2 deletions src/frontend/src/components/user/getReviewedApts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ export default function getReviewedApts(username: string) {
const [apartments, setApartments] = useState(emptyarray);

useEffect(() => {
setLoading(true);
setError(false);
const CancelToken = axios.CancelToken;
const source = CancelToken.source();
const timer = setTimeout(() => {
const req = {
is_get_liked: true,
user_id: 1,
};
const json = JSON.stringify(req);
axios({
Expand All @@ -38,7 +41,7 @@ export default function getReviewedApts(username: string) {
price_max: res.data[i].price_max,
votes: res.data[i].votes,
});
};
}
}
return newApartments;
})
Expand All @@ -52,6 +55,6 @@ export default function getReviewedApts(username: string) {
clearTimeout(timer);
source.cancel();
};
});
}, [username]);
return {loading, error, apartments};
}
2 changes: 1 addition & 1 deletion src/frontend/src/components/user/getUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default function getInfo(username: string) {
clearTimeout(timer);
source.cancel();
};
});
}, [username]);
return {loading, error, user};
}

Expand Down
81 changes: 52 additions & 29 deletions src/frontend/src/pages/User.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import {
Divider,
Stack,
Button,
Link,
ListItemAvatar,
Avatar,
ListItem,
AvatarGroup
} from '@mui/material';
import EmailIcon from '@mui/icons-material/Email';
import PhoneIcon from '@mui/icons-material/Phone';
Expand All @@ -23,11 +28,17 @@ import getUser from '../components/user/getUser';


export default function User() {
const btnstyle = { marginLeft: '10px' };
return (
<>
<Grid container spacing={2}>
<Grid item xs={3}>
<Grid item xs={4}>
<FormUser/>
<Button variant="outlined" style={btnstyle}>
<Typography variant="subtitle2">
Change Password
</Typography>
</Button>
</Grid>

<Grid item xs={7}>
Expand All @@ -39,56 +50,68 @@ export default function User() {
}

function FormUser() {
const user_info = getUser("");
const user_info = getUser("Zongxian");
return (
<React.Fragment>
<List>
<ListItemButton>
<ListItemIcon>
<PersonIcon/>
</ListItemIcon>
<ListItemText primary={ user_info.user.username }/>
</ListItemButton>
<ListItem>
<ListItemAvatar>
<Avatar>
<PersonIcon/>
</Avatar>
</ListItemAvatar>
<ListItemText primary="Username" secondary={ user_info.user.username }/>
</ListItem>

<Divider />

<ListItemButton>
<ListItemText inset primary="Change password"/>
</ListItemButton>
<ListItem>
<ListItemAvatar>
<Avatar>
<EmailIcon/>
</Avatar>
</ListItemAvatar>
<ListItemText primary="Email" secondary={ user_info.user.email }/>
<Button color="primary" variant="outlined">
<Typography variant="subtitle2">
Change email
</Typography>
</Button>
</ListItem>

<Divider />

<ListItemButton>
<ListItemIcon>
<EmailIcon/>
</ListItemIcon>
<ListItemText primary={ user_info.user.email } secondary=""/>
</ListItemButton>

<Divider />

<ListItemButton>
<ListItemIcon>
<PhoneIcon/>
</ListItemIcon>
<ListItemText primary={ user_info.user.phone }/>
</ListItemButton>
<ListItem>
<ListItemAvatar>
<Avatar>
<EmailIcon/>
</Avatar>
</ListItemAvatar>
<ListItemText primary="Phone number" secondary={ user_info.user.phone }/>
<Button color="primary" variant="outlined">
<Typography variant="subtitle2">
Change phone
</Typography>
</Button>
</ListItem>
</List>
</React.Fragment>
);
}

function FormLikedApts() {
const reviewed_apts = getReviewedApts("");
console.log("Getting apt info")
const reviewed_apts = getReviewedApts("Zongxian");
return (
<React.Fragment>
<Box>
<Stack spacing={2}>
{reviewed_apts.apartments.map((apt, i) => {
return (
<Button variant="outlined">
<Button variant="outlined" key={i} onClick={() => {
console.log("Getting apt info")
}}>
{apt.name + " " + apt.address}
onClick = {}
</Button>
);
})}
Expand Down

3 comments on commit 12163e5

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
app.py1332780%55–82
config.py10100% 
decorators.py270100% 
dataholders
   apt.py90100% 
   mainpage_get.py150100% 
   review.py70100% 
   user.py80100% 
pages
   login.py290100% 
   mainpage.py1000100% 
   userpage.py540100% 
TOTAL3832793% 

Tests Skipped Failures Errors Time
48 0 💤 3 ❌ 0 🔥 0.925s ⏱️

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
app.py1332780%55–82
config.py10100% 
decorators.py270100% 
dataholders
   apt.py90100% 
   mainpage_get.py150100% 
   review.py70100% 
   user.py80100% 
pages
   login.py290100% 
   mainpage.py1000100% 
   userpage.py540100% 
TOTAL3832793% 

Tests Skipped Failures Errors Time
48 0 💤 3 ❌ 0 🔥 1.299s ⏱️

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
app.py1332780%55–82
config.py10100% 
decorators.py270100% 
dataholders
   apt.py90100% 
   mainpage_get.py150100% 
   review.py70100% 
   user.py80100% 
pages
   login.py290100% 
   mainpage.py1000100% 
   userpage.py540100% 
TOTAL3832793% 

Tests Skipped Failures Errors Time
48 0 💤 3 ❌ 0 🔥 1.282s ⏱️

Please sign in to comment.