2020-09-23 23:52:00 +03:00
|
|
|
import * as React from "react";
|
|
|
|
import * as Strings from "~/common/strings";
|
|
|
|
import * as Constants from "~/common/constants";
|
|
|
|
import * as System from "~/components/system";
|
|
|
|
import * as Actions from "~/common/actions";
|
2020-11-22 00:25:40 +03:00
|
|
|
import * as UserBehaviors from "~/common/user-behaviors";
|
2020-09-23 23:52:00 +03:00
|
|
|
|
2020-11-30 08:24:22 +03:00
|
|
|
import { css } from "@emotion/react";
|
2020-10-24 09:36:52 +03:00
|
|
|
import { ButtonPrimary, ButtonDisabled } from "~/components/system/components/Buttons";
|
2020-09-27 07:43:25 +03:00
|
|
|
import { SlatePicker } from "~/components/core/SlatePicker";
|
2020-09-23 23:52:00 +03:00
|
|
|
|
|
|
|
const STYLES_HEADER = css`
|
|
|
|
font-family: ${Constants.font.semiBold};
|
|
|
|
margin-top: 32px;
|
|
|
|
margin-bottom: 16px;
|
|
|
|
`;
|
|
|
|
|
|
|
|
export default class SidebarAddFileToSlate extends React.Component {
|
|
|
|
state = {
|
|
|
|
selected: {},
|
|
|
|
};
|
|
|
|
|
2020-09-25 06:16:10 +03:00
|
|
|
componentDidMount = () => {
|
|
|
|
if (!this.props.sidebarData || !this.props.sidebarData.files) {
|
|
|
|
this.props.onCancel();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-09-23 23:52:00 +03:00
|
|
|
_handleCreateSlate = async () => {
|
|
|
|
if (
|
|
|
|
Object.values(this.state.selected).some((value) => {
|
|
|
|
return !!value;
|
|
|
|
})
|
|
|
|
) {
|
|
|
|
await this._handleSubmit();
|
|
|
|
}
|
|
|
|
await this.props.onCancel();
|
|
|
|
this.props.onAction({
|
|
|
|
type: "SIDEBAR",
|
|
|
|
value: "SIDEBAR_CREATE_SLATE",
|
|
|
|
data: this.props.sidebarData,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
_handleAdd = (slate) => {
|
|
|
|
if (this.state.selected[slate.id]) {
|
|
|
|
this.setState({
|
|
|
|
selected: { ...this.state.selected, [slate.id]: false },
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.setState({
|
|
|
|
selected: { ...this.state.selected, [slate.id]: slate },
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
_handleSubmit = async () => {
|
2020-12-15 04:43:16 +03:00
|
|
|
this.props.onCancel();
|
2020-09-23 23:52:00 +03:00
|
|
|
for (let slate of Object.values(this.state.selected)) {
|
|
|
|
if (!slate) continue;
|
2021-06-01 02:41:00 +03:00
|
|
|
await UserBehaviors.saveCopy({
|
2020-10-05 00:30:28 +03:00
|
|
|
slate,
|
2020-11-22 00:25:40 +03:00
|
|
|
files: this.props.sidebarData.files,
|
2020-10-05 00:30:28 +03:00
|
|
|
});
|
2020-09-23 23:52:00 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<System.P
|
|
|
|
style={{
|
|
|
|
fontFamily: Constants.font.semiBold,
|
|
|
|
fontSize: Constants.typescale.lvl3,
|
2020-12-11 05:59:17 +03:00
|
|
|
marginBottom: 36,
|
2020-09-23 23:52:00 +03:00
|
|
|
}}
|
|
|
|
>
|
2021-04-23 08:18:46 +03:00
|
|
|
Add files to collection
|
2020-09-23 23:52:00 +03:00
|
|
|
</System.P>
|
|
|
|
|
|
|
|
<System.P css={STYLES_HEADER}>Slates</System.P>
|
2020-09-27 07:43:25 +03:00
|
|
|
|
|
|
|
<SlatePicker
|
|
|
|
slates={this.props.viewer.slates}
|
|
|
|
selected={this.state.selected}
|
|
|
|
onAdd={this._handleAdd}
|
|
|
|
onCreateSlate={this._handleCreateSlate}
|
|
|
|
/>
|
|
|
|
|
2020-09-24 22:42:32 +03:00
|
|
|
{Object.keys(this.state.selected).length ? (
|
2020-12-22 04:20:24 +03:00
|
|
|
<ButtonPrimary full onClick={this._handleSubmit} style={{ marginTop: 32 }}>
|
2021-04-23 08:18:46 +03:00
|
|
|
Add to collections
|
2020-09-24 22:42:32 +03:00
|
|
|
</ButtonPrimary>
|
|
|
|
) : (
|
|
|
|
<ButtonDisabled full style={{ marginTop: 32 }}>
|
2021-04-23 08:18:46 +03:00
|
|
|
Add to collections
|
2020-09-24 22:42:32 +03:00
|
|
|
</ButtonDisabled>
|
|
|
|
)}
|
2020-09-23 23:52:00 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|