refactor: update UI to use new client uploadImage function (#967)

Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
This commit is contained in:
SleeplessOne1917 2023-03-26 22:06:42 -04:00 committed by GitHub
parent b7a391f66e
commit 47daa9d143
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 62 additions and 77 deletions

View file

@ -1,8 +1,7 @@
import { Component, linkEvent } from "inferno";
import { pictrsUri } from "../../env";
import { i18n } from "../../i18next";
import { UserService } from "../../services";
import { randomStr, toast } from "../../utils";
import { randomStr, toast, uploadImage } from "../../utils";
import { Icon } from "./icon";
interface ImageUploadFormProps {
@ -74,25 +73,17 @@ export class ImageUploadForm extends Component<
handleImageUpload(i: ImageUploadForm, event: any) {
event.preventDefault();
let file = event.target.files[0];
const formData = new FormData();
formData.append("images[]", file);
const file = event.target.files[0];
i.setState({ loading: true });
fetch(pictrsUri, {
method: "POST",
body: formData,
})
.then(res => res.json())
uploadImage(file)
.then(res => {
console.log("pictrs upload:");
console.log(res);
if (res.msg == "ok") {
let hash = res.files[0].file;
let url = `${pictrsUri}/${hash}`;
if (res.msg === "ok") {
i.setState({ loading: false });
i.props.onUpload(url);
i.props.onUpload(res.url as string);
} else {
i.setState({ loading: false });
toast(JSON.stringify(res), "danger");