Skip to content

Commit

Permalink
Merge pull request ChatGPTNextWeb#1679 from Yidadaa/export
Browse files Browse the repository at this point in the history
chore: mobile export image style
  • Loading branch information
Yidadaa committed May 21, 2023
2 parents 0439d12 + 1f12753 commit f0b4ef5
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 42 deletions.
40 changes: 27 additions & 13 deletions app/components/exporter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -222,16 +222,19 @@ export function MessageExporter() {
export function PreviewActions(props: {
download: () => void;
copy: () => void;
showCopy?: boolean;
}) {
return (
<div className={styles["preview-actions"]}>
<IconButton
text={Locale.Export.Copy}
bordered
shadow
icon={<CopyIcon />}
onClick={props.copy}
></IconButton>
{props.showCopy && (
<IconButton
text={Locale.Export.Copy}
bordered
shadow
icon={<CopyIcon />}
onClick={props.copy}
></IconButton>
)}
<IconButton
text={Locale.Export.Download}
bordered
Expand Down Expand Up @@ -282,23 +285,34 @@ export function ImagePreviewer(props: {
}
});
};

const isMobile = useMobileScreen();

const download = () => {
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 (
<div className={styles["image-previewer"]}>
<PreviewActions copy={copy} download={download} />
<PreviewActions copy={copy} download={download} showCopy={!isMobile} />
<div
className={`${styles["preview-body"]} ${styles["default-theme"]}`}
ref={previewRef}
Expand Down
25 changes: 23 additions & 2 deletions app/components/message-selector.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,31 @@
.search-bar {
max-width: unset;
flex-grow: 1;
margin-right: 10px;
}

.filter-item:not(:last-child) {
margin-right: 10px;
.actions {
display: flex;

button:not(:last-child) {
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;
}
}
}
}

Expand Down
56 changes: 29 additions & 27 deletions app/components/message-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,33 +140,35 @@ export function MessageSelector(props: {
}}
></input>

<IconButton
text={Locale.Select.All}
bordered
className={styles["filter-item"]}
onClick={selectAll}
/>
<IconButton
text={Locale.Select.Latest}
bordered
className={styles["filter-item"]}
onClick={() =>
props.updateSelection((selection) => {
selection.clear();
messages
.slice(messageCount - 10)
.forEach((m) => selection.add(m.id!));
})
}
/>
<IconButton
text={Locale.Select.Clear}
bordered
className={styles["filter-item"]}
onClick={() =>
props.updateSelection((selection) => selection.clear())
}
/>
<div className={styles["actions"]}>
<IconButton
text={Locale.Select.All}
bordered
className={styles["filter-item"]}
onClick={selectAll}
/>
<IconButton
text={Locale.Select.Latest}
bordered
className={styles["filter-item"]}
onClick={() =>
props.updateSelection((selection) => {
selection.clear();
messages
.slice(messageCount - 10)
.forEach((m) => selection.add(m.id!));
})
}
/>
<IconButton
text={Locale.Select.Clear}
bordered
className={styles["filter-item"]}
onClick={() =>
props.updateSelection((selection) => selection.clear())
}
/>
</div>
</div>

<div className={styles["messages"]}>
Expand Down

0 comments on commit f0b4ef5

Please sign in to comment.