Merge pull request #1679 from Yidadaa/export

chore: mobile export image style
This commit is contained in:
Yifei Zhang 2023-05-22 01:25:49 +08:00 committed by GitHub
commit f0b4ef5917
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 79 additions and 42 deletions

View File

@ -3,7 +3,7 @@ import Locale from "../locales";
import styles from "./exporter.module.scss"; import styles from "./exporter.module.scss";
import { List, ListItem, Modal, showToast } from "./ui-lib"; import { List, ListItem, Modal, showToast } from "./ui-lib";
import { IconButton } from "./button"; import { IconButton } from "./button";
import { copyToClipboard, downloadAs } from "../utils"; import { copyToClipboard, downloadAs, useMobileScreen } from "../utils";
import CopyIcon from "../icons/copy.svg"; import CopyIcon from "../icons/copy.svg";
import LoadingIcon from "../icons/three-dots.svg"; import LoadingIcon from "../icons/three-dots.svg";
@ -222,9 +222,11 @@ export function MessageExporter() {
export function PreviewActions(props: { export function PreviewActions(props: {
download: () => void; download: () => void;
copy: () => void; copy: () => void;
showCopy?: boolean;
}) { }) {
return ( return (
<div className={styles["preview-actions"]}> <div className={styles["preview-actions"]}>
{props.showCopy && (
<IconButton <IconButton
text={Locale.Export.Copy} text={Locale.Export.Copy}
bordered bordered
@ -232,6 +234,7 @@ export function PreviewActions(props: {
icon={<CopyIcon />} icon={<CopyIcon />}
onClick={props.copy} onClick={props.copy}
></IconButton> ></IconButton>
)}
<IconButton <IconButton
text={Locale.Export.Download} text={Locale.Export.Download}
bordered bordered
@ -282,23 +285,34 @@ export function ImagePreviewer(props: {
} }
}); });
}; };
const isMobile = useMobileScreen();
const download = () => { const download = () => {
const dom = previewRef.current; const dom = previewRef.current;
if (!dom) return; if (!dom) return;
toPng(dom) toPng(dom)
.then((blob) => { .then((blob) => {
if (!blob) return; if (!blob) return;
if (isMobile) {
const image = new Image();
image.src = blob;
const win = window.open("");
win?.document.write(image.outerHTML);
} else {
const link = document.createElement("a"); const link = document.createElement("a");
link.download = `${props.topic}.png`; link.download = `${props.topic}.png`;
link.href = blob; link.href = blob;
link.click(); link.click();
}
}) })
.catch((e) => console.log("[Export Image] ", e)); .catch((e) => console.log("[Export Image] ", e));
}; };
return ( return (
<div className={styles["image-previewer"]}> <div className={styles["image-previewer"]}>
<PreviewActions copy={copy} download={download} /> <PreviewActions copy={copy} download={download} showCopy={!isMobile} />
<div <div
className={`${styles["preview-body"]} ${styles["default-theme"]}`} className={`${styles["preview-body"]} ${styles["default-theme"]}`}
ref={previewRef} ref={previewRef}

View File

@ -5,13 +5,34 @@
.search-bar { .search-bar {
max-width: unset; max-width: unset;
flex-grow: 1; flex-grow: 1;
margin-right: 10px;
} }
.filter-item:not(:last-child) { .actions {
display: flex;
button:not(:last-child) {
margin-right: 10px; margin-right: 10px;
} }
} }
@media screen and (max-width: 600px) {
flex-direction: column;
.search-bar {
margin-right: 0;
}
.actions {
margin-top: 20px;
button {
flex-grow: 1;
}
}
}
}
.messages { .messages {
margin-top: 20px; margin-top: 20px;
border-radius: 10px; border-radius: 10px;

View File

@ -140,6 +140,7 @@ export function MessageSelector(props: {
}} }}
></input> ></input>
<div className={styles["actions"]}>
<IconButton <IconButton
text={Locale.Select.All} text={Locale.Select.All}
bordered bordered
@ -168,6 +169,7 @@ export function MessageSelector(props: {
} }
/> />
</div> </div>
</div>
<div className={styles["messages"]}> <div className={styles["messages"]}>
{messages.map((m, i) => { {messages.map((m, i) => {