From 5ab6745a247977171b21efb0cca3d49f7f6bc3e8 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Wed, 28 Feb 2024 16:43:07 +0000 Subject: [PATCH] fix: update preview post-save --- src/ts/admin/EditBlogPost.ts | 2 ++ src/ts/admin/MarkdownEditor/Prism.d.ts | 2 +- src/ts/admin/MarkdownEditor/UI.ts | 12 ++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/ts/admin/EditBlogPost.ts b/src/ts/admin/EditBlogPost.ts index 4156d4e..951d043 100644 --- a/src/ts/admin/EditBlogPost.ts +++ b/src/ts/admin/EditBlogPost.ts @@ -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); } diff --git a/src/ts/admin/MarkdownEditor/Prism.d.ts b/src/ts/admin/MarkdownEditor/Prism.d.ts index b3e9cc8..3775222 100644 --- a/src/ts/admin/MarkdownEditor/Prism.d.ts +++ b/src/ts/admin/MarkdownEditor/Prism.d.ts @@ -10,4 +10,4 @@ declare interface Prism { highlightAllUnder(element: HTMLElement): void; } -declare const Prism: Prism; \ No newline at end of file +declare const Prism: Prism; diff --git a/src/ts/admin/MarkdownEditor/UI.ts b/src/ts/admin/MarkdownEditor/UI.ts index 06a35e4..16cf188 100644 --- a/src/ts/admin/MarkdownEditor/UI.ts +++ b/src/ts/admin/MarkdownEditor/UI.ts @@ -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.