2020-08-26 03:44:45 +03:00
|
|
|
import * as React from "react";
|
|
|
|
import * as Constants from "~/common/constants";
|
|
|
|
import * as System from "~/components/system";
|
2020-08-26 04:27:05 +03:00
|
|
|
import * as Actions from "~/common/actions";
|
2020-08-26 03:44:45 +03:00
|
|
|
|
2020-11-04 20:55:48 +03:00
|
|
|
import { css } from "@emotion/core";
|
2020-09-12 01:25:33 +03:00
|
|
|
import { dispatchCustomEvent } from "~/common/custom-events";
|
2020-08-26 03:44:45 +03:00
|
|
|
|
2020-08-26 06:13:06 +03:00
|
|
|
const STYLES_ITEM = css`
|
|
|
|
font-size: 12px;
|
|
|
|
font-weight: 600;
|
|
|
|
font-famliy: monaco;
|
|
|
|
white-space: pre-wrap;
|
|
|
|
overflow-wrap: break-word;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_ROW = css`
|
|
|
|
display: flex;
|
|
|
|
align-items: flex-start;
|
|
|
|
justify-content: space-between;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_COLUMN = css`
|
|
|
|
width: 33.33%;
|
|
|
|
flex-shrink: 0;
|
|
|
|
padding: 24px;
|
|
|
|
box-sizing: border-box;
|
|
|
|
`;
|
|
|
|
|
2020-08-26 03:44:45 +03:00
|
|
|
export const getServerSideProps = async (context) => {
|
|
|
|
return {
|
|
|
|
props: { ...context.query },
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export default class IntegrationPage extends React.Component {
|
2020-08-26 04:27:05 +03:00
|
|
|
state = {
|
|
|
|
results: [],
|
2020-08-26 06:13:06 +03:00
|
|
|
viewer: this.props.viewer,
|
2020-08-26 04:27:05 +03:00
|
|
|
};
|
2020-08-26 03:44:45 +03:00
|
|
|
|
2020-08-28 01:05:20 +03:00
|
|
|
async componentDidMount() {
|
|
|
|
const response = await Actions.getNetworkDirectory();
|
|
|
|
console.log(response);
|
|
|
|
}
|
2020-08-26 03:44:45 +03:00
|
|
|
|
2020-08-26 04:27:05 +03:00
|
|
|
_handleChange = async (e) => {
|
|
|
|
const query = e.target.value;
|
2020-10-31 02:12:20 +03:00
|
|
|
const results = await Actions.search({
|
|
|
|
query,
|
|
|
|
filter: {
|
|
|
|
slates: true,
|
|
|
|
},
|
|
|
|
});
|
2020-08-26 04:27:05 +03:00
|
|
|
|
|
|
|
this.setState({ results: results.data.results });
|
|
|
|
};
|
|
|
|
|
2020-08-26 06:13:06 +03:00
|
|
|
_handleUpdate = async (e) => {
|
|
|
|
const response = await Actions.hydrateAuthenticatedUser();
|
|
|
|
|
2020-09-12 01:25:33 +03:00
|
|
|
if (!response) {
|
|
|
|
dispatchCustomEvent({
|
|
|
|
name: "create-alert",
|
|
|
|
detail: {
|
|
|
|
alert: {
|
2020-10-31 02:12:20 +03:00
|
|
|
message: "We're having trouble connecting right now. Please try again later",
|
2020-09-12 01:25:33 +03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
2020-08-26 06:13:06 +03:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-09-12 01:25:33 +03:00
|
|
|
if (response.error) {
|
|
|
|
dispatchCustomEvent({
|
|
|
|
name: "create-alert",
|
|
|
|
detail: { alert: { decorator: response.decorator } },
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-08-26 06:13:06 +03:00
|
|
|
const updates = {
|
|
|
|
viewer: response.data,
|
|
|
|
};
|
|
|
|
|
|
|
|
this.setState(updates);
|
|
|
|
};
|
|
|
|
|
2020-08-26 13:03:39 +03:00
|
|
|
_handleDelete = async (entity) => {
|
|
|
|
const response = await Actions.deleteTrustRelationship({ id: entity.id });
|
2020-08-31 21:19:46 +03:00
|
|
|
console.log(response);
|
2020-08-26 13:03:39 +03:00
|
|
|
|
|
|
|
await this._handleUpdate();
|
|
|
|
};
|
|
|
|
|
2020-08-26 06:13:06 +03:00
|
|
|
_handleTrust = async (user) => {
|
2020-08-26 06:22:41 +03:00
|
|
|
const response = await Actions.createTrustRelationship({
|
|
|
|
userId: user.target_user_id ? user.target_user_id : user.id,
|
|
|
|
});
|
2020-08-28 07:34:50 +03:00
|
|
|
console.log(response);
|
2020-08-26 06:13:06 +03:00
|
|
|
|
|
|
|
await this._handleUpdate();
|
|
|
|
};
|
|
|
|
|
2020-08-26 13:03:39 +03:00
|
|
|
_handleAccept = async (user) => {
|
|
|
|
const response = await Actions.updateTrustRelationship({
|
|
|
|
userId: user.owner_user_id,
|
|
|
|
});
|
2020-08-28 07:34:50 +03:00
|
|
|
console.log(response);
|
2020-08-26 13:03:39 +03:00
|
|
|
|
|
|
|
await this._handleUpdate();
|
|
|
|
};
|
|
|
|
|
2020-08-26 06:13:06 +03:00
|
|
|
_handleSubscribe = async (entity) => {
|
|
|
|
let response;
|
|
|
|
if (entity.type === "USER" || entity.target_user_id) {
|
|
|
|
response = await Actions.createSubscription({
|
|
|
|
userId: entity.target_user_id ? entity.target_user_id : entity.id,
|
|
|
|
});
|
2020-08-28 07:34:50 +03:00
|
|
|
console.log(response);
|
2020-08-26 06:13:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (entity.type === "SLATE" || entity.target_slate_id) {
|
|
|
|
response = await Actions.createSubscription({
|
|
|
|
slateId: entity.target_slate_id ? entity.target_slate_id : entity.id,
|
|
|
|
});
|
2020-08-28 07:34:50 +03:00
|
|
|
console.log(response);
|
2020-08-26 06:13:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
await this._handleUpdate();
|
|
|
|
};
|
|
|
|
|
2020-08-26 03:44:45 +03:00
|
|
|
render() {
|
2020-08-26 04:27:05 +03:00
|
|
|
return (
|
2020-08-26 06:13:06 +03:00
|
|
|
<div css={STYLES_ROW}>
|
|
|
|
<div css={STYLES_COLUMN}>
|
2020-08-26 13:03:39 +03:00
|
|
|
{this.state.viewer.pendingTrusted.map((each) => {
|
|
|
|
return (
|
|
|
|
<div css={STYLES_ITEM} key={each.id}>
|
|
|
|
{JSON.stringify(each, null, 1)}{" "}
|
|
|
|
<div>
|
|
|
|
{!each.data.verified ? (
|
2020-10-31 02:12:20 +03:00
|
|
|
<button onClick={() => this._handleAccept(each)}>Accept</button>
|
2020-08-26 13:03:39 +03:00
|
|
|
) : null}
|
|
|
|
|
|
|
|
{each.data.verified ? (
|
2020-10-31 02:12:20 +03:00
|
|
|
<button onClick={() => this._handleDelete(each)}>Delete</button>
|
2020-08-26 13:03:39 +03:00
|
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
})}
|
2020-08-26 06:22:41 +03:00
|
|
|
|
2020-08-26 13:03:39 +03:00
|
|
|
{this.state.viewer.trusted.map((each) => {
|
2020-08-26 06:13:06 +03:00
|
|
|
return (
|
|
|
|
<div css={STYLES_ITEM} key={each.id}>
|
|
|
|
{JSON.stringify(each, null, 1)}{" "}
|
2020-08-26 06:22:41 +03:00
|
|
|
<div>
|
2020-08-26 13:03:39 +03:00
|
|
|
{!each.data.verified ? (
|
|
|
|
<button onClick={() => this._handleTrust(each)}>
|
|
|
|
Cancel Pending Request Or Delete Friend
|
|
|
|
</button>
|
|
|
|
) : null}
|
|
|
|
|
|
|
|
{each.data.verified ? (
|
2020-10-31 02:12:20 +03:00
|
|
|
<button onClick={() => this._handleDelete(each)}>Delete</button>
|
2020-08-26 13:03:39 +03:00
|
|
|
) : null}
|
2020-08-26 06:22:41 +03:00
|
|
|
</div>
|
2020-08-26 06:13:06 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
<div css={STYLES_COLUMN}>
|
2020-10-31 02:12:20 +03:00
|
|
|
<button onClick={this._handleUpdate}>Update {this.state.viewer.username}</button>
|
2020-08-26 06:13:06 +03:00
|
|
|
<br />
|
2020-10-31 02:12:20 +03:00
|
|
|
<input type="text" onChange={this._handleChange} placeholder="type anything to search" />
|
2020-08-26 06:13:06 +03:00
|
|
|
|
|
|
|
{this.state.results.map((each) => {
|
|
|
|
if (!each) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div css={STYLES_ITEM} key={each.id}>
|
|
|
|
{JSON.stringify(each, null, 1)}{" "}
|
|
|
|
<div>
|
|
|
|
{each.type === "USER" ? (
|
2020-10-31 02:12:20 +03:00
|
|
|
<button onClick={() => this._handleTrust(each)}>Trust</button>
|
2020-08-26 06:13:06 +03:00
|
|
|
) : null}
|
2020-10-31 02:12:20 +03:00
|
|
|
<button onClick={() => this._handleSubscribe(each)}>Subscribe</button>
|
2020-08-26 06:13:06 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
<div css={STYLES_COLUMN}>
|
|
|
|
{this.state.viewer.subscriptions.map((each) => {
|
|
|
|
return (
|
|
|
|
<div css={STYLES_ITEM} key={each.id}>
|
|
|
|
{JSON.stringify(each, null, 1)}{" "}
|
|
|
|
<div>
|
2020-10-31 02:12:20 +03:00
|
|
|
<button onClick={() => this._handleSubscribe(each)}>Unsubscribe</button>
|
2020-08-26 06:13:06 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</div>
|
2020-08-26 04:27:05 +03:00
|
|
|
</div>
|
|
|
|
);
|
2020-08-26 03:44:45 +03:00
|
|
|
}
|
|
|
|
}
|