import { useApiInContext } from "@/utils/store/api"; import { usePhotosPlayback } from "@/utils/store/photosPlayback"; import { createFileRoute } from "@tanstack/react-router"; import React, { type MouseEvent, useCallback, useMemo, useState } from "react"; import { AnimatePresence, motion } from "motion/react"; //@ts-ignore import brokenImage from "/assetsStatic/broken-image.png?url"; import { save } from "@tauri-apps/plugin-dialog"; import "./photos.scss"; import getImageUrlsApi from "@/utils/methods/getImageUrlsApi"; import { IconButton, ListItemIcon, ListItemText, Menu, MenuItem, } from "@mui/material"; import { download } from "@tauri-apps/plugin-upload"; import { useSnackbar } from "notistack"; export const Route = createFileRoute("/_api/player/photos")({ component: PhotosPlayer, }); function PhotosPlayer() { const api = useApiInContext((s) => s.api); const [photos, startIndex] = usePhotosPlayback((s) => [s.photos, s.index]); const [currentIndex, setCurrentIndex] = useState(startIndex); const { enqueueSnackbar } = useSnackbar(); const currentPhoto = useMemo( () => photos?.[currentIndex], [photos, currentIndex], ); const allPhotos = useMemo( () => photos?.map((item, index) => (
setCurrentIndex(index)} key={item?.Id ?? "noPhoto"} className={ index === currentIndex ? "photos-preview active" : "photos-preview" } > Изображение
)), [photos, currentIndex], ); const handlePhotosChangePrev = useCallback(() => { setCurrentIndex(currentIndex - 1); }, [currentIndex]); const handlePhotosChangeNext = useCallback(() => { setCurrentIndex(currentIndex + 1); }, [currentIndex]); const [contextMenu, setContextMenu] = useState<{ mouseX: number; mouseY: number; } | null>(null); const handleShowContextMenu = (e: MouseEvent) => { e.preventDefault(); if (contextMenu === null) { setContextMenu({ mouseX: e.clientX + 2, mouseY: e.clientY - 6 }); } else { setContextMenu(null); } }; const handleContextMenuClose = useCallback(() => { setContextMenu(null); }, []); const handleImageDownload = useCallback(async () => { const pathToSave = await save({ filters: [ { name: "Image", extensions: ["png", "jpeg"], }, ], }); if (pathToSave) { download( `${api?.basePath}/Items/${currentPhoto?.Id}/Download?ApiKey=${api?.accessToken}`, pathToSave, ); enqueueSnackbar("Загрузка изображения добавлена в очередь.", { variant: "info" }); } }, [currentIndex]); return (
chevron_left chevron_right
download Скачать
{allPhotos}
); }