archiveTodayUrl,
capitalizeFirstLetter,
communityToChoice,
- debounce,
fetchCommunities,
getIdFromString,
ghostArchiveUrl,
isImage,
myAuth,
myAuthRequired,
- pictrsDeleteToast,
relTags,
setupTippy,
toast,
validURL,
webArchiveUrl,
} from "../../utils";
+import { debounce } from "../../utils/helpers/debounce";
import { Icon, Spinner } from "../common/icon";
import { LanguageSelect } from "../common/language-select";
import { MarkdownTextArea } from "../common/markdown-textarea";
suggestedPostsRes: RequestState<SearchResponse>;
metadataRes: RequestState<GetSiteMetadataResponse>;
imageLoading: boolean;
+ imageDeleteUrl: string;
communitySearchLoading: boolean;
communitySearchOptions: Choice[];
previewMode: boolean;
form: {},
loading: false,
imageLoading: false,
+ imageDeleteUrl: "",
communitySearchLoading: false,
previewMode: false,
communitySearchOptions: [],
{url && isImage(url) && (
<img src={url} className="img-fluid" alt="" />
)}
+ {this.state.imageDeleteUrl && (
+ <button
+ className="btn btn-danger btn-sm mt-2"
+ onClick={linkEvent(this, this.handleImageDelete)}
+ aria-label={i18n.t("delete")}
+ data-tippy-content={i18n.t("delete")}
+ >
+ <Icon icon="x" classes="icon-inline mr-1" />
+ {capitalizeFirstLetter(i18n.t("delete"))}
+ </button>
+ )}
{this.props.crossPosts && this.props.crossPosts.length > 0 && (
<>
<div className="my-1 text-muted small font-weight-bold">
}
handlePostUrlChange(i: PostForm, event: any) {
- i.setState(s => ((s.form.url = event.target.value), s));
+ const url = event.target.value;
+
+ i.setState({
+ form: {
+ url,
+ },
+ imageDeleteUrl: "",
+ });
+
i.fetchPageTitle();
}
if (res.state === "success") {
if (res.data.msg === "ok") {
i.state.form.url = res.data.url;
- pictrsDeleteToast(file.name, res.data.delete_url as string);
- i.setState({ imageLoading: false });
+ i.setState({
+ imageLoading: false,
+ imageDeleteUrl: res.data.delete_url as string,
+ });
} else {
toast(JSON.stringify(res), "danger");
}
} else if (res.state === "failed") {
console.error(res.msg);
toast(res.msg, "danger");
+ i.setState({ imageLoading: false });
}
});
}
+ handleImageDelete(i: PostForm) {
+ const { imageDeleteUrl } = i.state;
+
+ fetch(imageDeleteUrl);
+
+ i.setState({
+ imageDeleteUrl: "",
+ imageLoading: false,
+ form: {
+ url: "",
+ },
+ });
+ }
+
handleCommunitySearch = debounce(async (text: string) => {
const { selectedCommunityChoice } = this.props;
this.setState({ communitySearchLoading: true });