slate/components/system/modules/FriendsList.js

237 lines
6.0 KiB
JavaScript
Raw Normal View History

2020-08-01 06:44:16 +03:00
import * as React from "react";
import * as Constants from "~/common/constants";
import * as Strings from "~/common/strings";
import * as SVG from "~/common/svg";
2020-08-01 06:44:16 +03:00
2020-11-30 08:24:22 +03:00
import { css } from "@emotion/react";
2020-08-01 06:44:16 +03:00
import { Table } from "~/components/system/components/Table";
import { StatUpload, StatDownload } from "~/components/system/components/Stat";
let genericImg = Strings.getURLfromCID(
"bafybeiblly23jomdjjiq7ilth667npcfm5llqb5xfstodbbfa5pxtoek7u"
);
2020-08-01 06:44:16 +03:00
const STYLES_BUTTON = `
font-family: ${Constants.font.text};
font-size: ${Constants.typescale.lvl1};
cursor: pointer;
background: none;
border: none;
outline: none;
padding: 8px;
:hover {
background-color: ${Constants.system.gray};
border-radius: 4px;
}
`;
2020-08-02 23:15:40 +03:00
const STYLES_HEADER = css`
2020-08-02 23:21:51 +03:00
font-size: ${Constants.typescale.lvl2};
2020-08-02 23:15:40 +03:00
margin-bottom: 8px;
`;
2020-08-01 06:44:16 +03:00
const STYLES_ACCEPT_BUTTON = css`
${STYLES_BUTTON}
2021-07-07 22:14:51 +03:00
color: ${Constants.system.blue};
2020-08-01 06:44:16 +03:00
`;
const STYLES_REJECT_BUTTON = css`
${STYLES_BUTTON}
color: ${Constants.system.black};
`;
2020-08-02 21:53:26 +03:00
const STYLES_CENTER_LEFT = {
2020-08-01 06:44:16 +03:00
display: "flex",
height: "100%",
alignItems: "center",
};
2020-08-02 21:53:26 +03:00
const STYLES_CENTER_RIGHT = {
2020-08-01 06:44:16 +03:00
display: "flex",
height: "100%",
alignItems: "center",
justifyContent: "flex-end",
};
2020-08-02 21:53:26 +03:00
const ExpandSection = ({ friend }) => {
return (
<div>
<div
style={{
display: "grid",
alignItems: "center",
gridTemplateColumns: "1fr 1fr",
}}
>
{friend.location ? (
<div>
<SVG.LocationPin
height="20px"
style={{
position: "relative",
top: "5px",
marginRight: "8px",
}}
/>
{friend.location}
</div>
) : null}
<div style={{ justifySelf: "end" }}>
<br />
<StatUpload size={friend.upload} style={{ marginRight: "16px" }} />
<StatDownload size={friend.download} />
</div>
</div>
<br />
<div>
<strong>Height</strong>: {friend.height}
</div>
<br />
<div style={{ wordBreak: "break-word" }}>
<strong>Chain Head</strong>: {friend.chainHead}
</div>
</div>
);
};
2020-08-01 06:44:16 +03:00
export class FriendsList extends React.Component {
state = {
selectedRowId: null,
};
_handleClick = (e) => {
this.setState({ selectedRowId: e.target.value });
};
render() {
return (
<React.Fragment>
2020-08-02 21:53:26 +03:00
<div css={STYLES_HEADER}>Requests</div>
2020-08-01 06:44:16 +03:00
<Table
noColor
noLabel
data={{
columns: [
{
key: "image",
width: "64px",
2020-08-02 21:53:26 +03:00
style: STYLES_CENTER_LEFT,
2020-08-01 06:44:16 +03:00
},
{
key: "user",
width: "100%",
2020-08-02 21:53:26 +03:00
style: STYLES_CENTER_LEFT,
2020-08-01 06:44:16 +03:00
},
{
key: "accept",
width: "92px",
2020-08-02 21:53:26 +03:00
style: STYLES_CENTER_RIGHT,
contentstyle: { padding: "0px" },
2020-08-01 06:44:16 +03:00
},
{
key: "reject",
width: "92px",
2020-08-02 21:53:26 +03:00
style: STYLES_CENTER_RIGHT,
contentstyle: { padding: "0px" },
2020-08-01 06:44:16 +03:00
},
],
rows: this.props.data.requests.map((each) => {
return {
id: each.user,
user: (
<a
2020-08-02 21:53:26 +03:00
href={`/${each.user}`}
2020-08-01 06:44:16 +03:00
target="_blank"
style={{
color: Constants.system.black,
fontSize: Constants.typescale.lvl1,
}}
>
{each.user}
</a>
),
image: (
<div
style={{
width: "40px",
height: "40px",
overflow: "hidden",
borderRadius: "4px",
}}
>
<img src={each.img || genericImg} alt="" style={{ width: "40px" }} />
2020-08-01 06:44:16 +03:00
</div>
),
accept: (
<button type="button" css={STYLES_ACCEPT_BUTTON}>
Accept
</button>
),
reject: (
<button type="button" css={STYLES_REJECT_BUTTON}>
Reject
</button>
),
};
}),
}}
/>
<br />
<br />
2020-08-02 21:53:26 +03:00
<div css={STYLES_HEADER}>Peers</div>
2020-08-01 06:44:16 +03:00
<Table
noColor
noLabel
selectedRowId={this.state.selectedRowId}
onClick={this._handleClick}
data={{
columns: [
{
key: "image",
width: "64px",
2020-08-02 21:53:26 +03:00
style: STYLES_CENTER_LEFT,
2020-08-01 06:44:16 +03:00
},
{
key: "user",
width: "100%",
2020-08-02 21:53:26 +03:00
style: STYLES_CENTER_LEFT,
2020-08-01 06:44:16 +03:00
},
],
rows: this.props.data.friends.map((each) => {
return {
id: each.user,
user: (
<a
href={"/" + each.user}
target="_blank"
style={{
color: Constants.system.black,
fontSize: Constants.typescale.lvl1,
}}
>
{each.user}
</a>
),
image: (
<div
style={{
width: "40px",
height: "40px",
overflow: "hidden",
borderRadius: "4px",
}}
>
<img src={each.img || genericImg} alt="" style={{ width: "40px" }} />
2020-08-01 06:44:16 +03:00
</div>
),
2020-08-02 21:53:26 +03:00
children: <ExpandSection friend={each.info} />,
2020-08-01 06:44:16 +03:00
};
}),
}}
/>
</React.Fragment>
);
}
}