-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from ramory-l/frontend
Frontend
- Loading branch information
Showing
52 changed files
with
1,243 additions
and
511 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import { Link } from "react-router-dom"; | ||
import Loading from "./common/loading"; | ||
import Table from "./common/table"; | ||
import { getUserBlacklist } from "../services/userService"; | ||
import _ from "lodash"; | ||
import moment from "moment"; | ||
|
||
const BlackListTable = (props) => { | ||
const [sortColumn, setSortColumn] = useState({ | ||
path: "username", | ||
order: "asc", | ||
}); | ||
const [blackList, setBlackList] = useState([]); | ||
|
||
useEffect(() => { | ||
async function fetchBlackList() { | ||
const { data: blackList } = await getUserBlacklist(); | ||
const modifiedBlackList = blackList.map((blockedUser) => { | ||
const newBlockedUser = { ...blockedUser }; | ||
const age = moment().diff(newBlockedUser.birthday, "years"); | ||
newBlockedUser.gender = newBlockedUser.gender | ||
? newBlockedUser.gender | ||
: "No gender"; | ||
newBlockedUser.birthday = isNaN(age) ? "No age" : age; | ||
return newBlockedUser; | ||
}); | ||
const sorted = _.orderBy( | ||
modifiedBlackList, | ||
[sortColumn.path], | ||
[sortColumn.order] | ||
); | ||
setBlackList(sorted); | ||
} | ||
fetchBlackList(); | ||
}, [sortColumn]); | ||
|
||
const columns = [ | ||
{ | ||
path: "avatar", | ||
label: "Avatar", | ||
content: (user) => ( | ||
<img | ||
alt={user.username} | ||
style={{ width: "5vw" }} | ||
src={`${ | ||
user.avatar?.link ? user.avatar.link : "/default-avatar.png" | ||
}`} | ||
/> | ||
), | ||
noSort: true, | ||
}, | ||
{ | ||
path: "username", | ||
label: "Username", | ||
content: (user) => { | ||
return ( | ||
<Link style={{ color: "black" }} to={`/profile/${user.username}`}> | ||
{user.username} | ||
</Link> | ||
); | ||
}, | ||
}, | ||
{ path: "gender", label: "Gender" }, | ||
{ path: "birthday", label: "Age" }, | ||
]; | ||
|
||
const handleSort = (sortColumn) => { | ||
setSortColumn(sortColumn); | ||
}; | ||
|
||
return blackList ? ( | ||
<Table | ||
columns={columns} | ||
data={blackList} | ||
onSort={handleSort} | ||
sortColumn={sortColumn} | ||
style={{ | ||
tableStyle: "table table-striped", | ||
tableHeaderStyle: "thead-dark", | ||
}} | ||
/> | ||
) : ( | ||
<Loading /> | ||
); | ||
}; | ||
|
||
export default BlackListTable; |
Oops, something went wrong.