Skip to content

Commit

Permalink
Merge pull request #19 from ramory-l/frontend
Browse files Browse the repository at this point in the history
Frontend
  • Loading branch information
s39f4lt authored Jan 6, 2021
2 parents d6e8b75 + cf81caf commit 1d2c61d
Show file tree
Hide file tree
Showing 52 changed files with 1,243 additions and 511 deletions.
181 changes: 21 additions & 160 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@
"query-string": "^6.13.7",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-id-swiper": "^4.0.0",
"react-router-dom": "^5.2.0",
"react-scripts": "3.4.3",
"react-tag-autocomplete": "^6.1.0",
"react-toastify": "^6.0.9",
"socket.io-client": "^3.0.4",
"swiper": "^6.3.5"
"react-tooltip": "^4.2.11"
},
"scripts": {
"start": "react-scripts start",
Expand Down
88 changes: 88 additions & 0 deletions frontend/src/components/blackListTable.jsx
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;
Loading

0 comments on commit 1d2c61d

Please sign in to comment.