2023-06-21 22:28:24 +00:00
|
|
|
import { myAuthRequired, setIsoData } from "@utils/app";
|
2022-11-27 18:02:32 +00:00
|
|
|
import { Component, linkEvent } from "inferno";
|
2023-03-27 16:49:46 +00:00
|
|
|
import {
|
|
|
|
CreateCustomEmoji,
|
|
|
|
DeleteCustomEmoji,
|
|
|
|
EditCustomEmoji,
|
2023-05-11 18:32:32 +00:00
|
|
|
GetSiteResponse,
|
|
|
|
} from "lemmy-js-client";
|
2023-06-21 22:28:24 +00:00
|
|
|
import { customEmojisLookup } from "../../markdown";
|
2023-06-22 00:54:35 +00:00
|
|
|
import { HttpService, I18NextService } from "../../services";
|
2023-06-21 22:28:24 +00:00
|
|
|
import { pictrsDeleteToast, toast } from "../../toast";
|
2022-11-27 18:02:32 +00:00
|
|
|
import { EmojiMart } from "../common/emoji-mart";
|
|
|
|
import { HtmlTags } from "../common/html-tags";
|
|
|
|
import { Icon } from "../common/icon";
|
|
|
|
import { Paginator } from "../common/paginator";
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
interface EmojiFormProps {
|
|
|
|
onEdit(form: EditCustomEmoji): void;
|
|
|
|
onCreate(form: CreateCustomEmoji): void;
|
|
|
|
onDelete(form: DeleteCustomEmoji): void;
|
2023-06-16 15:52:47 +00:00
|
|
|
loading: boolean;
|
2023-06-14 12:20:40 +00:00
|
|
|
}
|
|
|
|
|
2022-11-27 18:02:32 +00:00
|
|
|
interface EmojiFormState {
|
2023-03-27 16:49:46 +00:00
|
|
|
siteRes: GetSiteResponse;
|
|
|
|
customEmojis: CustomEmojiViewForm[];
|
2023-05-15 19:53:29 +00:00
|
|
|
page: number;
|
2022-11-27 18:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
interface CustomEmojiViewForm {
|
2023-03-27 16:49:46 +00:00
|
|
|
id: number;
|
|
|
|
category: string;
|
|
|
|
shortcode: string;
|
|
|
|
image_url: string;
|
|
|
|
alt_text: string;
|
|
|
|
keywords: string;
|
|
|
|
changed: boolean;
|
2023-05-15 19:53:29 +00:00
|
|
|
page: number;
|
2022-11-27 18:02:32 +00:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
export class EmojiForm extends Component<EmojiFormProps, EmojiFormState> {
|
2023-03-27 16:49:46 +00:00
|
|
|
private isoData = setIsoData(this.context);
|
|
|
|
private itemsPerPage = 15;
|
|
|
|
private emptyState: EmojiFormState = {
|
|
|
|
siteRes: this.isoData.site_res,
|
|
|
|
customEmojis: this.isoData.site_res.custom_emojis.map((x, index) => ({
|
|
|
|
id: x.custom_emoji.id,
|
|
|
|
category: x.custom_emoji.category,
|
|
|
|
shortcode: x.custom_emoji.shortcode,
|
|
|
|
image_url: x.custom_emoji.image_url,
|
|
|
|
alt_text: x.custom_emoji.alt_text,
|
|
|
|
keywords: x.keywords.map(x => x.keyword).join(" "),
|
|
|
|
changed: false,
|
2023-05-15 19:53:29 +00:00
|
|
|
page: 1 + Math.floor(index / this.itemsPerPage),
|
2023-03-27 16:49:46 +00:00
|
|
|
})),
|
2023-05-15 19:53:29 +00:00
|
|
|
page: 1,
|
2023-03-27 16:49:46 +00:00
|
|
|
};
|
|
|
|
state: EmojiFormState;
|
|
|
|
private scrollRef: any = {};
|
|
|
|
constructor(props: any, context: any) {
|
|
|
|
super(props, context);
|
|
|
|
this.state = this.emptyState;
|
2022-11-27 18:02:32 +00:00
|
|
|
|
2023-03-27 16:49:46 +00:00
|
|
|
this.handlePageChange = this.handlePageChange.bind(this);
|
|
|
|
this.handleEmojiClick = this.handleEmojiClick.bind(this);
|
|
|
|
}
|
|
|
|
get documentTitle(): string {
|
2023-06-22 00:54:35 +00:00
|
|
|
return I18NextService.i18n.t("custom_emojis");
|
2023-03-27 16:49:46 +00:00
|
|
|
}
|
2022-11-27 18:02:32 +00:00
|
|
|
|
2023-03-27 16:49:46 +00:00
|
|
|
render() {
|
|
|
|
return (
|
2023-06-20 18:46:16 +00:00
|
|
|
<div className="home-emojis-form col-12">
|
2023-03-27 16:49:46 +00:00
|
|
|
<HtmlTags
|
|
|
|
title={this.documentTitle}
|
|
|
|
path={this.context.router.route.match.url}
|
|
|
|
/>
|
2023-06-22 00:54:35 +00:00
|
|
|
<h5 className="col-12">{I18NextService.i18n.t("custom_emojis")}</h5>
|
2023-03-27 16:49:46 +00:00
|
|
|
{customEmojisLookup.size > 0 && (
|
|
|
|
<div>
|
|
|
|
<EmojiMart
|
|
|
|
onEmojiClick={this.handleEmojiClick}
|
|
|
|
pickerOptions={this.configurePicker()}
|
|
|
|
></EmojiMart>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
<div className="table-responsive">
|
|
|
|
<table id="emojis_table" className="table table-sm table-hover">
|
|
|
|
<thead className="pointer">
|
|
|
|
<tr>
|
2023-06-22 00:54:35 +00:00
|
|
|
<th>{I18NextService.i18n.t("column_emoji")}</th>
|
|
|
|
<th className="text-right">
|
|
|
|
{I18NextService.i18n.t("column_shortcode")}
|
|
|
|
</th>
|
|
|
|
<th className="text-right">
|
|
|
|
{I18NextService.i18n.t("column_category")}
|
|
|
|
</th>
|
2023-03-27 16:49:46 +00:00
|
|
|
<th className="text-right d-lg-table-cell d-none">
|
2023-06-22 00:54:35 +00:00
|
|
|
{I18NextService.i18n.t("column_imageurl")}
|
|
|
|
</th>
|
|
|
|
<th className="text-right">
|
|
|
|
{I18NextService.i18n.t("column_alttext")}
|
2023-03-27 16:49:46 +00:00
|
|
|
</th>
|
|
|
|
<th className="text-right d-lg-table-cell">
|
2023-06-22 00:54:35 +00:00
|
|
|
{I18NextService.i18n.t("column_keywords")}
|
2023-03-27 16:49:46 +00:00
|
|
|
</th>
|
|
|
|
<th style="width:121px"></th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
{this.state.customEmojis
|
|
|
|
.slice(
|
2023-05-15 19:53:29 +00:00
|
|
|
Number((this.state.page - 1) * this.itemsPerPage),
|
2023-05-11 18:32:32 +00:00
|
|
|
Number(
|
2023-05-15 19:53:29 +00:00
|
|
|
(this.state.page - 1) * this.itemsPerPage +
|
|
|
|
this.itemsPerPage
|
2023-05-11 18:32:32 +00:00
|
|
|
)
|
2023-03-27 16:49:46 +00:00
|
|
|
)
|
|
|
|
.map((cv, index) => (
|
|
|
|
<tr key={index} ref={e => (this.scrollRef[cv.shortcode] = e)}>
|
|
|
|
<td style="text-align:center;">
|
|
|
|
<label
|
|
|
|
htmlFor={index.toString()}
|
|
|
|
className="pointer text-muted small font-weight-bold"
|
|
|
|
>
|
|
|
|
{cv.image_url.length > 0 && (
|
|
|
|
<img
|
|
|
|
className="icon-emoji-admin"
|
|
|
|
src={cv.image_url}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{cv.image_url.length == 0 && (
|
|
|
|
<span className="btn btn-sm btn-secondary">
|
|
|
|
Upload
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
</label>
|
|
|
|
<input
|
|
|
|
name={index.toString()}
|
|
|
|
id={index.toString()}
|
|
|
|
type="file"
|
|
|
|
accept="image/*"
|
|
|
|
className="d-none"
|
|
|
|
onChange={linkEvent(
|
|
|
|
{ form: this, index: index },
|
|
|
|
this.handleImageUpload
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</td>
|
|
|
|
<td className="text-right">
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
placeholder="ShortCode"
|
|
|
|
className="form-control"
|
|
|
|
disabled={cv.id > 0}
|
|
|
|
value={cv.shortcode}
|
|
|
|
onInput={linkEvent(
|
|
|
|
{ form: this, index: index },
|
|
|
|
this.handleEmojiShortCodeChange
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</td>
|
|
|
|
<td className="text-right">
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
placeholder="Category"
|
|
|
|
className="form-control"
|
|
|
|
value={cv.category}
|
|
|
|
onInput={linkEvent(
|
|
|
|
{ form: this, index: index },
|
|
|
|
this.handleEmojiCategoryChange
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</td>
|
|
|
|
<td className="text-right d-lg-table-cell d-none">
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
placeholder="Url"
|
|
|
|
className="form-control"
|
|
|
|
value={cv.image_url}
|
|
|
|
onInput={linkEvent(
|
|
|
|
{ form: this, index: index, overrideValue: null },
|
|
|
|
this.handleEmojiImageUrlChange
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</td>
|
|
|
|
<td className="text-right">
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
placeholder="Alt Text"
|
|
|
|
className="form-control"
|
|
|
|
value={cv.alt_text}
|
|
|
|
onInput={linkEvent(
|
|
|
|
{ form: this, index: index },
|
|
|
|
this.handleEmojiAltTextChange
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</td>
|
|
|
|
<td className="text-right d-lg-table-cell">
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
placeholder="Keywords"
|
|
|
|
className="form-control"
|
|
|
|
value={cv.keywords}
|
|
|
|
onInput={linkEvent(
|
|
|
|
{ form: this, index: index },
|
|
|
|
this.handleEmojiKeywordChange
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<div>
|
|
|
|
<span title={this.getEditTooltip(cv)}>
|
|
|
|
<button
|
|
|
|
className={
|
|
|
|
(cv.changed ? "text-success " : "text-muted ") +
|
|
|
|
"btn btn-link btn-animate"
|
|
|
|
}
|
|
|
|
onClick={linkEvent(
|
2023-06-14 12:20:40 +00:00
|
|
|
{ i: this, cv: cv },
|
2023-03-27 16:49:46 +00:00
|
|
|
this.handleEditEmojiClick
|
|
|
|
)}
|
2023-06-22 00:54:35 +00:00
|
|
|
data-tippy-content={I18NextService.i18n.t("save")}
|
|
|
|
aria-label={I18NextService.i18n.t("save")}
|
2023-03-27 16:49:46 +00:00
|
|
|
disabled={
|
2023-06-16 15:52:47 +00:00
|
|
|
this.props.loading ||
|
2023-03-27 16:49:46 +00:00
|
|
|
!this.canEdit(cv) ||
|
|
|
|
!cv.changed
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{/* <Icon
|
2022-11-27 18:02:32 +00:00
|
|
|
icon="edit"
|
|
|
|
classes={`icon-inline`}
|
|
|
|
/> */}
|
2023-03-27 16:49:46 +00:00
|
|
|
Save
|
|
|
|
</button>
|
|
|
|
</span>
|
|
|
|
<button
|
|
|
|
className="btn btn-link btn-animate text-muted"
|
|
|
|
onClick={linkEvent(
|
2023-06-14 12:20:40 +00:00
|
|
|
{ i: this, index: index, cv: cv },
|
2023-03-27 16:49:46 +00:00
|
|
|
this.handleDeleteEmojiClick
|
|
|
|
)}
|
2023-06-22 00:54:35 +00:00
|
|
|
data-tippy-content={I18NextService.i18n.t("delete")}
|
|
|
|
aria-label={I18NextService.i18n.t("delete")}
|
2023-06-16 15:52:47 +00:00
|
|
|
disabled={this.props.loading}
|
2023-06-22 00:54:35 +00:00
|
|
|
title={I18NextService.i18n.t("delete")}
|
2023-03-27 16:49:46 +00:00
|
|
|
>
|
|
|
|
<Icon
|
|
|
|
icon="trash"
|
|
|
|
classes={`icon-inline text-danger`}
|
|
|
|
/>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
))}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
<br />
|
|
|
|
<button
|
2023-06-20 12:01:29 +00:00
|
|
|
className="btn btn-sm btn-secondary me-2"
|
2023-03-27 16:49:46 +00:00
|
|
|
onClick={linkEvent(this, this.handleAddEmojiClick)}
|
|
|
|
>
|
2023-06-22 00:54:35 +00:00
|
|
|
{I18NextService.i18n.t("add_custom_emoji")}
|
2023-03-27 16:49:46 +00:00
|
|
|
</button>
|
2022-11-27 18:02:32 +00:00
|
|
|
|
2023-03-27 16:49:46 +00:00
|
|
|
<Paginator page={this.state.page} onChange={this.handlePageChange} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2022-11-27 18:02:32 +00:00
|
|
|
|
2023-03-27 16:49:46 +00:00
|
|
|
canEdit(cv: CustomEmojiViewForm) {
|
|
|
|
const noEmptyFields =
|
|
|
|
cv.alt_text.length > 0 &&
|
|
|
|
cv.category.length > 0 &&
|
|
|
|
cv.image_url.length > 0 &&
|
|
|
|
cv.shortcode.length > 0;
|
|
|
|
const noDuplicateShortCodes =
|
|
|
|
this.state.customEmojis.filter(
|
|
|
|
x => x.shortcode == cv.shortcode && x.id != cv.id
|
|
|
|
).length == 0;
|
|
|
|
return noEmptyFields && noDuplicateShortCodes;
|
|
|
|
}
|
2022-11-27 18:02:32 +00:00
|
|
|
|
2023-03-27 16:49:46 +00:00
|
|
|
getEditTooltip(cv: CustomEmojiViewForm) {
|
2023-06-22 00:54:35 +00:00
|
|
|
if (this.canEdit(cv)) return I18NextService.i18n.t("save");
|
|
|
|
else return I18NextService.i18n.t("custom_emoji_save_validation");
|
2023-03-27 16:49:46 +00:00
|
|
|
}
|
|
|
|
|
2023-05-15 19:53:29 +00:00
|
|
|
handlePageChange(page: number) {
|
2023-03-27 16:49:46 +00:00
|
|
|
this.setState({ page: page });
|
|
|
|
}
|
2022-11-27 18:02:32 +00:00
|
|
|
|
2023-03-27 16:49:46 +00:00
|
|
|
handleEmojiClick(e: any) {
|
|
|
|
const view = customEmojisLookup.get(e.id);
|
|
|
|
if (view) {
|
|
|
|
const page = this.state.customEmojis.find(
|
|
|
|
x => x.id == view.custom_emoji.id
|
|
|
|
)?.page;
|
|
|
|
if (page) {
|
2022-11-27 18:02:32 +00:00
|
|
|
this.setState({ page: page });
|
2023-03-27 16:49:46 +00:00
|
|
|
this.scrollRef[view.custom_emoji.shortcode].scrollIntoView();
|
|
|
|
}
|
2022-11-27 18:02:32 +00:00
|
|
|
}
|
2023-03-27 16:49:46 +00:00
|
|
|
}
|
2022-11-27 18:02:32 +00:00
|
|
|
|
2023-03-27 16:49:46 +00:00
|
|
|
handleEmojiCategoryChange(
|
|
|
|
props: { form: EmojiForm; index: number },
|
|
|
|
event: any
|
|
|
|
) {
|
2023-06-05 21:31:12 +00:00
|
|
|
const custom_emojis = [...props.form.state.customEmojis];
|
|
|
|
const pagedIndex =
|
2023-05-15 19:53:29 +00:00
|
|
|
(props.form.state.page - 1) * props.form.itemsPerPage + props.index;
|
2023-06-05 21:31:12 +00:00
|
|
|
const item = {
|
2023-05-15 19:53:29 +00:00
|
|
|
...props.form.state.customEmojis[pagedIndex],
|
2023-03-27 16:49:46 +00:00
|
|
|
category: event.target.value,
|
|
|
|
changed: true,
|
|
|
|
};
|
2023-05-11 18:32:32 +00:00
|
|
|
custom_emojis[Number(pagedIndex)] = item;
|
2023-03-27 16:49:46 +00:00
|
|
|
props.form.setState({ customEmojis: custom_emojis });
|
|
|
|
}
|
2022-11-27 18:02:32 +00:00
|
|
|
|
2023-03-27 16:49:46 +00:00
|
|
|
handleEmojiShortCodeChange(
|
|
|
|
props: { form: EmojiForm; index: number },
|
|
|
|
event: any
|
|
|
|
) {
|
2023-06-05 21:31:12 +00:00
|
|
|
const custom_emojis = [...props.form.state.customEmojis];
|
|
|
|
const pagedIndex =
|
2023-05-15 19:53:29 +00:00
|
|
|
(props.form.state.page - 1) * props.form.itemsPerPage + props.index;
|
2023-06-05 21:31:12 +00:00
|
|
|
const item = {
|
2023-05-15 19:53:29 +00:00
|
|
|
...props.form.state.customEmojis[pagedIndex],
|
2023-03-27 16:49:46 +00:00
|
|
|
shortcode: event.target.value,
|
|
|
|
changed: true,
|
|
|
|
};
|
2023-05-11 18:32:32 +00:00
|
|
|
custom_emojis[Number(pagedIndex)] = item;
|
2023-03-27 16:49:46 +00:00
|
|
|
props.form.setState({ customEmojis: custom_emojis });
|
|
|
|
}
|
2022-11-27 18:02:32 +00:00
|
|
|
|
2023-03-27 16:49:46 +00:00
|
|
|
handleEmojiImageUrlChange(
|
|
|
|
props: { form: EmojiForm; index: number; overrideValue: string | null },
|
|
|
|
event: any
|
|
|
|
) {
|
2023-06-05 21:31:12 +00:00
|
|
|
const custom_emojis = [...props.form.state.customEmojis];
|
|
|
|
const pagedIndex =
|
2023-05-15 19:53:29 +00:00
|
|
|
(props.form.state.page - 1) * props.form.itemsPerPage + props.index;
|
2023-06-05 21:31:12 +00:00
|
|
|
const item = {
|
2023-05-15 19:53:29 +00:00
|
|
|
...props.form.state.customEmojis[pagedIndex],
|
2023-03-27 16:49:46 +00:00
|
|
|
image_url: props.overrideValue ?? event.target.value,
|
|
|
|
changed: true,
|
|
|
|
};
|
2023-05-11 18:32:32 +00:00
|
|
|
custom_emojis[Number(pagedIndex)] = item;
|
2023-03-27 16:49:46 +00:00
|
|
|
props.form.setState({ customEmojis: custom_emojis });
|
|
|
|
}
|
2022-11-27 18:02:32 +00:00
|
|
|
|
2023-03-27 16:49:46 +00:00
|
|
|
handleEmojiAltTextChange(
|
|
|
|
props: { form: EmojiForm; index: number },
|
|
|
|
event: any
|
|
|
|
) {
|
2023-06-05 21:31:12 +00:00
|
|
|
const custom_emojis = [...props.form.state.customEmojis];
|
|
|
|
const pagedIndex =
|
2023-05-15 19:53:29 +00:00
|
|
|
(props.form.state.page - 1) * props.form.itemsPerPage + props.index;
|
2023-06-05 21:31:12 +00:00
|
|
|
const item = {
|
2023-05-15 19:53:29 +00:00
|
|
|
...props.form.state.customEmojis[pagedIndex],
|
2023-03-27 16:49:46 +00:00
|
|
|
alt_text: event.target.value,
|
|
|
|
changed: true,
|
|
|
|
};
|
2023-05-11 18:32:32 +00:00
|
|
|
custom_emojis[Number(pagedIndex)] = item;
|
2023-03-27 16:49:46 +00:00
|
|
|
props.form.setState({ customEmojis: custom_emojis });
|
|
|
|
}
|
2022-11-27 18:02:32 +00:00
|
|
|
|
2023-03-27 16:49:46 +00:00
|
|
|
handleEmojiKeywordChange(
|
|
|
|
props: { form: EmojiForm; index: number },
|
|
|
|
event: any
|
|
|
|
) {
|
2023-06-05 21:31:12 +00:00
|
|
|
const custom_emojis = [...props.form.state.customEmojis];
|
|
|
|
const pagedIndex =
|
2023-05-15 19:53:29 +00:00
|
|
|
(props.form.state.page - 1) * props.form.itemsPerPage + props.index;
|
2023-06-05 21:31:12 +00:00
|
|
|
const item = {
|
2023-05-15 19:53:29 +00:00
|
|
|
...props.form.state.customEmojis[pagedIndex],
|
2023-03-27 16:49:46 +00:00
|
|
|
keywords: event.target.value,
|
|
|
|
changed: true,
|
|
|
|
};
|
2023-05-11 18:32:32 +00:00
|
|
|
custom_emojis[Number(pagedIndex)] = item;
|
2023-03-27 16:49:46 +00:00
|
|
|
props.form.setState({ customEmojis: custom_emojis });
|
|
|
|
}
|
2022-11-27 18:02:32 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
handleDeleteEmojiClick(d: {
|
|
|
|
i: EmojiForm;
|
2023-03-27 16:49:46 +00:00
|
|
|
index: number;
|
|
|
|
cv: CustomEmojiViewForm;
|
|
|
|
}) {
|
2023-06-14 12:20:40 +00:00
|
|
|
const pagedIndex = (d.i.state.page - 1) * d.i.itemsPerPage + d.index;
|
|
|
|
if (d.cv.id != 0) {
|
|
|
|
d.i.props.onDelete({
|
|
|
|
id: d.cv.id,
|
|
|
|
auth: myAuthRequired(),
|
|
|
|
});
|
2023-03-27 16:49:46 +00:00
|
|
|
} else {
|
2023-06-14 12:20:40 +00:00
|
|
|
const custom_emojis = [...d.i.state.customEmojis];
|
2023-05-11 18:32:32 +00:00
|
|
|
custom_emojis.splice(Number(pagedIndex), 1);
|
2023-06-14 12:20:40 +00:00
|
|
|
d.i.setState({ customEmojis: custom_emojis });
|
2022-11-27 18:02:32 +00:00
|
|
|
}
|
2023-03-27 16:49:46 +00:00
|
|
|
}
|
2022-11-27 18:02:32 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
handleEditEmojiClick(d: { i: EmojiForm; cv: CustomEmojiViewForm }) {
|
|
|
|
const keywords = d.cv.keywords
|
2023-03-27 16:49:46 +00:00
|
|
|
.split(" ")
|
|
|
|
.filter(x => x.length > 0) as string[];
|
|
|
|
const uniqueKeywords = Array.from(new Set(keywords));
|
2023-06-14 12:20:40 +00:00
|
|
|
if (d.cv.id != 0) {
|
|
|
|
d.i.props.onEdit({
|
|
|
|
id: d.cv.id,
|
|
|
|
category: d.cv.category,
|
|
|
|
image_url: d.cv.image_url,
|
|
|
|
alt_text: d.cv.alt_text,
|
2023-03-27 16:49:46 +00:00
|
|
|
keywords: uniqueKeywords,
|
2023-06-14 12:20:40 +00:00
|
|
|
auth: myAuthRequired(),
|
|
|
|
});
|
2023-03-27 16:49:46 +00:00
|
|
|
} else {
|
2023-06-14 12:20:40 +00:00
|
|
|
d.i.props.onCreate({
|
|
|
|
category: d.cv.category,
|
|
|
|
shortcode: d.cv.shortcode,
|
|
|
|
image_url: d.cv.image_url,
|
|
|
|
alt_text: d.cv.alt_text,
|
2023-03-27 16:49:46 +00:00
|
|
|
keywords: uniqueKeywords,
|
2023-06-14 12:20:40 +00:00
|
|
|
auth: myAuthRequired(),
|
|
|
|
});
|
2022-11-27 18:02:32 +00:00
|
|
|
}
|
2023-03-27 16:49:46 +00:00
|
|
|
}
|
2022-11-27 18:02:32 +00:00
|
|
|
|
2023-03-27 16:49:46 +00:00
|
|
|
handleAddEmojiClick(form: EmojiForm, event: any) {
|
|
|
|
event.preventDefault();
|
2023-06-05 21:31:12 +00:00
|
|
|
const custom_emojis = [...form.state.customEmojis];
|
2023-05-15 19:53:29 +00:00
|
|
|
const page =
|
|
|
|
1 + Math.floor(form.state.customEmojis.length / form.itemsPerPage);
|
2023-06-05 21:31:12 +00:00
|
|
|
const item: CustomEmojiViewForm = {
|
2023-03-27 16:49:46 +00:00
|
|
|
id: 0,
|
|
|
|
shortcode: "",
|
|
|
|
alt_text: "",
|
|
|
|
category: "",
|
|
|
|
image_url: "",
|
|
|
|
keywords: "",
|
|
|
|
changed: true,
|
|
|
|
page: page,
|
|
|
|
};
|
|
|
|
custom_emojis.push(item);
|
|
|
|
form.setState({ customEmojis: custom_emojis, page: page });
|
|
|
|
}
|
2022-11-27 18:02:32 +00:00
|
|
|
|
2023-03-27 16:49:46 +00:00
|
|
|
handleImageUpload(props: { form: EmojiForm; index: number }, event: any) {
|
|
|
|
let file: any;
|
|
|
|
if (event.target) {
|
|
|
|
event.preventDefault();
|
|
|
|
file = event.target.files[0];
|
|
|
|
} else {
|
|
|
|
file = event;
|
2022-11-27 18:02:32 +00:00
|
|
|
}
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
HttpService.client.uploadImage({ image: file }).then(res => {
|
|
|
|
console.log("pictrs upload:");
|
|
|
|
console.log(res);
|
|
|
|
if (res.state === "success") {
|
|
|
|
if (res.data.msg === "ok") {
|
|
|
|
pictrsDeleteToast(file.name, res.data.delete_url as string);
|
2023-03-27 16:49:46 +00:00
|
|
|
} else {
|
|
|
|
toast(JSON.stringify(res), "danger");
|
2023-06-14 12:20:40 +00:00
|
|
|
const hash = res.data.files?.at(0)?.file;
|
|
|
|
const url = `${res.data.url}/${hash}`;
|
2023-03-27 16:49:46 +00:00
|
|
|
props.form.handleEmojiImageUrlChange(
|
|
|
|
{ form: props.form, index: props.index, overrideValue: url },
|
|
|
|
event
|
|
|
|
);
|
2022-11-27 18:02:32 +00:00
|
|
|
}
|
2023-06-14 12:20:40 +00:00
|
|
|
} else if (res.state === "failed") {
|
|
|
|
console.error(res.msg);
|
|
|
|
toast(res.msg, "danger");
|
|
|
|
}
|
|
|
|
});
|
2023-03-27 16:49:46 +00:00
|
|
|
}
|
2022-11-27 18:02:32 +00:00
|
|
|
|
2023-03-27 16:49:46 +00:00
|
|
|
configurePicker(): any {
|
|
|
|
return {
|
|
|
|
data: { categories: [], emojis: [], aliases: [] },
|
|
|
|
maxFrequentRows: 0,
|
|
|
|
dynamicWidth: true,
|
|
|
|
};
|
|
|
|
}
|
2022-11-27 18:02:32 +00:00
|
|
|
}
|