π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
update(locker):update-ItemDetailView
Aswin Asokeb481a95bd4e
diff --git a/web/apps/locker/src/components/ItemDetailView.tsx b/web/apps/locker/src/components/ItemDetailView.tsxindex b5c165184e..7fe1adcb4b 100644--- a/web/apps/locker/src/components/ItemDetailView.tsx+++ b/web/apps/locker/src/components/ItemDetailView.tsx@@ -1,3 +1,4 @@+import { lockerItemIcon } from "@/components/locker-item-icons";import { downloadLockerFile } from "@/services/remote";import type {AccountCredentialData,@@ -8,33 +9,49 @@ import type {PhysicalRecordData,} from "@/types";import { getItemTitle } from "@/types";-import CloseIcon from "@mui/icons-material/Close";-import ContentCopyIcon from "@mui/icons-material/ContentCopy";-import DeleteOutlinedIcon from "@mui/icons-material/DeleteOutlined";-import EditOutlinedIcon from "@mui/icons-material/EditOutlined";-import FileDownloadOutlinedIcon from "@mui/icons-material/FileDownloadOutlined";-import ShareOutlinedIcon from "@mui/icons-material/ShareOutlined";-import VisibilityIcon from "@mui/icons-material/Visibility";-import VisibilityOffIcon from "@mui/icons-material/VisibilityOff";+import {+ Copy01Icon,+ Delete02Icon,+ Download01Icon,+ Link01Icon,+ PencilEdit02Icon,+ ViewIcon,+ ViewOffSlashIcon,+} from "@hugeicons/core-free-icons";+import { HugeiconsIcon } from "@hugeicons/react";+import ArrowBackOutlinedIcon from "@mui/icons-material/ArrowBackOutlined";import {Box,Button,CircularProgress,- Divider,Drawer,IconButton,Snackbar,Stack,Tooltip,Typography,+ type Theme,} from "@mui/material";import { formattedDateTime } from "ente-base/i18n-date";import log from "ente-base/log";import { t } from "i18next";import React, { useCallback, useState } from "react";+const textStyles = {+ display2: {+ fontFamily: '"Outfit Variable", sans-serif',+ fontSize: "24px",+ lineHeight: "32px",+ fontWeight: 600,+ },+ bodyBold: { fontSize: "14px", lineHeight: "20px", fontWeight: 600 },+ body: { fontSize: "14px", lineHeight: "20px", fontWeight: 500 },+ mini: { fontSize: "12px", lineHeight: "16px", fontWeight: 500 },+};+interface ItemDetailViewProps {item: LockerItem | null;+ collectionNames?: string[];onClose: () => void;onEdit?: (item: LockerItem) => void;onDelete?: (item: LockerItem) => void;@@ -45,6 +62,7 @@ interface ItemDetailViewProps {export const ItemDetailView: React.FC<ItemDetailViewProps> = ({item,+ collectionNames,onClose,onEdit,onDelete,@@ -103,91 +121,155 @@ export const ItemDetailView: React.FC<ItemDetailViewProps> = ({}}, [downloading, item]);+ const actionCount = isTrashView+ ? 0+ : Number(!!onEdit) + Number(!!(onDelete || onDeleteDisabledHint));+return (<Draweranchor="right"open={item !== null}onClose={onClose}- sx={{ "& .MuiDrawer-paper": { width: "min(420px, 90vw)", p: 0 } }}+ slotProps={{+ paper: {+ sx: [+ {+ width: { xs: "100%", sm: 420 },+ backgroundColor: "#f4f4f4",+ "&&": { p: 0 },+ },+ (theme) =>+ theme.applyStyles("dark", {+ backgroundColor: "#161616",+ }),+ ],+ },+ }}>{item && (<Stack sx={{ height: "100%" }}>- <Stack- direction="row"+ <Boxsx={{- alignItems: "center",- gap: 1,- px: 2.5,- py: 2,- borderBottom: 1,- borderColor: "divider",+ position: "relative",+ flexShrink: 0,+ height: 112,+ px: 2,+ pt: "48px",}}>- <Box sx={{ flex: 1, minWidth: 0 }}>+ <IconButton+ onClick={onClose}+ aria-label={t("close")}+ sx={{+ position: "absolute",+ left: 6,+ top: 6,+ "&&": { p: "10px" },+ }}+ >+ <ArrowBackOutlinedIcon sx={{ fontSize: 24 }} />+ </IconButton>+ <Box+ sx={{+ minWidth: 0,+ pr: actionCount+ ? `${actionCount * 40 + 8}px`+ : 0,+ }}+ ><Typographyvariant="h3"noWrap- sx={{ lineHeight: 1.3 }}+ sx={{ ...textStyles.display2 }}>{getItemTitle(item)}</Typography><Typography- variant="small"- sx={{ color: "text.faint" }}+ variant="mini"+ sx={{+ ...textStyles.mini,+ color: "text.muted",+ mt: "4px",+ }}>{typeLabel(item.type)}</Typography></Box>- {!isTrashView && onEdit && (- <Tooltip title={t("edit")}>- <IconButton- onClick={() => onEdit(item)}- size="small"- >- <EditOutlinedIcon fontSize="small" />- </IconButton>- </Tooltip>- )}- {!isTrashView && (onDelete || onDeleteDisabledHint) && (- <Tooltip- title={- onDelete- ? t("delete")- : (onDeleteDisabledHint ?? "")- }- >- <Box component="span">+ <Stack+ direction="row"+ sx={{+ position: "absolute",+ right: 16,+ top: 45,+ gap: 1,+ }}+ >+ {!isTrashView && onEdit && (+ <Tooltip title={t("edit")}><IconButton- onClick={- onDelete- ? () => onDelete(item)- : undefined- }+ onClick={() => onEdit(item)}size="small"- disabled={!onDelete}- sx={+ aria-label={t("edit")}+ sx={actionButtonSx}+ >+ <HugeiconsIcon+ icon={PencilEdit02Icon}+ size={18}+ strokeWidth={1.5}+ color="currentColor"+ />+ </IconButton>+ </Tooltip>+ )}+ {!isTrashView &&+ (onDelete || onDeleteDisabledHint) && (+ <Tooltip+ title={onDelete- ? { color: "critical.main" }- : undefined+ ? t("delete")+ : (onDeleteDisabledHint ?? "")}>- <DeleteOutlinedIcon fontSize="small" />- </IconButton>- </Box>- </Tooltip>- )}- <IconButton onClick={onClose} size="small">- <CloseIcon />- </IconButton>- </Stack>+ <Box component="span">+ <IconButton+ onClick={+ onDelete+ ? () => onDelete(item)+ : undefined+ }+ size="small"+ disabled={!onDelete}+ aria-label={t("delete")}+ sx={[+ actionButtonSx,+ onDelete+ ? {+ color: "critical.main",+ }+ : {},+ ]}+ >+ <HugeiconsIcon+ icon={Delete02Icon}+ size={18}+ strokeWidth={1.5}+ color="currentColor"+ />+ </IconButton>+ </Box>+ </Tooltip>+ )}+ </Stack>+ </Box><Stacksx={{flex: 1,overflowY: "auto",- px: 2.5,- py: 2,- gap: 2.5,+ minHeight: 0,+ px: 2,+ pb: 2,+ "& > *": { flexShrink: 0 },}}>{item.type === "note" && (@@ -215,70 +297,139 @@ export const ItemDetailView: React.FC<ItemDetailViewProps> = ({/>)}{item.type === "file" && (- <>- <FileDetail- data={item.data as GenericFileData}- onCopy={copyToClipboard}- />- <Stack sx={{ mt: 1, gap: 1 }}>- <Button- variant="contained"- endIcon={- downloading &&- downloadProgress !== null ? (- <CircularProgress- variant="determinate"- value={downloadProgress}- size={16}- thickness={6}- color="inherit"- />- ) : undefined- }- startIcon={<FileDownloadOutlinedIcon />}- onClick={() => void handleDownload()}- disabled={downloading}- fullWidth- >- {downloading- ? downloadProgress !== null- ? `${t("downloading")} ${downloadProgress}%`- : t("downloading")- : t("download")}- </Button>+ <FileDetail+ data={item.data as GenericFileData}+ onCopy={copyToClipboard}+ />+ )}+ {!!collectionNames?.length && (+ <Stack sx={{ gap: 1, mb: 3 }}>+ <Typography+ variant="body"+ sx={{ ...textStyles.bodyBold, mt: "8px" }}+ >+ {t("collections")}+ </Typography>+ <Stack+ direction="row"+ sx={{ flexWrap: "wrap", gap: "12px 8px" }}+ >+ {collectionNames.map((name, index) => (+ <Typography+ key={`${name}-${index}`}+ variant="body"+ sx={(theme) => ({+ ...textStyles.body,+ minHeight: 44,+ px: 2.5,+ py: 1.5,+ borderRadius: "16px",+ backgroundColor:+ theme.vars.palette+ .background.paper,+ color: "text.muted",+ overflowWrap: "anywhere",+ })}+ >+ {name}+ </Typography>+ ))}</Stack>- </>+ </Stack>+ )}+ <Box sx={{ flex: 1 }} />+ {item.type === "file" && (+ <Button+ variant="contained"+ color="accent"+ sx={{+ ...textStyles.bodyBold,+ minHeight: 52,+ borderRadius: "20px",+ mb: 1,+ }}+ endIcon={+ downloading && downloadProgress !== null ? (+ <CircularProgress+ variant="determinate"+ value={downloadProgress}+ size={16}+ thickness={6}+ color="inherit"+ />+ ) : undefined+ }+ startIcon={+ <HugeiconsIcon+ icon={Download01Icon}+ size={18}+ strokeWidth={1.5}+ color="currentColor"+ />+ }+ onClick={() => void handleDownload()}+ disabled={downloading}+ fullWidth+ >+ {downloading+ ? downloadProgress !== null+ ? `${t("downloading")} ${downloadProgress}%`+ : t("downloading")+ : t("download")}+ </Button>)}{onShareLink && (<Button- variant="outlined"- startIcon={<ShareOutlinedIcon />}+ variant="contained"+ color="secondary"+ sx={[+ (theme) => ({+ ...textStyles.bodyBold,+ minHeight: 52,+ borderRadius: "20px",+ backgroundColor:+ theme.vars.palette.fill.faint,+ color: theme.vars.palette.text.base,+ "&:hover": {+ backgroundColor: "#dedede",+ },+ }),+ (theme) =>+ theme.applyStyles("dark", {+ "&:hover": {+ backgroundColor: "#141414",+ },+ }),+ ]}+ startIcon={+ <HugeiconsIcon+ icon={Link01Icon}+ size={18}+ strokeWidth={1.5}+ color="currentColor"+ />+ }onClick={() => onShareLink(item)}fullWidth>{t("shareLink")}</Button>)}- </Stack>-- {item.updatedAt && (- <Box- sx={{- px: 2.5,- py: 1.5,- borderTop: 1,- borderColor: "divider",- }}- >+ {item.updatedAt && (<Typographyvariant="mini"- sx={{ color: "text.faint" }}+ sx={{+ color: "text.muted",+ ...textStyles.mini,+ textAlign: "center",+ mt: 2,+ }}>{t("lastUpdated")}:{" "}{formattedDateTime(item.updatedAt)}</Typography>- </Box>- )}+ )}+ </Stack></Stack>)}@@ -323,7 +474,6 @@ interface FieldRowProps {label: string;value: string;onCopy: (value: string, field: string) => void;- monospace?: boolean;secret?: boolean;multiline?: boolean;}@@ -332,7 +482,6 @@ const FieldRow: React.FC<FieldRowProps> = ({label,value,onCopy,- monospace,secret,multiline,}) => {@@ -348,24 +497,31 @@ const FieldRow: React.FC<FieldRowProps> = ({: value;return (- <Stack sx={{ gap: 0.5 }}>- <Typography- variant="mini"- sx={{- color: "text.faint",- textTransform: "uppercase",- letterSpacing: "0.08em",- fontWeight: "bold",- }}- >+ <Stack sx={{ gap: 1, mb: 3 }}>+ <Typography variant="body" sx={{ ...textStyles.body }}>{label}</Typography>- <Stack direction="row" sx={{ alignItems: "flex-start", gap: 0.5 }}>+ <Stack+ direction="row"+ sx={(theme) => ({+ alignItems: multiline ? "flex-start" : "center",+ minHeight: 52,+ borderRadius: "16px",+ backgroundColor: theme.vars.palette.background.paper,+ border: `1px solid ${theme.vars.palette.divider}`,+ px: 2,+ py: multiline ? 2 : 0,+ gap: 0.5,+ })}+ ><Typographyvariant="body"sx={{+ ...textStyles.body,flex: 1,- fontFamily: monospace ? "monospace" : undefined,+ minWidth: 0,+ letterSpacing:+ secret && !revealed ? "0.14em" : undefined,whiteSpace: multiline ? "pre-wrap" : "nowrap",overflow: multiline ? "visible" : "hidden",textOverflow: multiline ? "unset" : "ellipsis",@@ -374,30 +530,65 @@ const FieldRow: React.FC<FieldRowProps> = ({>{displayValue}</Typography>- {secret && (- <Tooltip- title={revealed ? t("hidePassword") : t("showPassword")}- >+ <Stack direction="row" sx={{ gap: 0, mr: "-4px" }}>+ {secret && (+ <Tooltip+ title={+ revealed ? t("hidePassword") : t("showPassword")+ }+ >+ <IconButton+ size="small"+ aria-label={+ revealed+ ? t("hidePassword")+ : t("showPassword")+ }+ sx={{+ color: "inherit",+ flexShrink: 0,+ "&&": { p: "4px", borderRadius: "8px" },+ }}+ onClick={() => setRevealed((value) => !value)}+ >+ {revealed ? (+ <HugeiconsIcon+ icon={ViewOffSlashIcon}+ size={18}+ strokeWidth={1.5}+ color="currentColor"+ />+ ) : (+ <HugeiconsIcon+ icon={ViewIcon}+ size={18}+ strokeWidth={1.5}+ color="currentColor"+ />+ )}+ </IconButton>+ </Tooltip>+ )}+ <Tooltip title={t("copy")}><IconButtonsize="small"- onClick={() => setRevealed((value) => !value)}+ aria-label={t("copy")}+ sx={{+ color: "inherit",+ flexShrink: 0,+ "&&": { p: "4px", borderRadius: "8px" },+ }}+ onClick={() => onCopy(value, label)}>- {revealed ? (- <VisibilityOffIcon fontSize="small" />- ) : (- <VisibilityIcon fontSize="small" />- )}+ <HugeiconsIcon+ icon={Copy01Icon}+ size={18}+ strokeWidth={1.5}+ color="currentColor"+ /></IconButton></Tooltip>- )}- <Tooltip title={t("copy")}>- <IconButton- size="small"- onClick={() => onCopy(value, label)}- >- <ContentCopyIcon fontSize="small" />- </IconButton>- </Tooltip>+ </Stack></Stack></Stack>);@@ -421,24 +612,19 @@ const CredentialDetail: React.FC<{}> = ({ data, onCopy }) => (<><FieldRow label={t("username")} value={data.username} onCopy={onCopy} />- <Divider /><FieldRowlabel={t("password")}value={data.password}onCopy={onCopy}secret- monospace/>{data.notes && (- <>- <Divider />- <FieldRow- label={t("credentialNotes")}- value={data.notes}- onCopy={onCopy}- multiline- />- </>+ <FieldRow+ label={t("credentialNotes")}+ value={data.notes}+ onCopy={onCopy}+ multiline+ />)}</>);@@ -454,15 +640,12 @@ const PhysicalRecordDetail: React.FC<{onCopy={onCopy}/>{data.notes && (- <>- <Divider />- <FieldRow- label={t("recordNotes")}- value={data.notes}- onCopy={onCopy}- multiline- />- </>+ <FieldRow+ label={t("recordNotes")}+ value={data.notes}+ onCopy={onCopy}+ multiline+ />)}</>);@@ -478,22 +661,92 @@ const EmergencyContactDetail: React.FC<{onCopy={onCopy}/>{data.notes && (- <>- <Divider />- <FieldRow- label={t("contactNotes")}- value={data.notes}- onCopy={onCopy}- multiline- />- </>+ <FieldRow+ label={t("contactNotes")}+ value={data.notes}+ onCopy={onCopy}+ multiline+ />)}</>);+const actionButtonSx = (theme: Theme) => ({+ "&&": { width: 36, height: 36, p: 0, borderRadius: "12px" },+ "&:hover": { backgroundColor: theme.vars.palette.fill.faint },+});++const formattedBytes = (bytes: number) => {+ const units = ["B", "KB", "MB", "GB", "TB"];+ const index = Math.min(+ Math.floor(Math.log(Math.max(bytes, 1)) / Math.log(1024)),+ units.length - 1,+ );+ return `${Number((bytes / 1024 ** index).toFixed(1))} ${units[index]}`;+};+const FileDetail: React.FC<{data: GenericFileData;onCopy: (value: string, field: string) => void;-}> = ({ data, onCopy }) => (- <FieldRow label={t("fileTitle")} value={data.name} onCopy={onCopy} />-);+}> = ({ data, onCopy }) => {+ const suffix = /\.([a-z0-9]{1,5})$/i.exec(data.name)?.[1];+ const extension =+ suffix && /[a-z]/i.test(suffix) ? suffix.toUpperCase() : undefined;+ const meta = [+ extension,+ data.fileSize === undefined ? undefined : formattedBytes(data.fileSize),+ ]+ .filter(Boolean)+ .join(" Β· ");+ return (+ <>+ <Stack+ sx={(theme) => ({+ height: 180,+ borderRadius: "20px",+ backgroundColor: theme.vars.palette.background.paper,+ alignItems: "center",+ justifyContent: "center",+ gap: "10px",+ mb: 3,+ })}+ >+ <Box+ sx={[+ {+ width: 56,+ height: 56,+ borderRadius: "16px",+ backgroundColor: "#f4f4f4",+ display: "grid",+ placeItems: "center",+ },+ (theme) =>+ theme.applyStyles("dark", {+ backgroundColor: "#161616",+ }),+ ]}+ >+ {lockerItemIcon("file", {+ fileName: data.name,+ size: 32,+ strokeWidth: 1.5,+ })}+ </Box>+ {meta && (+ <Typography+ variant="mini"+ sx={{ ...textStyles.mini, color: "text.muted" }}+ >+ {meta}+ </Typography>+ )}+ </Stack>+ <FieldRow+ label={t("fileTitle")}+ value={data.name}+ onCopy={onCopy}+ />+ </>+ );+};diff --git a/web/apps/locker/src/components/ItemList.tsx b/web/apps/locker/src/components/ItemList.tsxindex 3de3953151..551d132bf4 100644--- a/web/apps/locker/src/components/ItemList.tsx+++ b/web/apps/locker/src/components/ItemList.tsx@@ -234,6 +234,18 @@ export const ItemList: React.FC<ItemListProps> = ({null);}, [allItemsByID, selectedItemID, trashItemsByID]);+ const selectedItemCollectionNames = useMemo(+ () =>+ (isTrashView ? [] : (selectedItem?.collectionIDs ?? [])).flatMap(+ (id) => {+ const collection = collections.find(+ (collection) => collection.id === id,+ );+ return collection ? [collection.name] : [];+ },+ ),+ [collections, isTrashView, selectedItem],+ );const restoreItem = useMemo(() =>restoreItemID === null@@ -1236,6 +1248,7 @@ export const ItemList: React.FC<ItemListProps> = ({<ItemDetailViewitem={selectedItem}+ collectionNames={selectedItemCollectionNames}onClose={() => setSelectedItemID(null)}onEdit={onEditItem &&