slate/components/system/modules/FriendsList.js

239 lines
6.1 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 "~/components/system/svg";
import { css } from "@emotion/react";
import { Table } from "~/components/system/components/Table";
import { StatUpload, StatDownload } from "~/components/system/components/Stat";
let genericImg =
"https://hub.textile.io/ipfs/bafybeiblly23jomdjjiq7ilth667npcfm5llqb5xfstodbbfa5pxtoek7u";
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;
}
`;
const STYLES_ACCEPT_BUTTON = css`
${STYLES_BUTTON}
color: ${Constants.system.brand};
`;
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,
2020-08-01 06:44:16 +03:00
contentStyle: { padding: "0px" },
},
{
key: "reject",
width: "92px",
2020-08-02 21:53:26 +03:00
style: STYLES_CENTER_RIGHT,
2020-08-01 06:44:16 +03:00
contentStyle: { padding: "0px" },
},
],
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" }}
/>
</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" }}
/>
</div>
),
2020-08-02 21:53:26 +03:00
children: <ExpandSection friend={each.info} />,
2020-08-01 06:44:16 +03:00
};
}),
}}
/>
</React.Fragment>
);
}
}