2020-08-31 21:19:46 +03:00
|
|
|
import * as React from "react";
|
|
|
|
import * as Actions from "~/common/actions";
|
|
|
|
|
2020-11-30 08:24:22 +03:00
|
|
|
import { css } from "@emotion/react";
|
2020-10-31 02:12:20 +03:00
|
|
|
import { ButtonPrimary, ButtonSecondary } from "~/components/system/components/Buttons";
|
2020-08-31 21:19:46 +03:00
|
|
|
|
|
|
|
import ScenePage from "~/components/core/ScenePage";
|
|
|
|
import Profile from "~/components/core/Profile";
|
|
|
|
|
2020-09-15 00:29:41 +03:00
|
|
|
const STYLES_BUTTONS = css`
|
|
|
|
display: inline-flex;
|
|
|
|
flex-direction: row;
|
|
|
|
align-items: center;
|
|
|
|
`;
|
|
|
|
|
2020-08-31 21:19:46 +03:00
|
|
|
const STATUS_BUTTON_MAP = {
|
2020-09-13 03:00:58 +03:00
|
|
|
trusted: "Remove peer",
|
|
|
|
untrusted: "Add peer",
|
|
|
|
sent: "Cancel request",
|
|
|
|
received: "Accept request",
|
2020-08-31 21:19:46 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
export default class SceneProfile extends React.Component {
|
2020-10-31 02:12:20 +03:00
|
|
|
_handleTrust = async (trustStatus, trustId) => {
|
|
|
|
if (trustStatus === "untrusted" || trustStatus === "sent") {
|
|
|
|
await Actions.createTrustRelationship({
|
|
|
|
userId: this.props.data.id,
|
|
|
|
});
|
|
|
|
} else if (trustStatus === "received") {
|
|
|
|
await Actions.updateTrustRelationship({
|
|
|
|
userId: this.props.data.id,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
await Actions.deleteTrustRelationship({
|
|
|
|
id: trustId,
|
|
|
|
});
|
|
|
|
}
|
2020-08-31 21:19:46 +03:00
|
|
|
};
|
|
|
|
|
2020-10-31 02:12:20 +03:00
|
|
|
_handleFollow = async () => {
|
|
|
|
await Actions.createSubscription({
|
|
|
|
userId: this.props.data.id,
|
|
|
|
});
|
2020-08-31 21:19:46 +03:00
|
|
|
};
|
|
|
|
|
2020-10-31 02:12:20 +03:00
|
|
|
render() {
|
|
|
|
let trustId, followStatus, relation;
|
|
|
|
let trustStatus = "untrusted";
|
|
|
|
let viewer = this.props.viewer;
|
2020-08-31 21:19:46 +03:00
|
|
|
let trust = viewer.trusted.filter((entry) => {
|
|
|
|
return entry.target_user_id === this.props.data.id;
|
|
|
|
});
|
|
|
|
if (trust.length) {
|
2020-10-31 02:12:20 +03:00
|
|
|
relation = trust[0];
|
|
|
|
trustId = relation.id;
|
2020-08-31 21:19:46 +03:00
|
|
|
if (relation.data.verified) {
|
2020-10-31 02:12:20 +03:00
|
|
|
trustStatus = "trusted";
|
2020-08-31 21:19:46 +03:00
|
|
|
} else {
|
2020-10-31 02:12:20 +03:00
|
|
|
trustStatus = "sent";
|
2020-08-31 21:19:46 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
let pendingTrust = viewer.pendingTrusted.filter((entry) => {
|
|
|
|
return entry.owner_user_id === this.props.data.id;
|
|
|
|
});
|
|
|
|
if (pendingTrust.length) {
|
2020-10-31 02:12:20 +03:00
|
|
|
relation = pendingTrust[0];
|
|
|
|
trustId = relation.id;
|
2020-08-31 21:19:46 +03:00
|
|
|
if (pendingTrust[0].data.verified) {
|
2020-10-31 02:12:20 +03:00
|
|
|
trustStatus = "trusted";
|
2020-08-31 21:19:46 +03:00
|
|
|
} else {
|
2020-10-31 02:12:20 +03:00
|
|
|
trustStatus = "received";
|
2020-08-31 21:19:46 +03:00
|
|
|
}
|
|
|
|
}
|
2020-10-31 02:12:20 +03:00
|
|
|
followStatus = !!viewer.subscriptions.filter((entry) => {
|
|
|
|
return entry.target_user_id === this.props.data.id;
|
|
|
|
}).length;
|
2020-08-31 21:19:46 +03:00
|
|
|
|
|
|
|
let buttons = (
|
2020-09-15 00:29:41 +03:00
|
|
|
<div css={STYLES_BUTTONS}>
|
2020-10-31 02:12:20 +03:00
|
|
|
{followStatus ? (
|
2020-11-28 04:54:42 +03:00
|
|
|
<ButtonSecondary style={{ marginRight: 8, minWidth: 152 }} onClick={this._handleFollow}>
|
2020-09-03 00:08:32 +03:00
|
|
|
Unfollow
|
|
|
|
</ButtonSecondary>
|
|
|
|
) : (
|
2020-11-28 04:54:42 +03:00
|
|
|
<ButtonPrimary style={{ marginRight: 8, minWidth: 152 }} onClick={this._handleFollow}>
|
2020-09-03 00:08:32 +03:00
|
|
|
Follow
|
|
|
|
</ButtonPrimary>
|
|
|
|
)}
|
2020-10-31 02:12:20 +03:00
|
|
|
{trustStatus === "untrusted" || trustStatus === "received" ? (
|
2020-09-03 00:08:32 +03:00
|
|
|
<ButtonPrimary
|
2020-11-28 04:54:42 +03:00
|
|
|
style={{ marginRight: 8, minWidth: 152 }}
|
2020-10-31 02:12:20 +03:00
|
|
|
onClick={() => this._handleTrust(trustStatus, trustId)}
|
2020-09-03 00:08:32 +03:00
|
|
|
>
|
2020-10-31 02:12:20 +03:00
|
|
|
{STATUS_BUTTON_MAP[trustStatus]}
|
2020-09-03 00:08:32 +03:00
|
|
|
</ButtonPrimary>
|
|
|
|
) : (
|
|
|
|
<ButtonSecondary
|
2020-11-28 04:54:42 +03:00
|
|
|
style={{ marginRight: 8, minWidth: 152 }}
|
2020-10-31 02:12:20 +03:00
|
|
|
onClick={() => this._handleTrust(trustStatus, trustId)}
|
2020-09-03 00:08:32 +03:00
|
|
|
>
|
2020-10-31 02:12:20 +03:00
|
|
|
{STATUS_BUTTON_MAP[trustStatus]}
|
2020-09-03 00:08:32 +03:00
|
|
|
</ButtonSecondary>
|
|
|
|
)}
|
2020-08-31 21:19:46 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
return (
|
2020-09-03 00:08:32 +03:00
|
|
|
<ScenePage>
|
2020-08-31 21:19:46 +03:00
|
|
|
<Profile
|
2020-09-03 02:17:31 +03:00
|
|
|
{...this.props}
|
2020-08-31 21:19:46 +03:00
|
|
|
onAction={this.props.onAction}
|
|
|
|
creator={this.props.data}
|
|
|
|
sceneId={this.props.sceneId}
|
2020-10-31 02:12:20 +03:00
|
|
|
buttons={this.props.viewer.username === this.props.data.username ? null : buttons}
|
2020-10-05 00:30:28 +03:00
|
|
|
isOwner={this.props.viewer.username === this.props.data.username}
|
2020-08-31 21:19:46 +03:00
|
|
|
/>
|
|
|
|
</ScenePage>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|