From e47e0c0bca3cb49382ab37262ad3f0c4807ff473 Mon Sep 17 00:00:00 2001 From: Frank Zhang <1282608+0xfrankz@users.noreply.github.com> Date: Thu, 5 Sep 2024 11:36:32 +0800 Subject: [PATCH] feat(Conversation): added feature to view and download images, DONE --- src-tauri/Cargo.toml | 2 +- src-tauri/tauri.conf.json | 3 + src/components/ImagePreviewer.tsx | 82 +++++++++++++++++++++++---- src/i18n/locales/en/error.json | 3 +- src/i18n/locales/en/generic.json | 4 +- src/i18n/locales/zh-Hans/error.json | 3 +- src/i18n/locales/zh-Hans/generic.json | 4 +- 7 files changed, 86 insertions(+), 15 deletions(-) diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 556701c..365a1b5 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -30,7 +30,7 @@ serde = { version = "1.0", features = ["derive"] } sqlx = { version = "0.7", features = [ "sqlite", "runtime-tokio", "tls-native-tls" ] } strum = "0.26" strum_macros = "0.26" -tauri = { version = "1.5.4", features = [ "clipboard-write-text", "clipboard-read-text", "updater", "shell-open", "path-all", "fs-write-file", "fs-remove-dir", "fs-read-dir", "fs-exists", "fs-copy-file", "fs-read-file", "fs-rename-file", "fs-create-dir", "fs-remove-file"] } +tauri = { version = "1.5.4", features = [ "dialog-save", "clipboard-write-text", "clipboard-read-text", "updater", "shell-open", "path-all", "fs-write-file", "fs-remove-dir", "fs-read-dir", "fs-exists", "fs-copy-file", "fs-read-file", "fs-rename-file", "fs-create-dir", "fs-remove-file"] } tauri-plugin-log = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1", features = ["colored"] } thiserror = "1.0" tokio = "1.36.0" diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 13d9419..8371f2f 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -33,6 +33,9 @@ "clipboard": { "writeText": true, "readText": true + }, + "dialog": { + "save": true } }, "bundle": { diff --git a/src/components/ImagePreviewer.tsx b/src/components/ImagePreviewer.tsx index a79cc23..6a38d4a 100644 --- a/src/components/ImagePreviewer.tsx +++ b/src/components/ImagePreviewer.tsx @@ -1,7 +1,13 @@ +import { save } from '@tauri-apps/api/dialog'; +import { writeBinaryFile } from '@tauri-apps/api/fs'; +import { downloadDir } from '@tauri-apps/api/path'; import { useHover } from 'ahooks'; -import { X } from 'lucide-react'; +import { Save, X } from 'lucide-react'; import { forwardRef, type HtmlHTMLAttributes, useRef, useState } from 'react'; +import { useTranslation } from 'react-i18next'; +import { toast } from 'sonner'; +import log from '@/lib/log'; import type { FileData } from '@/lib/types'; import { cn } from '@/lib/utils'; @@ -13,7 +19,18 @@ import { CarouselNext, CarouselPrevious, } from './ui/carousel'; -import { Dialog, DialogContent, DialogTitle } from './ui/dialog'; +import { + ContextMenu, + ContextMenuContent, + ContextMenuItem, + ContextMenuTrigger, +} from './ui/context-menu'; +import { + Dialog, + DialogContent, + DialogDescription, + DialogTitle, +} from './ui/dialog'; type ImagePreviewerProps = { files: FileData[]; @@ -43,7 +60,7 @@ export function ImageThumbnail({