slate/scenes/SceneDirectory.js

537 lines
16 KiB
JavaScript
Raw Normal View History

import * as React from "react";
import * as Actions from "~/common/actions";
import * as Constants from "~/common/constants";
import * as SVG from "~/common/svg";
2020-11-30 08:24:22 +03:00
import { css } from "@emotion/react";
2020-12-18 00:49:39 +03:00
import { SecondaryTabGroup } from "~/components/core/TabGroup";
2020-09-06 02:41:12 +03:00
import { Boundary } from "~/components/system/components/fragments/Boundary";
import { PopoverNavigation } from "~/components/system/components/PopoverNavigation";
2020-10-26 00:11:27 +03:00
import { ButtonPrimary, ButtonSecondary } from "~/components/system/components/Buttons";
import ScenePage from "~/components/core/ScenePage";
import ScenePageHeader from "~/components/core/ScenePageHeader";
import EmptyState from "~/components/core/EmptyState";
const STYLES_USER_ENTRY = css`
display: grid;
2020-09-06 00:36:20 +03:00
grid-template-columns: auto 1fr;
align-items: center;
font-size: ${Constants.typescale.lvl1};
cursor: pointer;
2020-12-11 05:59:17 +03:00
${"" /* border: 1px solid ${Constants.system.lightBorder}; */}
2020-09-05 22:08:09 +03:00
border-radius: 4px;
margin-bottom: 8px;
2020-12-11 05:59:17 +03:00
background-color: ${Constants.system.white};
`;
const STYLES_USER = css`
display: grid;
grid-template-columns: auto 1fr;
align-items: center;
2020-12-11 06:12:03 +03:00
margin: 16px;
2020-09-05 22:08:09 +03:00
color: ${Constants.system.brand};
font-family: ${Constants.font.medium};
font-size: ${Constants.typescale.lvl1};
2020-10-01 03:41:53 +03:00
@media (max-width: ${Constants.sizes.mobile}px) {
margin: 12px 16px;
}
`;
2020-09-06 00:36:20 +03:00
const STYLES_BUTTONS = css`
justify-self: end;
2020-09-06 00:36:20 +03:00
display: flex;
flex-direction: row;
2020-12-11 06:12:03 +03:00
margin-right: 16px;
2020-10-01 03:41:53 +03:00
justify-content: flex-end;
@media (max-width: ${Constants.sizes.mobile}px) {
margin-right: 8px;
}
2020-09-06 00:36:20 +03:00
`;
2020-09-06 02:41:12 +03:00
const STYLES_ITEM_BOX = css`
position: relative;
justify-self: end;
display: flex;
align-items: center;
justify-content: center;
padding: 8px;
2020-12-11 06:12:03 +03:00
margin-right: 16px;
2020-09-06 02:41:12 +03:00
color: ${Constants.system.darkGray};
2020-10-01 03:41:53 +03:00
@media (max-width: ${Constants.sizes.mobile}px) {
margin-right: 8px;
}
2020-09-06 02:41:12 +03:00
`;
2020-09-06 00:36:20 +03:00
const STYLES_ACTION_BUTTON = css`
cursor: pointer;
padding: 8px;
color: ${Constants.system.brand};
font-family: ${Constants.font.medium};
`;
const STYLES_PROFILE_IMAGE = css`
2020-09-10 06:28:48 +03:00
background-color: ${Constants.system.foreground};
background-size: cover;
background-position: 50% 50%;
height: 24px;
width: 24px;
2020-09-05 22:08:09 +03:00
margin-right: 16px;
border-radius: 4px;
`;
2020-09-06 02:41:12 +03:00
const STYLES_MESSAGE = css`
color: ${Constants.system.black};
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
@media (max-width: 1000px) {
display: none;
}
`;
2020-09-07 01:30:33 +03:00
const STYLES_NAME = css`
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
`;
2020-09-05 22:08:09 +03:00
function UserEntry({ user, button, onClick, message }) {
return (
<div key={user.username} css={STYLES_USER_ENTRY}>
<div css={STYLES_USER} onClick={onClick}>
2020-10-26 00:11:27 +03:00
<div css={STYLES_PROFILE_IMAGE} style={{ backgroundImage: `url(${user.data.photo})` }} />
2020-09-07 01:30:33 +03:00
<span css={STYLES_NAME}>
2020-09-05 22:08:09 +03:00
{user.data.name || `@${user.username}`}
2020-09-06 02:41:12 +03:00
{message ? <span css={STYLES_MESSAGE}>{message}</span> : null}
2020-09-05 22:08:09 +03:00
</span>
</div>
{button}
</div>
);
}
2020-09-06 02:41:12 +03:00
const STYLES_COPY_INPUT = css`
pointer-events: none;
position: absolute;
opacity: 0;
`;
2020-10-01 03:41:53 +03:00
const STYLES_MOBILE_HIDDEN = css`
@media (max-width: ${Constants.sizes.mobile}px) {
display: none;
}
`;
const STYLES_MOBILE_ONLY = css`
@media (min-width: ${Constants.sizes.mobile}px) {
display: none;
}
`;
export default class SceneDirectory extends React.Component {
2020-09-06 02:41:12 +03:00
_ref;
state = {
2020-09-06 02:41:12 +03:00
copyValue: "",
contextMenu: null,
};
2020-09-06 02:41:12 +03:00
_handleCopy = (e, value) => {
e.stopPropagation();
this.setState({ copyValue: value }, () => {
this._ref.select();
document.execCommand("copy");
this._handleHide();
});
};
_handleHide = (e) => {
this.setState({ contextMenu: null });
};
_handleClick = (e, value) => {
e.stopPropagation();
if (this.state.contextMenu === value) {
this._handleHide();
} else {
this.setState({ contextMenu: value });
}
};
2020-12-13 04:30:56 +03:00
// _handleDelete = async (e, id) => {
// this._handleHide();
// e.stopPropagation();
// await Actions.deleteTrustRelationship({
// id: id,
// });
// };
// _handleAccept = async (e, id) => {
// this._handleHide();
// e.stopPropagation();
// await Actions.updateTrustRelationship({
// userId: id,
// });
// };
2020-09-06 02:41:12 +03:00
_handleFollow = async (e, id) => {
this._handleHide();
e.stopPropagation();
2020-10-31 02:12:20 +03:00
await Actions.createSubscription({
userId: id,
});
};
render() {
2020-12-13 04:16:55 +03:00
// let requests = this.props.viewer.pendingTrusted
// .filter((relation) => {
// return !relation.data.verified;
// })
// .map((relation) => {
// let button = (
// <React.Fragment>
// <span css={STYLES_MOBILE_ONLY}>
// <div css={STYLES_BUTTONS}>
// <div
// css={STYLES_ITEM_BOX}
// onClick={(e) => this._handleAccept(e, relation.owner.id)}
// >
// <SVG.CheckBox height="24px" style={{ color: Constants.system.brand }} />
// </div>
// <div
// css={STYLES_ITEM_BOX}
// style={{ marginRight: 0 }}
// onClick={(e) => {
// this._handleDelete(e, relation.id);
// }}
// >
// <SVG.Dismiss height="24px" style={{ color: Constants.system.gray }} />
// </div>
// </div>
// </span>
// <span css={STYLES_MOBILE_HIDDEN}>
// <div css={STYLES_BUTTONS}>
// <ButtonPrimary
// transparent
// style={{ fontSize: 16 }}
// onClick={(e) => this._handleAccept(e, relation.owner.id)}
// >
// Accept
// </ButtonPrimary>
// <ButtonSecondary
// transparent
// style={{ fontSize: 16 }}
// onClick={(e) => {
// this._handleDelete(e, relation.id);
// }}
// >
// Decline
// </ButtonSecondary>
// </div>
// </span>
// </React.Fragment>
// );
// return (
// <UserEntry
// key={relation.id}
// user={relation.owner}
// button={button}
// onClick={() => {
// this.props.onAction({
// type: "NAVIGATE",
// value: this.props.sceneId,
// scene: "PROFILE",
2020-12-13 04:16:55 +03:00
// data: relation.owner,
// });
// }}
// message=" requested to trust you"
// />
// );
// });
2020-09-01 07:44:56 +03:00
2020-12-13 04:16:55 +03:00
// let trusted = this.props.viewer.pendingTrusted
// .filter((relation) => {
// return relation.data.verified;
// })
// .map((relation) => {
// let button = (
// <div css={STYLES_ITEM_BOX} onClick={(e) => this._handleClick(e, relation.id)}>
// <SVG.MoreHorizontal height="24px" />
// {this.state.contextMenu === relation.id ? (
// <Boundary
// captureResize={true}
// captureScroll={false}
// enabled
// onOutsideRectEvent={(e) => this._handleClick(e, relation.id)}
// >
// <PopoverNavigation
// style={{
// top: "40px",
// right: "0px",
// }}
// navigation={[
// {
// text: "Copy profile URL",
// onClick: (e) =>
// this._handleCopy(e, `https://slate.host/${relation.owner.username}`),
// },
// {
// text: "Remove peer",
// onClick: (e) => this._handleDelete(e, relation.id),
// },
// ]}
// />
// </Boundary>
// ) : null}
// </div>
// );
// return (
// <UserEntry
// key={relation.id}
// user={relation.owner}
// button={button}
// onClick={() => {
// this.props.onAction({
// type: "NAVIGATE",
// value: this.props.sceneId,
// scene: "PROFILE",
2020-12-13 04:16:55 +03:00
// data: relation.owner,
// });
// }}
// />
// );
// });
// if (!trusted) {
// trusted = [];
// }
// trusted.push(
// ...this.props.viewer.trusted
// .filter((relation) => {
// return relation.data.verified;
// })
// .map((relation) => {
// let button = (
// <div css={STYLES_ITEM_BOX} onClick={(e) => this._handleClick(e, relation.id)}>
// <SVG.MoreHorizontal height="24px" />
// {this.state.contextMenu === relation.id ? (
// <Boundary
// captureResize={true}
// captureScroll={false}
// enabled
// onOutsideRectEvent={(e) => this._handleClick(e, relation.id)}
// >
// <PopoverNavigation
// style={{
// top: "40px",
// right: "0px",
// }}
// navigation={[
// {
// text: "Copy profile URL",
// onClick: (e) =>
// this._handleCopy(e, `https://slate.host/${relation.user.username}`),
// },
// {
// text: "Remove peer",
// onClick: (e) => this._handleDelete(e, relation.id),
// },
// ]}
// />
// </Boundary>
// ) : null}
// </div>
// );
// return (
// <UserEntry
// key={relation.id}
// user={relation.user}
// button={button}
// onClick={() => {
// this.props.onAction({
// type: "NAVIGATE",
// value: this.props.sceneId,
// scene: "PROFILE",
2020-12-13 04:16:55 +03:00
// data: relation.user,
// });
// }}
// />
// );
// })
// );
2020-09-01 07:44:56 +03:00
2020-09-06 00:36:20 +03:00
let following = this.props.viewer.subscriptions
2020-09-01 07:44:56 +03:00
.filter((relation) => {
return !!relation.target_user_id;
})
.map((relation) => {
let button = (
2020-10-26 00:11:27 +03:00
<div css={STYLES_ITEM_BOX} onClick={(e) => this._handleClick(e, relation.id)}>
2020-09-06 02:41:12 +03:00
<SVG.MoreHorizontal height="24px" />
{this.state.contextMenu === relation.id ? (
<Boundary
captureResize={true}
captureScroll={false}
enabled
onOutsideRectEvent={(e) => this._handleClick(e, relation.id)}
>
<PopoverNavigation
style={{
top: "40px",
right: "0px",
2020-09-06 02:41:12 +03:00
}}
navigation={[
{
text: "Copy profile URL",
2020-09-06 02:41:12 +03:00
onClick: (e) =>
2020-10-26 00:11:27 +03:00
this._handleCopy(e, `https://slate.host/${relation.user.username}`),
2020-09-06 02:41:12 +03:00
},
{
text: "Unfollow",
onClick: (e) => this._handleFollow(e, relation.user.id),
},
]}
/>
</Boundary>
) : null}
2020-09-01 07:44:56 +03:00
</div>
);
return (
<UserEntry
2020-09-06 02:41:12 +03:00
key={relation.id}
2020-09-01 07:44:56 +03:00
user={relation.user}
button={button}
onClick={() => {
this.props.onAction({
type: "NAVIGATE",
value: this.props.sceneId,
scene: "PROFILE",
2020-09-01 07:44:56 +03:00
data: relation.user,
});
}}
/>
);
});
2020-09-07 01:30:33 +03:00
let followers = this.props.viewer.subscribers.map((relation) => {
let button = (
2020-10-26 00:11:27 +03:00
<div css={STYLES_ITEM_BOX} onClick={(e) => this._handleClick(e, relation.id)}>
2020-09-07 01:30:33 +03:00
<SVG.MoreHorizontal height="24px" />
{this.state.contextMenu === relation.id ? (
<Boundary
captureResize={true}
captureScroll={false}
enabled
onOutsideRectEvent={(e) => this._handleClick(e, relation.id)}
>
<PopoverNavigation
style={{
top: "40px",
right: "0px",
}}
navigation={[
{
text: "Copy profile URL",
2020-09-07 01:30:33 +03:00
onClick: (e) =>
2020-10-26 00:11:27 +03:00
this._handleCopy(e, `https://slate.host/${relation.owner.username}`),
2020-09-07 01:30:33 +03:00
},
{
2020-10-26 00:11:27 +03:00
text: this.props.viewer.subscriptions.filter((subscription) => {
return subscription.target_user_id === relation.owner.id;
}).length
2020-09-07 01:30:33 +03:00
? "Unfollow"
: "Follow",
onClick: (e) => this._handleFollow(e, relation.owner.id),
},
]}
/>
</Boundary>
) : null}
</div>
);
return (
<UserEntry
key={relation.id}
user={relation.owner}
button={button}
onClick={() => {
this.props.onAction({
type: "NAVIGATE",
value: this.props.sceneId,
scene: "PROFILE",
2020-09-07 01:30:33 +03:00
data: relation.owner,
});
}}
/>
);
});
return (
<ScenePage>
<ScenePageHeader title="Directory" />
2020-12-18 00:49:39 +03:00
<SecondaryTabGroup
2020-12-19 08:25:50 +03:00
tabs={[
{ title: "Following", value: "NAV_DIRECTORY" },
{ title: "Followers", value: "NAV_DIRECTORY_FOLLOWERS" },
]}
2020-12-18 05:59:41 +03:00
value={this.props.tab}
2020-12-19 08:25:50 +03:00
onAction={this.props.onAction}
2020-09-03 02:17:31 +03:00
/>
2020-12-18 05:59:41 +03:00
{/* {this.props.tab === 0 ? (
2020-09-14 23:42:52 +03:00
requests && requests.length ? (
2020-09-08 01:16:02 +03:00
requests
) : (
<EmptyState>
<SVG.Users height="24px" style={{ marginBottom: 24 }} />
Trust requests that you receive will appear here.
2020-09-08 01:16:02 +03:00
</EmptyState>
)
) : null}
2020-12-18 05:59:41 +03:00
{this.props.tab === 1 ? (
2020-09-14 23:42:52 +03:00
trusted && trusted.length ? (
2020-09-08 01:16:02 +03:00
trusted
) : (
<EmptyState>
<SVG.Users height="24px" style={{ marginBottom: 24 }} />
Trusted is for your close friends.
2020-09-08 01:16:02 +03:00
</EmptyState>
)
2020-12-13 04:16:55 +03:00
) : null} */}
2020-12-18 05:59:41 +03:00
{this.props.tab === 0 ? (
2020-09-14 23:42:52 +03:00
following && following.length ? (
2020-09-08 01:16:02 +03:00
following
) : (
<EmptyState>
<SVG.Users height="24px" style={{ marginBottom: 24 }} />
2020-10-26 00:11:27 +03:00
You can follow any user on the network to be updated on their new uploads and slates.
2020-09-08 01:16:02 +03:00
</EmptyState>
)
) : null}
2020-12-18 05:59:41 +03:00
{this.props.tab === 1 ? (
2020-09-14 23:42:52 +03:00
followers && followers.length ? (
2020-09-08 01:16:02 +03:00
followers
) : (
<EmptyState>
<SVG.Users height="24px" style={{ marginBottom: 24 }} />
You don't have any followers yet.
2020-09-08 01:16:02 +03:00
</EmptyState>
)
) : null}
<input
readOnly
ref={(c) => {
this._ref = c;
}}
value={this.state.copyValue}
2020-09-27 07:43:25 +03:00
tabIndex="-1"
2020-09-08 01:16:02 +03:00
css={STYLES_COPY_INPUT}
/>
</ScenePage>
);
}
}