From 28162e655af81e9d47864c4d476ce47bda47b7f7 Mon Sep 17 00:00:00 2001 From: Christian Fehmer Date: Sun, 31 May 2026 20:13:14 +0200 Subject: [PATCH] feat: download custom texts (@fehmer) --- .../ts/components/modals/SavedTextsModal.tsx | 31 +++++++++++++++++++ frontend/src/ts/test/test-screenshot.ts | 19 +++--------- frontend/src/ts/utils/misc.ts | 16 ++++++---- 3 files changed, 46 insertions(+), 20 deletions(-) diff --git a/frontend/src/ts/components/modals/SavedTextsModal.tsx b/frontend/src/ts/components/modals/SavedTextsModal.tsx index c8baed8a7142..451be1bef6c0 100644 --- a/frontend/src/ts/components/modals/SavedTextsModal.tsx +++ b/frontend/src/ts/components/modals/SavedTextsModal.tsx @@ -2,8 +2,13 @@ import { createSignal, For, Index, JSXElement, Setter, Show } from "solid-js"; import * as CustomTextState from "../../legacy-states/custom-text-name"; import { hideModal } from "../../states/modals"; +import { + showErrorNotification, + showSuccessNotification, +} from "../../states/notifications"; import { showSimpleModal } from "../../states/simple-modal"; import * as CustomText from "../../test/custom-text"; +import { download } from "../../utils/misc"; import { AnimatedModal } from "../common/AnimatedModal"; import { Button } from "../common/Button"; import { Separator } from "../common/Separator"; @@ -81,6 +86,18 @@ export function SavedTextsModal(props: { }); }; + const handleDownload = (name: string, long: boolean) => { + const text = CustomText.getCustomText(name, long); + + try { + const data = new Blob([text.join(" ")], { type: "text/plain" }); + download({ filename: `${name}.txt`, data }); + showSuccessNotification("custom text downloaded"); + } catch (e) { + showErrorNotification(`failed to download custom text: ${e}`); + } + }; + return ( handleNameClick(name, false)} /> +