From 629f005ceff4f627073864488595c2c28893c770 Mon Sep 17 00:00:00 2001 From: Cyperghost Date: Thu, 19 Dec 2024 12:39:28 +0100 Subject: [PATCH] Add basic template for quote list --- ts/WoltLabSuite/Core/Api/Messages/Author.ts | 3 +- .../Core/Api/Messages/RenderQuote.ts | 3 +- ts/WoltLabSuite/Core/Component/Quote/List.ts | 52 ++++++++++++++++++- .../Core/Component/Quote/Storage.ts | 10 +++- .../WoltLabSuite/Core/Component/Quote/List.js | 49 ++++++++++++++++- .../core/messages/GetMessageAuthor.class.php | 3 +- .../core/messages/RenderQuote.class.php | 3 +- 7 files changed, 114 insertions(+), 9 deletions(-) diff --git a/ts/WoltLabSuite/Core/Api/Messages/Author.ts b/ts/WoltLabSuite/Core/Api/Messages/Author.ts index 8a850bc06f..2285cd63b6 100644 --- a/ts/WoltLabSuite/Core/Api/Messages/Author.ts +++ b/ts/WoltLabSuite/Core/Api/Messages/Author.ts @@ -15,7 +15,8 @@ type Response = { objectID: number; authorID: number; author: string; - time: number; + time: string; + title: string; link: string; avatar: string; }; diff --git a/ts/WoltLabSuite/Core/Api/Messages/RenderQuote.ts b/ts/WoltLabSuite/Core/Api/Messages/RenderQuote.ts index 11fda558e1..85195f9474 100644 --- a/ts/WoltLabSuite/Core/Api/Messages/RenderQuote.ts +++ b/ts/WoltLabSuite/Core/Api/Messages/RenderQuote.ts @@ -15,8 +15,9 @@ type Response = { objectID: number; authorID: number; author: string; - time: number; + time: string; link: string; + title: string; avatar: string; message: string; }; diff --git a/ts/WoltLabSuite/Core/Component/Quote/List.ts b/ts/WoltLabSuite/Core/Component/Quote/List.ts index b047baacf7..83ff19aa22 100644 --- a/ts/WoltLabSuite/Core/Component/Quote/List.ts +++ b/ts/WoltLabSuite/Core/Component/Quote/List.ts @@ -13,7 +13,8 @@ import type { CKEditor } from "WoltLabSuite/Core/Component/Ckeditor"; import { getTabMenu } from "WoltLabSuite/Core/Component/Message/MessageTabMenu"; import { getPhrase } from "WoltLabSuite/Core/Language"; import { setActiveEditor } from "WoltLabSuite/Core/Component/Quote/Message"; -import { getQuotes } from "WoltLabSuite/Core/Component/Quote/Storage"; +import { getQuotes, getMessage } from "WoltLabSuite/Core/Component/Quote/Storage"; +import DomUtil from "WoltLabSuite/Core/Dom/Util"; const quoteLists = new Map(); @@ -40,7 +41,54 @@ class QuoteList { public renderQuotes(): void { this.#container.innerHTML = ""; - for (const [, quotes] of getQuotes()) { + for (const [key, quotes] of getQuotes()) { + const message = getMessage(key)!; + + // TODO escape values + // TODO create web components??? + this.#container.append( + DomUtil.createFragmentFromHtml(`
+
+
+
+ + +
+

+ ${message.title} +

+ +
+
+
+
+
+
    + ${Array.from(quotes) + .map( + (quote) => `
  • + + + + + +
    + ${quote} +
    +
  • `, + ) + .join("")} +
+
+
+
+
`), + ); // TODO render quotes } diff --git a/ts/WoltLabSuite/Core/Component/Quote/Storage.ts b/ts/WoltLabSuite/Core/Component/Quote/Storage.ts index 78b74ba854..788894b304 100644 --- a/ts/WoltLabSuite/Core/Component/Quote/Storage.ts +++ b/ts/WoltLabSuite/Core/Component/Quote/Storage.ts @@ -14,7 +14,8 @@ import { messageAuthor } from "WoltLabSuite/Core/Api/Messages/Author"; interface Message { objectID: number; - time: number; + time: string; + title: string; link: string; authorID: number; author: string; @@ -50,6 +51,7 @@ export async function saveFullQuote(objectType: string, objectClassName: string, { objectID: result.value.objectID, time: result.value.time, + title: result.value.title, link: result.value.link, authorID: result.value.authorID, author: result.value.author, @@ -78,6 +80,12 @@ export function getQuotes(): Map> { return getStorage().quotes; } +export function getMessage(objectType: string, objectId?: number): Message | undefined { + const key = objectId ? getKey(objectType, objectId) : objectType; + + return getStorage().messages.get(key); +} + function getStorage(): StorageData { const data = window.localStorage.getItem(STORAGE_KEY); if (data === null) { diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Quote/List.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Quote/List.js index a7a080d342..9cb14f1db3 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Quote/List.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Quote/List.js @@ -7,11 +7,12 @@ * @since 6.2 * @woltlabExcludeBundle tiny */ -define(["require", "exports", "WoltLabSuite/Core/Component/Ckeditor/Event", "WoltLabSuite/Core/Component/Message/MessageTabMenu", "WoltLabSuite/Core/Language", "WoltLabSuite/Core/Component/Quote/Message", "WoltLabSuite/Core/Component/Quote/Storage"], function (require, exports, Event_1, MessageTabMenu_1, Language_1, Message_1, Storage_1) { +define(["require", "exports", "tslib", "WoltLabSuite/Core/Component/Ckeditor/Event", "WoltLabSuite/Core/Component/Message/MessageTabMenu", "WoltLabSuite/Core/Language", "WoltLabSuite/Core/Component/Quote/Message", "WoltLabSuite/Core/Component/Quote/Storage", "WoltLabSuite/Core/Dom/Util"], function (require, exports, tslib_1, Event_1, MessageTabMenu_1, Language_1, Message_1, Storage_1, Util_1) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getQuoteList = getQuoteList; exports.setup = setup; + Util_1 = tslib_1.__importDefault(Util_1); const quoteLists = new Map(); class QuoteList { #container; @@ -31,7 +32,51 @@ define(["require", "exports", "WoltLabSuite/Core/Component/Ckeditor/Event", "Wol } renderQuotes() { this.#container.innerHTML = ""; - for (const [, quotes] of (0, Storage_1.getQuotes)()) { + for (const [key, quotes] of (0, Storage_1.getQuotes)()) { + const message = (0, Storage_1.getMessage)(key); + // TODO escape values + // TODO create web components??? + this.#container.append(Util_1.default.createFragmentFromHtml(`
+
+
+
+ + +
+

+ ${message.title} +

+ +
+
+
+
+
+
    + ${Array.from(quotes) + .map((quote) => `
  • + + + + + +
    + +
    +
  • `) + .join("")} +
+
+
+
+
`)); // TODO render quotes } if (this.#container.hasChildNodes()) { diff --git a/wcfsetup/install/files/lib/system/endpoint/controller/core/messages/GetMessageAuthor.class.php b/wcfsetup/install/files/lib/system/endpoint/controller/core/messages/GetMessageAuthor.class.php index e378a79dd8..a6022686fc 100644 --- a/wcfsetup/install/files/lib/system/endpoint/controller/core/messages/GetMessageAuthor.class.php +++ b/wcfsetup/install/files/lib/system/endpoint/controller/core/messages/GetMessageAuthor.class.php @@ -37,8 +37,9 @@ final class GetMessageAuthor implements IController "objectID" => $object->getObjectID(), "authorID" => $userProfile->getUserID(), "author" => $userProfile->getUsername(), + "title" => $object->getTitle(), "avatar" => $userProfile->getAvatar()->getURL(), - "time" => $object->getTime(), + "time" => (new \DateTime('@' . $object->getTime()))->format("c"), "link" => $object->getLink(), ], 200, diff --git a/wcfsetup/install/files/lib/system/endpoint/controller/core/messages/RenderQuote.class.php b/wcfsetup/install/files/lib/system/endpoint/controller/core/messages/RenderQuote.class.php index e6868a7fbf..21c1103cb2 100644 --- a/wcfsetup/install/files/lib/system/endpoint/controller/core/messages/RenderQuote.class.php +++ b/wcfsetup/install/files/lib/system/endpoint/controller/core/messages/RenderQuote.class.php @@ -40,7 +40,8 @@ final class RenderQuote implements IController "authorID" => $userProfile->getUserID(), "author" => $userProfile->getUsername(), "avatar" => $userProfile->getAvatar()->getURL(), - "time" => $object->getTime(), + "time" => (new \DateTime('@' . $object->getTime()))->format("c"), + "title" => $object->getTitle(), "link" => $object->getLink(), "message" => $parameters->fullQuote ? $this->renderFullQuote($object) : "" ], -- 2.20.1