okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-split-int (c157ea373) into f-split-qa1: my new strings renumbered after s3236 (s3237-s3255)e5476b0e1

main
2.9 KiB45 linesraw
1import { tr } from '../lib/i18n';
2import { pushToast } from '../lib/store';
3import { Btn, Dialog, Icon } from './ui';
4/** Saves the picture and says so: a download gives no sign of its own in some windows (QA O02), so a short message follows it. */
5export function saveSnapshotWithNotice(data: string) {
6    try {
7        downloadSnapshot(data);
8        pushToast('success', tr('Screenshot saved'), tr('It is in your Downloads folder.'));
9    }
10    catch {
11        pushToast('error', tr('The screenshot was not saved'), tr('Try again, or take a screenshot of this window instead.'));
12    }
13}
14export function downloadSnapshot(data: string) {
15    const encoded = data.slice(data.indexOf(',') + 1);
16    const bytes = Uint8Array.from(atob(encoded), character => character.charCodeAt(0));
17    const url = URL.createObjectURL(new Blob([bytes], { type: 'image/png' }));
18    const link = document.createElement('a');
19    link.href = url;
20    link.download = `Strata-Monitor-${new Date().toISOString().slice(0, 10)}.png`;
21    document.body.appendChild(link);
22    link.click();
23    link.remove();
24    setTimeout(() => URL.revokeObjectURL(url), 1000);
25}
26export function SnapshotDialog({ open, data, pending, error, onClose, onRetry }: {
27    open: boolean;
28    data: string;
29    pending: boolean;
30    error: string;
31    onClose: () => void;
32    onRetry: () => void;
33}) {
34    const caption = 'My local AI performance with Strata';
35    const project = 'https://github.com/Niko1221/Strata';
36    return <Dialog open={open} title={tr("Monitor screenshot")} onClose={onClose} actions={<><Btn onClick={onClose}>{tr("Close")}</Btn><Btn icon="download" variant="primary" disabled={!data || pending} onClick={() => saveSnapshotWithNotice(data)}>{tr("Download")}</Btn></>}>
37    <div className="snapshot-preview" aria-busy={pending}>
38      {tr(pending ? <p className="small muted" role="status">{tr("Preparing your screenshot\u2026")}</p> : data ? <img src={data} alt={tr("Captured Strata Monitor readings")}/> : <div><p className="inline-error" role="alert">{tr(error || 'Screenshot could not be prepared.')}</p><Btn onClick={onRetry}>{tr("Try again")}</Btn></div>)}
39    </div>
40    {tr(data && !pending ? <><div className="snapshot-share-actions">
41      <a className="st-btn st-btn--secondary" href={`https://x.com/intent/post?text=${encodeURIComponent(`${caption}\n${project}`)}`} target="_blank" rel="noreferrer" onClick={() => downloadSnapshot(data)}>{tr("Share to X ")}<Icon name="link" size={15}/></a>
42      <a className="st-btn st-btn--secondary" href={`https://www.reddit.com/submit?title=${encodeURIComponent(caption)}&url=${encodeURIComponent(project)}`} target="_blank" rel="noreferrer" onClick={() => downloadSnapshot(data)}>{tr("Share to Reddit ")}<Icon name="link" size={15}/></a>
43    </div><p className="small muted">{tr("Sharing downloads the image and opens a draft. Attach the image to your post.")}</p></> : null)}
44  </Dialog>;
45}