fix: update preview post-save

This commit is contained in:
Oliver Booth 2024-02-28 16:43:07 +00:00
parent e800504651
commit 5ab6745a24
Signed by: oliverbooth
GPG Key ID: E60B570D1B7557B5
3 changed files with 15 additions and 1 deletions

View File

@ -25,6 +25,8 @@ import SaveButtonMode from "./MarkdownEditor/SaveButtonMode";
await Interop.invoke("Save", post.id, UI.markdownInput.value);
post = await API.getBlogPost(post.id);
UI.setSaveButtonMode(SaveButtonMode.SAVED);
UI.setPreviewContent(post.content);
UI.redraw();
setTimeout(() => UI.setSaveButtonMode(SaveButtonMode.NORMAL), 2000);
}

View File

@ -1,3 +1,4 @@
import SharedUI from "../../app/UI";
import SaveButtonMode from "./SaveButtonMode";
/**
@ -12,6 +13,7 @@ class UI {
private static _highlighting: HTMLElement;
private static _content: HTMLTextAreaElement;
private static _saveButton: HTMLButtonElement;
private static _preview: HTMLElement;
private static _saveCallbacks: Function[] = [];
@ -38,6 +40,7 @@ class UI {
* Initializes the editor's user interface.
*/
public static init() {
UI._preview = document.getElementById("article-preview");
UI._saveButton = document.getElementById("save-button") as HTMLButtonElement;
UI._content = document.getElementById("content") as HTMLTextAreaElement;
UI._highlightingContent = document.getElementById("highlighting-content");
@ -76,6 +79,15 @@ class UI {
UI.syncEditorScroll();
}
/**
* Sets the HTML content of the preview section.
* @param html The HTML content.
*/
public static setPreviewContent(html: string): void {
UI._preview.innerHTML = html;
SharedUI.updateUI(UI._preview);
}
/**
* Sets the display mode of the save button.
* @param mode The display mode.