diff --git a/Wave/Assets/React/ArticleEditor.tsx b/Wave/Assets/React/ArticleEditor.tsx
index c2b1fa4..f4d5982 100644
--- a/Wave/Assets/React/ArticleEditor.tsx
+++ b/Wave/Assets/React/ArticleEditor.tsx
@@ -1,5 +1,5 @@
import React, { useState, useEffect, useRef } from "react";
-import { updateCharactersLeft, insertBeforeSelection, insertBeforeAndAfterSelection } from "../utilities/md_functions";
+import { updateCharactersLeft } from "../utilities/md_functions";
import { LabelInput, ToolBarButton } from "./Forms";
import ImageEditor from "./ImageEditor";
import { CategoryColor, Category, ArticleStatus, ArticleView, ArticleDto } from "../model/Models";
@@ -215,8 +215,8 @@ export default function Editor() {
{t("Published")}
- setImageDialog(false)} callback={(location) => {
- textAreaMarkdown.current?.append(`\n![](${location})\n`)
+ setImageDialog(false)} callback={(location, description) => {
+ textAreaMarkdown.current?.append(`\n![${description}](${location})\n`)
setImageDialog(false)
}} />
diff --git a/Wave/Assets/React/ImageEditor.tsx b/Wave/Assets/React/ImageEditor.tsx
index e54dd78..c90bb3a 100644
--- a/Wave/Assets/React/ImageEditor.tsx
+++ b/Wave/Assets/React/ImageEditor.tsx
@@ -1,33 +1,93 @@
-import React, {useEffect} from "react";
+import React, {ChangeEvent, useEffect, useState} from "react";
import Modal from "./Modal";
-const ImageEditor = function({open = false, onClose, callback}: {open: boolean, onClose: () => void, callback: (location: string) => void}){
+interface ImageEditorProperties {
+ open: boolean,
+ onClose: () => void,
+ callback: (location: string, description?: string) => void,
+ t: any
+}
+
+const ImageEditor = function({open = false, onClose, callback, t}: ImageEditorProperties){
+ const [busy, setBusy] = useState(false);
+ const [file, setFile] = useState("");
+
async function onSubmit(event: React.FormEvent) {
event.preventDefault();
+ const elem = event.target as HTMLFormElement;
+ const fileElem = elem.file as HTMLInputElement;
+ if (fileElem.value.length < 1) return;
- const formData = new FormData(event.target as HTMLFormElement);
- let response = await fetch("/images/create", {
- method: "PUT",
- body: formData
- })
- if (!response.ok) {
- throw new Error(response.statusText);
+ if (busy) return;
+ setBusy(true);
+
+ try {
+ const formData = new FormData(elem);
+ let response = await fetch("/images/create", {
+ method: "PUT",
+ body: formData
+ })
+ if (!response.ok) {
+ throw new Error(response.statusText);
+ }
+
+ (event.target as HTMLFormElement)?.reset()
+ setFile("")
+
+ const loc = response.headers.get("Location") as string;
+ callback(loc, formData.get("imageAlt") as string);
+ } finally {
+ setBusy(false);
}
+ }
- (event.target as HTMLFormElement)?.reset()
-
- const loc = response.headers.get("Location") as string;
- callback(loc);
+ function onImageChange(event: ChangeEvent) {
+ const fileInput = event.target as HTMLInputElement;
+ if (!fileInput || !fileInput.files || fileInput.files.length < 1) return;
+ setFile(URL.createObjectURL(fileInput.files[0]));
}
return (
-
-