import { Alert, Box, Button, ButtonGroup, Container, Divider, Link, Stack, styled, Typography, useMediaQuery, useTheme, } from "@mui/material"; import { bindPopover, usePopupState } from "material-ui-popup-state/hooks"; import React, { forwardRef, useCallback, useContext, useEffect, useMemo, useState } from "react"; import { Trans, useTranslation } from "react-i18next"; import { Link as RouterLink } from "react-router-dom"; import { FileResponse, Share } from "../../../api/explorer.ts"; import { bindDelayedHover } from "../../../hooks/delayedHover.tsx"; import { useAppDispatch, useAppSelector } from "../../../redux/hooks.ts"; import { downloadSingleFile } from "../../../redux/thunks/download.ts"; import { createShareShortcut, openFileContextMenu } from "../../../redux/thunks/file.ts"; import { queueLoadShareInfo } from "../../../redux/thunks/share.ts"; import { openViewers } from "../../../redux/thunks/viewer.ts"; import SessionManager from "../../../session/index.ts"; import { sizeToString } from "../../../util/index.ts"; import CrUri from "../../../util/uri.ts"; import { SecondaryButton } from "../../Common/StyledComponents.tsx"; import UserAvatar from "../../Common/User/UserAvatar.tsx"; import CaretDown from "../../Icons/CaretDown.tsx"; import Download from "../../Icons/Download.tsx"; import Eye from "../../Icons/Eye.tsx"; import FolderLink from "../../Icons/FolderLink.tsx"; import Open from "../../Icons/Open.tsx"; import Timer from "../../Icons/Timer.tsx"; import useActionDisplayOpt from "../ContextMenu/useActionDisplayOpt.ts"; import { FmIndexContext } from "../FmIndexContext.tsx"; import { PropTypography, ShareExpires, ShareStatistics } from "../TopBar/ShareInfoPopover.tsx"; import PaidShareGate from "../PaidShareGate.tsx"; import FileIcon from "./FileIcon.tsx"; import FileTagSummary from "./FileTagSummary.tsx"; import { useFileBlockState } from "./GridView/GridFile.tsx"; import { ThumbPopover } from "./ListView/Cell.tsx"; const ShareContainer = styled(Box)(({ theme }) => ({ border: `1px solid ${theme.palette.divider}`, borderRadius: theme.shape.borderRadius, padding: theme.spacing(2), width: "100%", backgroundColor: theme.palette.background.default, boxShadow: `0 0 10px 0 rgba(0, 0, 0, 0.1)`, })); const FileList = ({ file }: { file: FileResponse }) => { const theme = useTheme(); const isMobile = useMediaQuery(theme.breakpoints.down("sm")); const isTouch = useMediaQuery("(pointer: coarse)"); const { uploading, noThumb, fileTag, isSelected, thumbWidth, thumbHeight } = useFileBlockState({ file, }); const user = useMemo(() => { return SessionManager.currentLoginOrNull(); }, []); const popupState = usePopupState({ variant: "popover", popupId: "thumbPreview" + file.id, }); const hoverState = bindDelayedHover(popupState, 800); const stopPropagation = useCallback((e: React.MouseEvent) => e.stopPropagation(), []); return ( <> {file?.name}{" "} {fileTag && fileTag.length > 0 && ( )} {sizeToString(file?.size ?? 0)} {!noThumb && ( )} ); }; const SingleFileView = forwardRef((_props, ref: React.Ref) => { const { t } = useTranslation(); const theme = useTheme(); const isMobile = useMediaQuery(theme.breakpoints.down("sm")); const dispatch = useAppDispatch(); const fmIndex = useContext(FmIndexContext); const file = useAppSelector((state) => state.fileManager[fmIndex].list?.files[0]); const [loading, setLoading] = useState(false); const [shareInfo, setShareInfo] = useState(null); const displayOpt = useActionDisplayOpt(file ? [file] : []); useEffect(() => { if (file) { dispatch(queueLoadShareInfo(new CrUri(file.path))) .then((info) => { setShareInfo(info); }) .catch((_e) => { setShareInfo(null); }) .finally(() => { setLoading(false); }); } else { setShareInfo(null); } }, [file]); const openMore = useCallback( (e: React.MouseEvent) => { if (file) { dispatch(openFileContextMenu(fmIndex, file, true, e)); } }, [dispatch, file], ); const download = useCallback(async () => { if (!file) { return; } setLoading(true); try { await dispatch(downloadSingleFile(file)); } finally { setLoading(false); } }, [file, dispatch]); const user = useMemo(() => { return SessionManager.currentLoginOrNull(); }, []); return ( {shareInfo && ( {shareInfo.owner.nickname} , ]} values={{ nick: shareInfo.owner.nickname, num: 1 }} /> {file && } {(shareInfo.remain_downloads || shareInfo.expires) && ( }> )} window.location.reload()} /> {!!user && file && ( dispatch(createShareShortcut(fmIndex))} disabled={loading} startIcon={} > {t("application:fileManager.save")} )} {displayOpt.showOpen && file && !(shareInfo.price && !shareInfo.paid) && ( dispatch(openViewers(0, file))} disabled={loading} startIcon={} > {t("application:fileManager.open")} )} {!shareInfo.preview_only && !(shareInfo.price && !shareInfo.paid) && ( )} )} ); }); export default SingleFileView;