From ef51434f59c4d26506469bc12eb0bc39ce8b9fb3 Mon Sep 17 00:00:00 2001 From: Peter Lohse Date: Fri, 16 Aug 2024 10:34:02 +0200 Subject: [PATCH] split typescript classes --- .../js/Hanashi/Faq/Api/Questions/GetSearch.js | 17 +++++++++++++++++ .../Hanashi/Faq/Api/Questions/RenderSearch.js | 16 ++++++++++++++++ files/js/Hanashi/Faq/BBCode.js | 6 +++--- .../Api/Questions/{Search.ts => GetSearch.ts} | 13 ------------- ts/Hanashi/Faq/Api/Questions/RenderSearch.ts | 19 +++++++++++++++++++ ts/Hanashi/Faq/BBCode.ts | 3 ++- 6 files changed, 57 insertions(+), 17 deletions(-) create mode 100644 files/js/Hanashi/Faq/Api/Questions/GetSearch.js create mode 100644 files/js/Hanashi/Faq/Api/Questions/RenderSearch.js rename ts/Hanashi/Faq/Api/Questions/{Search.ts => GetSearch.ts} (62%) create mode 100644 ts/Hanashi/Faq/Api/Questions/RenderSearch.ts diff --git a/files/js/Hanashi/Faq/Api/Questions/GetSearch.js b/files/js/Hanashi/Faq/Api/Questions/GetSearch.js new file mode 100644 index 0000000..baf0d5f --- /dev/null +++ b/files/js/Hanashi/Faq/Api/Questions/GetSearch.js @@ -0,0 +1,17 @@ +define(["require", "exports", "WoltLabSuite/Core/Ajax/Backend", "WoltLabSuite/Core/Api/Result"], function (require, exports, Backend_1, Result_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.searchQuestions = searchQuestions; + async function searchQuestions(query) { + const url = new URL(`${window.WSC_API_URL}index.php?api/rpc/faq/questions/search`); + url.searchParams.set("query", query); + let response; + try { + response = (await (0, Backend_1.prepareRequest)(url).get().fetchAsJson()); + } + catch (e) { + return (0, Result_1.apiResultFromError)(e); + } + return (0, Result_1.apiResultFromValue)(response); + } +}); diff --git a/files/js/Hanashi/Faq/Api/Questions/RenderSearch.js b/files/js/Hanashi/Faq/Api/Questions/RenderSearch.js new file mode 100644 index 0000000..8c97ec9 --- /dev/null +++ b/files/js/Hanashi/Faq/Api/Questions/RenderSearch.js @@ -0,0 +1,16 @@ +define(["require", "exports", "WoltLabSuite/Core/Ajax/Backend", "WoltLabSuite/Core/Api/Result"], function (require, exports, Backend_1, Result_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.renderSearch = renderSearch; + async function renderSearch() { + const url = new URL(`${window.WSC_API_URL}index.php?api/rpc/faq/questions/search/render`); + let response; + try { + response = (await (0, Backend_1.prepareRequest)(url).get().fetchAsJson()); + } + catch (e) { + return (0, Result_1.apiResultFromError)(e); + } + return (0, Result_1.apiResultFromValue)(response); + } +}); diff --git a/files/js/Hanashi/Faq/BBCode.js b/files/js/Hanashi/Faq/BBCode.js index c2607ea..d6a4184 100644 --- a/files/js/Hanashi/Faq/BBCode.js +++ b/files/js/Hanashi/Faq/BBCode.js @@ -1,4 +1,4 @@ -define(["require", "exports", "tslib", "WoltLabSuite/Core/Component/Ckeditor/Event", "WoltLabSuite/Core/Component/Dialog", "WoltLabSuite/Core/Dom/Util", "WoltLabSuite/Core/Language", "./Api/Questions/Search"], function (require, exports, tslib_1, Event_1, Dialog_1, Util_1, Language, Search_1) { +define(["require", "exports", "tslib", "WoltLabSuite/Core/Component/Ckeditor/Event", "WoltLabSuite/Core/Component/Dialog", "WoltLabSuite/Core/Dom/Util", "WoltLabSuite/Core/Language", "./Api/Questions/GetSearch", "./Api/Questions/RenderSearch"], function (require, exports, tslib_1, Event_1, Dialog_1, Util_1, Language, GetSearch_1, RenderSearch_1) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FaqBBCode = void 0; @@ -29,7 +29,7 @@ define(["require", "exports", "tslib", "WoltLabSuite/Core/Component/Ckeditor/Eve }); } async openDialog(ckeditor) { - const inputResponse = await (0, Search_1.renderSearch)(); + const inputResponse = await (0, RenderSearch_1.renderSearch)(); if (!inputResponse.ok) { return; } @@ -67,7 +67,7 @@ define(["require", "exports", "tslib", "WoltLabSuite/Core/Component/Ckeditor/Eve Util_1.default.innerError(inputContainer, false); } } - const inputResponse = await (0, Search_1.searchQuestions)(value); + const inputResponse = await (0, GetSearch_1.searchQuestions)(value); if (!inputResponse.ok) { return; } diff --git a/ts/Hanashi/Faq/Api/Questions/Search.ts b/ts/Hanashi/Faq/Api/Questions/GetSearch.ts similarity index 62% rename from ts/Hanashi/Faq/Api/Questions/Search.ts rename to ts/Hanashi/Faq/Api/Questions/GetSearch.ts index ad30d27..4d39873 100644 --- a/ts/Hanashi/Faq/Api/Questions/Search.ts +++ b/ts/Hanashi/Faq/Api/Questions/GetSearch.ts @@ -5,19 +5,6 @@ type Response = { template: string; }; -export async function renderSearch(): Promise> { - const url = new URL(`${window.WSC_API_URL}index.php?api/rpc/faq/questions/search/render`); - - let response: Response; - try { - response = (await prepareRequest(url).get().fetchAsJson()) as Response; - } catch (e) { - return apiResultFromError(e); - } - - return apiResultFromValue(response); -} - export async function searchQuestions(query: string): Promise> { const url = new URL(`${window.WSC_API_URL}index.php?api/rpc/faq/questions/search`); url.searchParams.set("query", query); diff --git a/ts/Hanashi/Faq/Api/Questions/RenderSearch.ts b/ts/Hanashi/Faq/Api/Questions/RenderSearch.ts new file mode 100644 index 0000000..56b029e --- /dev/null +++ b/ts/Hanashi/Faq/Api/Questions/RenderSearch.ts @@ -0,0 +1,19 @@ +import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend"; +import { ApiResult, apiResultFromError, apiResultFromValue } from "WoltLabSuite/Core/Api/Result"; + +type Response = { + template: string; +}; + +export async function renderSearch(): Promise> { + const url = new URL(`${window.WSC_API_URL}index.php?api/rpc/faq/questions/search/render`); + + let response: Response; + try { + response = (await prepareRequest(url).get().fetchAsJson()) as Response; + } catch (e) { + return apiResultFromError(e); + } + + return apiResultFromValue(response); +} diff --git a/ts/Hanashi/Faq/BBCode.ts b/ts/Hanashi/Faq/BBCode.ts index 00f7f7e..590e5dd 100644 --- a/ts/Hanashi/Faq/BBCode.ts +++ b/ts/Hanashi/Faq/BBCode.ts @@ -4,7 +4,8 @@ import { listenToCkeditor } from "WoltLabSuite/Core/Component/Ckeditor/Event"; import { dialogFactory } from "WoltLabSuite/Core/Component/Dialog"; import DomUtil from "WoltLabSuite/Core/Dom/Util"; import * as Language from "WoltLabSuite/Core/Language"; -import { renderSearch, searchQuestions } from "./Api/Questions/Search"; +import { searchQuestions } from "./Api/Questions/GetSearch"; +import { renderSearch } from "./Api/Questions/RenderSearch"; export class FaqBBCode { private dialog: WoltlabCoreDialogElement;