From 1f12753c6870fbe69d83d4dfbe155a61d2b292c2 Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Mon, 22 May 2023 01:23:08 +0800 Subject: [PATCH] chore: mobile export image style --- app/components/exporter.tsx | 40 ++++++++++----- app/components/message-selector.module.scss | 25 ++++++++- app/components/message-selector.tsx | 56 +++++++++++---------- 3 files changed, 79 insertions(+), 42 deletions(-) diff --git a/app/components/exporter.tsx b/app/components/exporter.tsx index 8f38be0f..1465d89a 100644 --- a/app/components/exporter.tsx +++ b/app/components/exporter.tsx @@ -3,7 +3,7 @@ import Locale from "../locales"; import styles from "./exporter.module.scss"; import { List, ListItem, Modal, showToast } from "./ui-lib"; import { IconButton } from "./button"; -import { copyToClipboard, downloadAs } from "../utils"; +import { copyToClipboard, downloadAs, useMobileScreen } from "../utils"; import CopyIcon from "../icons/copy.svg"; import LoadingIcon from "../icons/three-dots.svg"; @@ -222,16 +222,19 @@ export function MessageExporter() { export function PreviewActions(props: { download: () => void; copy: () => void; + showCopy?: boolean; }) { return (
- } - onClick={props.copy} - > + {props.showCopy && ( + } + onClick={props.copy} + > + )} { const dom = previewRef.current; if (!dom) return; toPng(dom) .then((blob) => { if (!blob) return; - const link = document.createElement("a"); - link.download = `${props.topic}.png`; - link.href = blob; - link.click(); + + if (isMobile) { + const image = new Image(); + image.src = blob; + const win = window.open(""); + win?.document.write(image.outerHTML); + } else { + const link = document.createElement("a"); + link.download = `${props.topic}.png`; + link.href = blob; + link.click(); + } }) .catch((e) => console.log("[Export Image] ", e)); }; return (
- +
- - - props.updateSelection((selection) => { - selection.clear(); - messages - .slice(messageCount - 10) - .forEach((m) => selection.add(m.id!)); - }) - } - /> - - props.updateSelection((selection) => selection.clear()) - } - /> +
+ + + props.updateSelection((selection) => { + selection.clear(); + messages + .slice(messageCount - 10) + .forEach((m) => selection.add(m.id!)); + }) + } + /> + + props.updateSelection((selection) => selection.clear()) + } + /> +