2020-07-16 04:36:29 +03:00
|
|
|
import * as React from "react";
|
|
|
|
import * as Actions from "~/common/actions";
|
2020-07-28 09:54:15 +03:00
|
|
|
import * as Constants from "~/common/constants";
|
2020-07-16 04:36:29 +03:00
|
|
|
import * as System from "~/components/system";
|
2020-09-05 02:15:29 +03:00
|
|
|
import * as SVG from "~/common/svg";
|
2020-11-28 07:39:01 +03:00
|
|
|
import * as Events from "~/common/custom-events";
|
2020-07-16 04:36:29 +03:00
|
|
|
|
2020-11-30 08:24:22 +03:00
|
|
|
import { css } from "@emotion/react";
|
2020-07-16 04:36:29 +03:00
|
|
|
|
|
|
|
import ScenePage from "~/components/core/ScenePage";
|
2020-08-22 07:25:34 +03:00
|
|
|
import ScenePageHeader from "~/components/core/ScenePageHeader";
|
2020-07-29 02:08:38 +03:00
|
|
|
import CodeBlock from "~/components/system/CodeBlock";
|
2020-07-16 04:36:29 +03:00
|
|
|
|
2021-03-22 21:17:42 +03:00
|
|
|
import APIDocsGet from "~/components/api/get";
|
|
|
|
import APIDocsGetSlate from "~/components/api/get-slate.js";
|
2021-03-24 07:10:26 +03:00
|
|
|
import APIDocsUpdateSlate from "~/components/api/update-slate.js";
|
|
|
|
import APIDocsUploadToSlate from "~/components/api/upload.js";
|
2021-03-22 21:17:42 +03:00
|
|
|
|
2020-07-28 09:54:15 +03:00
|
|
|
const STYLES_KEY = css`
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: space-between;
|
2020-08-09 01:04:17 +03:00
|
|
|
width: 100%;
|
2020-08-09 06:52:22 +03:00
|
|
|
max-width: 416px;
|
2020-09-14 08:22:19 +03:00
|
|
|
background-color: ${Constants.system.foreground};
|
2020-09-05 21:12:43 +03:00
|
|
|
color: ${Constants.system.pitchBlack};
|
|
|
|
border-radius: 4px;
|
2020-09-14 08:22:19 +03:00
|
|
|
height: 40px;
|
2020-07-28 09:54:15 +03:00
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_KEY_LEFT = css`
|
2020-08-09 01:04:17 +03:00
|
|
|
min-width: 10%;
|
|
|
|
width: 100%;
|
2020-07-28 09:54:15 +03:00
|
|
|
font-family: ${Constants.font.code};
|
2020-09-14 08:22:19 +03:00
|
|
|
padding: 0 16px;
|
2020-08-09 01:04:17 +03:00
|
|
|
font-size: 11px;
|
2020-07-28 09:54:15 +03:00
|
|
|
`;
|
|
|
|
|
2020-09-14 08:22:19 +03:00
|
|
|
const STYLES_KEY_CONTAINER = css`
|
|
|
|
height: 40px;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
align-items: center;
|
|
|
|
margin-bottom: 8px;
|
2020-07-28 09:54:15 +03:00
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_CIRCLE_BUTTON = css`
|
2020-09-14 08:22:19 +03:00
|
|
|
height: 40px;
|
|
|
|
width: 40px;
|
2020-09-05 21:12:43 +03:00
|
|
|
border-radius: 4px;
|
2020-07-28 09:54:15 +03:00
|
|
|
display: inline-flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
user-select: none;
|
2020-09-14 08:22:19 +03:00
|
|
|
background: ${Constants.system.gray};
|
2020-08-09 01:04:17 +03:00
|
|
|
color: ${Constants.system.black};
|
2020-07-28 09:54:15 +03:00
|
|
|
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.07);
|
|
|
|
cursor: pointer;
|
2020-08-09 01:04:17 +03:00
|
|
|
transition: 200ms ease all;
|
|
|
|
|
|
|
|
:hover {
|
|
|
|
background: ${Constants.system.brand};
|
|
|
|
color: ${Constants.system.white};
|
|
|
|
}
|
2020-07-28 09:54:15 +03:00
|
|
|
`;
|
|
|
|
|
2021-03-24 07:10:26 +03:00
|
|
|
const STYLES_LANGUAGE_CONTAINER = css`
|
|
|
|
display: flex;
|
|
|
|
width: 240px;
|
|
|
|
flex-direction: row;
|
|
|
|
position: relative;
|
|
|
|
justify-self: center;
|
|
|
|
justify-content: space-between;
|
|
|
|
align-items: center;
|
|
|
|
margin-top: 48px;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_LANGUAGE_TILE = css`
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
height: 100px;
|
|
|
|
width: 100px;
|
|
|
|
border-radius: 4px;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: flex-end;
|
|
|
|
user-select: pointer;
|
|
|
|
border: 2px solid #1a1a1a;
|
|
|
|
cursor: pointer;
|
|
|
|
`;
|
|
|
|
|
2021-03-22 21:17:42 +03:00
|
|
|
//NOTE(toast): overrides ScenePage from AppLayout
|
|
|
|
const STYLES_PAGE = css`
|
|
|
|
max-width: 960px;
|
|
|
|
width: 100%;
|
|
|
|
margin: 0 auto 0 auto;
|
|
|
|
padding: 88px 24px 128px 0px;
|
|
|
|
|
|
|
|
@media (max-width: 568px) {
|
|
|
|
padding: 88px 24px 128px 24px;
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_SIDEBAR = css`
|
2021-03-24 07:10:26 +03:00
|
|
|
padding: 160px 24px 128px 24px;
|
2021-03-22 21:17:42 +03:00
|
|
|
position: fixed;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
bottom: 0;
|
2021-03-24 07:10:26 +03:00
|
|
|
width: 236px;
|
2021-03-22 21:17:42 +03:00
|
|
|
background-color: ${Constants.system.foreground};
|
|
|
|
overflow-y: scroll;
|
|
|
|
|
|
|
|
::-webkit-scrollbar {
|
|
|
|
width: 4px;
|
|
|
|
}
|
|
|
|
|
|
|
|
::-webkit-scrollbar-track {
|
|
|
|
background: ${Constants.system.gray};
|
|
|
|
}
|
|
|
|
|
|
|
|
::-webkit-scrollbar-thumb {
|
|
|
|
background: ${Constants.system.darkGray};
|
|
|
|
}
|
|
|
|
|
|
|
|
::-webkit-scrollbar-thumb:hover {
|
|
|
|
background: ${Constants.system.brand};
|
|
|
|
}
|
|
|
|
|
|
|
|
@media (max-width: 568px) {
|
|
|
|
width: 100%;
|
|
|
|
position: relative;
|
|
|
|
overflow-y: auto;
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_LABEL = css`
|
|
|
|
font-family: ${Constants.font.semiBold};
|
|
|
|
display: block;
|
2021-03-24 07:10:26 +03:00
|
|
|
font-size: 16px;
|
2021-03-22 21:17:42 +03:00
|
|
|
text-transform: uppercase;
|
|
|
|
color: ${Constants.system.darkGray};
|
|
|
|
letter-spacing: 0.6px;
|
|
|
|
margin-top: 32px;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_LINK = css`
|
|
|
|
font-family: ${Constants.font.semiBold};
|
|
|
|
color: ${Constants.system.pitchBlack};
|
2021-03-24 07:10:26 +03:00
|
|
|
font-size: 16px;
|
2021-03-22 21:17:42 +03:00
|
|
|
text-decoration: none;
|
|
|
|
font-weight: 400;
|
|
|
|
display: block;
|
|
|
|
margin-top: 8px;
|
|
|
|
|
|
|
|
:hover {
|
|
|
|
color: ${Constants.system.brand};
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2020-07-28 09:54:15 +03:00
|
|
|
class Key extends React.Component {
|
|
|
|
state = { visible: false };
|
|
|
|
|
|
|
|
_handleToggleVisible = () => {
|
|
|
|
this.setState({ visible: !this.state.visible });
|
|
|
|
};
|
|
|
|
|
2020-08-09 01:04:17 +03:00
|
|
|
_handleDelete = async (id) => {
|
|
|
|
await this.props.onDelete(id);
|
|
|
|
};
|
|
|
|
|
2020-07-28 09:54:15 +03:00
|
|
|
render() {
|
|
|
|
return (
|
2020-09-14 08:22:19 +03:00
|
|
|
<div css={STYLES_KEY_CONTAINER}>
|
|
|
|
<div css={STYLES_KEY}>
|
|
|
|
{this.state.visible ? (
|
|
|
|
<div css={STYLES_KEY_LEFT}>{this.props.data.key}</div>
|
|
|
|
) : (
|
2020-10-28 07:01:15 +03:00
|
|
|
<div css={STYLES_KEY_LEFT}>XXXXXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXXXX</div>
|
2020-09-14 08:22:19 +03:00
|
|
|
)}
|
2020-07-28 09:54:15 +03:00
|
|
|
</div>
|
2020-09-14 08:22:19 +03:00
|
|
|
<span
|
|
|
|
css={STYLES_CIRCLE_BUTTON}
|
|
|
|
onClick={this._handleToggleVisible}
|
|
|
|
style={{
|
|
|
|
marginLeft: 8,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<SVG.Privacy height="16px" />
|
|
|
|
</span>
|
|
|
|
<span
|
|
|
|
css={STYLES_CIRCLE_BUTTON}
|
|
|
|
onClick={() => this._handleDelete(this.props.data.id)}
|
|
|
|
style={{
|
|
|
|
marginLeft: 8,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<SVG.Dismiss height="16px" />
|
|
|
|
</span>
|
2020-07-28 09:54:15 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-16 04:36:29 +03:00
|
|
|
export default class SceneSettingsDeveloper extends React.Component {
|
2020-07-28 09:54:15 +03:00
|
|
|
state = {
|
|
|
|
loading: false,
|
2021-03-24 07:10:26 +03:00
|
|
|
language: "javascript",
|
|
|
|
docs: "GET",
|
2020-07-28 09:54:15 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
_handleSave = async (e) => {
|
|
|
|
this.setState({ loading: true });
|
|
|
|
|
|
|
|
const response = await Actions.generateAPIKey();
|
2020-09-12 01:25:33 +03:00
|
|
|
|
2020-11-28 07:39:01 +03:00
|
|
|
Events.hasError(response);
|
2020-07-28 09:54:15 +03:00
|
|
|
|
|
|
|
this.setState({ loading: false });
|
|
|
|
};
|
|
|
|
|
|
|
|
_handleDelete = async (id) => {
|
|
|
|
this.setState({ loading: true });
|
|
|
|
|
2020-10-28 07:01:15 +03:00
|
|
|
if (!window.confirm("Are you sure you want to delete this key? This action is irreversible")) {
|
2020-07-28 09:54:15 +03:00
|
|
|
this.setState({ loading: false });
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const response = await Actions.deleteAPIKey({ id });
|
|
|
|
|
2020-11-28 07:39:01 +03:00
|
|
|
Events.hasError(response);
|
|
|
|
|
2020-10-31 02:12:20 +03:00
|
|
|
this.setState({ loading: false });
|
2020-07-28 09:54:15 +03:00
|
|
|
};
|
|
|
|
|
2021-03-22 21:17:42 +03:00
|
|
|
//handles language changes
|
|
|
|
_handleChangeLanguage = (newLanguage) => {
|
|
|
|
this.setState({ language: newLanguage });
|
|
|
|
};
|
|
|
|
|
2020-07-29 02:08:38 +03:00
|
|
|
async componentDidMount() {
|
|
|
|
if (!this.props.viewer.keys) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!this.props.viewer.keys.length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const response = await fetch("/api/v1/get-slate", {
|
|
|
|
method: "POST",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
Authorization: `Basic ${this.props.viewer.keys[0].key}`,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
const json = await response.json();
|
|
|
|
console.log(json);
|
|
|
|
}
|
|
|
|
|
2020-07-16 04:36:29 +03:00
|
|
|
render() {
|
2021-03-24 07:10:26 +03:00
|
|
|
let APIKey = "YOUR-API-KEY-HERE";
|
2021-03-25 02:30:41 +03:00
|
|
|
let lang = this.state.language;
|
2020-07-29 02:08:38 +03:00
|
|
|
if (this.props.viewer.keys) {
|
|
|
|
if (this.props.viewer.keys.length) {
|
2021-03-22 21:17:42 +03:00
|
|
|
APIKey = this.props.viewer.keys[0].key;
|
2020-07-29 02:08:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-24 07:10:26 +03:00
|
|
|
let slateId = "YOUR-SLATE-ID-VALUE";
|
2020-07-29 02:08:38 +03:00
|
|
|
if (this.props.viewer.slates) {
|
|
|
|
if (this.props.viewer.slates.length) {
|
|
|
|
slateId = this.props.viewer.slates[0].id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-09 10:28:03 +03:00
|
|
|
let userBucketCID = this.props.viewer?.userBucketCID;
|
2021-04-08 23:41:10 +03:00
|
|
|
|
2020-07-28 09:54:15 +03:00
|
|
|
return (
|
2021-03-25 02:30:41 +03:00
|
|
|
<ScenePage>
|
|
|
|
{/*
|
2021-03-22 21:17:42 +03:00
|
|
|
<div css={STYLES_SIDEBAR}>
|
2021-03-24 07:10:26 +03:00
|
|
|
<span css={STYLES_LINK} onClick={() => this._changeDocs("INTRO")}>
|
2021-03-22 21:17:42 +03:00
|
|
|
Introduction
|
|
|
|
</span>
|
2021-03-24 07:10:26 +03:00
|
|
|
<span css={STYLES_LABEL}>api</span>
|
2021-03-22 21:17:42 +03:00
|
|
|
<div>
|
2021-03-24 07:10:26 +03:00
|
|
|
<span
|
|
|
|
css={STYLES_LINK}
|
|
|
|
style={{ color: this.state.docs === "GET" ? Constants.system.brand : null }}
|
|
|
|
onClick={() => this._changeDocs("GET")}
|
|
|
|
>
|
2021-03-22 21:17:42 +03:00
|
|
|
Get all slates
|
|
|
|
</span>
|
2021-03-24 07:10:26 +03:00
|
|
|
<span
|
|
|
|
css={STYLES_LINK}
|
|
|
|
style={{ color: this.state.docs === "GET_SLATE" ? Constants.system.brand : null }}
|
|
|
|
onClick={() => this._changeDocs("GET_SLATE")}
|
|
|
|
>
|
2021-03-22 21:17:42 +03:00
|
|
|
Get slate by ID
|
|
|
|
</span>
|
2021-03-24 07:10:26 +03:00
|
|
|
<span
|
|
|
|
css={STYLES_LINK}
|
|
|
|
style={{
|
|
|
|
color: this.state.docs === "UPLOAD_TO_SLATE" ? Constants.system.brand : null,
|
|
|
|
}}
|
|
|
|
onClick={() => this._changeDocs("UPLOAD_TO_SLATE")}
|
|
|
|
>
|
2021-03-22 21:17:42 +03:00
|
|
|
Upload to slate by ID
|
|
|
|
</span>
|
2021-03-24 07:10:26 +03:00
|
|
|
<span
|
|
|
|
css={STYLES_LINK}
|
|
|
|
style={{ color: this.state.docs === "UPDATE_SLATE" ? Constants.system.brand : null }}
|
|
|
|
onClick={() => this._changeDocs("UPDATE_SLATE")}
|
|
|
|
>
|
2021-03-22 21:17:42 +03:00
|
|
|
Update slate
|
|
|
|
</span>
|
|
|
|
</div>
|
2021-03-24 07:10:26 +03:00
|
|
|
<span css={STYLES_LABEL}>guides</span>
|
2021-03-22 21:17:42 +03:00
|
|
|
</div>
|
2021-03-25 02:30:41 +03:00
|
|
|
*/}
|
2021-03-24 07:10:26 +03:00
|
|
|
<ScenePageHeader title="Developer Documentation">
|
2020-10-28 07:01:15 +03:00
|
|
|
You can use your API key to get slates and add images to slates. You can have a total of
|
|
|
|
10 keys at any given time.
|
2020-08-22 07:25:34 +03:00
|
|
|
</ScenePageHeader>
|
2020-07-28 09:54:15 +03:00
|
|
|
|
2021-04-08 23:41:10 +03:00
|
|
|
{userBucketCID && (
|
|
|
|
<System.DescriptionGroup
|
|
|
|
style={{ maxWidth: 640, marginTop: 34 }}
|
|
|
|
label="Bucket CID"
|
2021-04-09 10:21:24 +03:00
|
|
|
description={`${userBucketCID}`}
|
2021-04-08 23:41:10 +03:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
<br />
|
2021-04-12 23:21:46 +03:00
|
|
|
<System.DescriptionGroup style={{ maxWidth: 640, marginBottom: 34 }} label="API Keys" />
|
2020-07-28 09:54:15 +03:00
|
|
|
{this.props.viewer.keys.map((k) => {
|
|
|
|
return <Key key={k.id} data={k} onDelete={this._handleDelete} />;
|
|
|
|
})}
|
|
|
|
|
|
|
|
<div style={{ marginTop: 24 }}>
|
2020-10-28 07:01:15 +03:00
|
|
|
<System.ButtonPrimary onClick={this._handleSave} loading={this.state.loading}>
|
2020-07-28 09:54:15 +03:00
|
|
|
Generate
|
|
|
|
</System.ButtonPrimary>
|
2021-03-24 07:10:26 +03:00
|
|
|
{APIKey === "YOUR-API-KEY-HERE" ? (
|
|
|
|
<ScenePageHeader title="">
|
|
|
|
Generate an API key to have it appear in the code examples
|
|
|
|
</ScenePageHeader>
|
|
|
|
) : null}
|
2020-07-28 09:54:15 +03:00
|
|
|
</div>
|
2021-03-25 22:05:09 +03:00
|
|
|
{/*
|
2021-03-24 07:10:26 +03:00
|
|
|
<div css={STYLES_LANGUAGE_CONTAINER}>
|
|
|
|
<div
|
|
|
|
css={STYLES_LANGUAGE_TILE}
|
|
|
|
style={{ color: this.state.language === "javascript" ? Constants.system.brand : null }}
|
|
|
|
onClick={() => this._handleChangeLanguage("javascript")}
|
|
|
|
>
|
|
|
|
<span style={{ marginBottom: 32 }}>JS ICON</span>
|
|
|
|
<span>Node.js</span>
|
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
css={STYLES_LANGUAGE_TILE}
|
|
|
|
style={{ color: this.state.language === "python" ? Constants.system.brand : null }}
|
|
|
|
onClick={() => this._handleChangeLanguage("python")}
|
|
|
|
>
|
|
|
|
<span style={{ marginBottom: 32 }}>PY ICON</span>
|
|
|
|
<span>Python3</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-03-25 22:05:09 +03:00
|
|
|
|
2021-03-25 02:30:41 +03:00
|
|
|
<APIDocsGet language={lang} APIKey={APIKey} />
|
|
|
|
<APIDocsUpdateSlate language={lang} APIKey={APIKey} slateId={slateId} />
|
|
|
|
<APIDocsUploadToSlate language={lang} APIKey={APIKey} slateId={slateId} />
|
2021-03-25 22:05:09 +03:00
|
|
|
*/}
|
|
|
|
<React.Fragment>
|
2021-03-30 04:19:36 +03:00
|
|
|
<APIDocsGet
|
|
|
|
language={lang}
|
|
|
|
APIKey={APIKey}
|
|
|
|
onLanguageChange={this._handleChangeLanguage}
|
|
|
|
/>
|
2021-03-25 22:05:09 +03:00
|
|
|
<APIDocsGetSlate
|
|
|
|
language={lang}
|
|
|
|
APIKey={APIKey}
|
|
|
|
slateId={slateId}
|
|
|
|
onLanguageChange={this._handleChangeLanguage}
|
|
|
|
/>
|
2021-03-30 04:19:36 +03:00
|
|
|
<APIDocsUpdateSlate
|
|
|
|
language={lang}
|
|
|
|
APIKey={APIKey}
|
|
|
|
slateId={slateId}
|
|
|
|
onLanguageChange={this._handleChangeLanguage}
|
|
|
|
/>
|
|
|
|
<APIDocsUploadToSlate
|
|
|
|
language={lang}
|
|
|
|
APIKey={APIKey}
|
|
|
|
slateId={slateId}
|
|
|
|
onLanguageChange={this._handleChangeLanguage}
|
|
|
|
/>
|
2021-03-25 02:30:41 +03:00
|
|
|
</React.Fragment>
|
2020-07-28 09:54:15 +03:00
|
|
|
</ScenePage>
|
|
|
|
);
|
2020-07-16 04:36:29 +03:00
|
|
|
}
|
|
|
|
}
|