Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

refractor(locker):split-ItemList

Aswin Asok55789ba4972b
diff --git a/web/apps/locker/src/components/collections/CollectionCard.tsx b/web/apps/locker/src/components/collections/CollectionCard.tsx
new file mode 100644
index 0000000000..ee213581f8
--- /dev/null
+++ b/web/apps/locker/src/components/collections/CollectionCard.tsx
@@ -0,0 +1,169 @@
+import {
+ lockerColorSx,
+ lockerTextBodySx,
+ lockerTextMiniSx,
+} from "@/styles/tokens";
+import type { LockerCollection } from "@/types";
+import { isImportantCollection } from "@/types";
+import { Link01Icon, StarIcon, Wallet05Icon } from "@hugeicons/core-free-icons";
+import { HugeiconsIcon } from "@hugeicons/react";
+import { Box, ButtonBase, Stack, Typography } from "@mui/material";
+import { t } from "i18next";
+import React from "react";
+
+import { CollectionContextMenu } from "./CollectionContextMenu";
+
+export const CollectionCard: React.FC<{
+ collection: LockerCollection;
+ onClick: () => void;
+ onShare?: () => void;
+ onLeave?: () => void;
+ onRename?: () => void;
+ onDelete?: () => void;
+}> = ({ collection, onClick, onShare, onLeave, onRename, onDelete }) => {
+ return (
+ <ButtonBase
+ component="div"
+ onClick={onClick}
+ sx={(theme) => ({
+ width: "100%",
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "space-between",
+ gap: 1.5,
+ pl: 1.5,
+ pr: 0,
+ py: 1.5,
+ borderRadius: "20px",
+ border: "1.5px solid",
+ transition: "background-color 0.15s, border-color 0.15s",
+ ...lockerColorSx(theme, {
+ backgroundColor: "fillLight",
+ borderColor: "fillLight",
+ }),
+ "&:hover": {
+ ...lockerColorSx(theme, { backgroundColor: "fillDark" }),
+ },
+ })}
+ >
+ <Stack
+ direction="row"
+ sx={{ flex: 1, minWidth: 0, alignItems: "center", gap: 1.25 }}
+ >
+ <Box
+ sx={(theme) => ({
+ position: "relative",
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center",
+ width: 40,
+ height: 40,
+ flexShrink: 0,
+ borderRadius: "12px",
+ ...lockerColorSx(theme, {
+ backgroundColor: "backgroundBase",
+ }),
+ })}
+ >
+ {isImportantCollection(collection) ? (
+ <Box
+ sx={(theme) => ({
+ display: "flex",
+ ...lockerColorSx(theme, { color: "primary" }),
+ })}
+ >
+ <HugeiconsIcon
+ icon={StarIcon}
+ size={24}
+ strokeWidth={1.5}
+ />
+ </Box>
+ ) : (
+ <Box
+ sx={(theme) => ({
+ display: "flex",
+ ...lockerColorSx(theme, { color: "textBase" }),
+ })}
+ >
+ <HugeiconsIcon
+ icon={Wallet05Icon}
+ size={24}
+ strokeWidth={1.5}
+ />
+ </Box>
+ )}
+ {collection.isShared && <SharedCollectionBadge />}
+ </Box>
+ <Box sx={{ flex: 1, minWidth: 0 }}>
+ <Typography
+ sx={(theme) => ({
+ ...lockerTextBodySx,
+ minWidth: 0,
+ ...lockerColorSx(theme, { color: "textBase" }),
+ })}
+ noWrap
+ >
+ {collection.name}
+ </Typography>
+ <Typography
+ sx={(theme) => ({
+ ...lockerTextMiniSx,
+ mt: "4px",
+ ...lockerColorSx(theme, { color: "textLight" }),
+ })}
+ >
+ {t("lockerItemsCount", {
+ count: collection.items.length,
+ })}
+ </Typography>
+ </Box>
+ </Stack>
+ <Box
+ sx={{
+ flexShrink: 0,
+ mr: 1.5,
+ width: 44,
+ height: 24,
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "flex-end",
+ }}
+ onClick={(event) => event.stopPropagation()}
+ >
+ {(onShare || onLeave || onRename || onDelete) && (
+ <CollectionContextMenu
+ ariaID={`collection-context-menu-${collection.id}`}
+ onShare={onShare}
+ onLeave={onLeave}
+ onRename={onRename}
+ onDelete={onDelete}
+ />
+ )}
+ </Box>
+ </ButtonBase>
+ );
+};
+
+const SharedCollectionBadge: React.FC = () => {
+ return (
+ <Box
+ sx={(theme) => ({
+ position: "absolute",
+ right: -4,
+ bottom: -4,
+ width: 18,
+ height: 18,
+ borderRadius: "50%",
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center",
+ ...lockerColorSx(theme, {
+ backgroundColor: "fillLight",
+ color: "primary",
+ }),
+ })}
+ >
+ <HugeiconsIcon icon={Link01Icon} size={12} strokeWidth={2} />
+ </Box>
+ );
+};
diff --git a/web/apps/locker/src/components/collections/CollectionChipFilters.tsx b/web/apps/locker/src/components/collections/CollectionChipFilters.tsx
new file mode 100644
index 0000000000..f9849248e6
--- /dev/null
+++ b/web/apps/locker/src/components/collections/CollectionChipFilters.tsx
@@ -0,0 +1,213 @@
+import {
+ lockerColors,
+ lockerColorSx,
+ lockerContentMaxWidth,
+ lockerTextBodySx,
+} from "@/styles/tokens";
+import type { LockerCollection } from "@/types";
+import ChevronLeftRoundedIcon from "@mui/icons-material/ChevronLeftRounded";
+import ChevronRightRoundedIcon from "@mui/icons-material/ChevronRightRounded";
+import { Box, ButtonBase, Stack, Typography } from "@mui/material";
+import React, { useEffect, useRef, useState } from "react";
+
+export const CollectionChipFilters: React.FC<{
+ collections: LockerCollection[];
+ selectedCollectionIDs: number[];
+ onToggleCollection: (collectionID: number) => void;
+}> = ({ collections, selectedCollectionIDs, onToggleCollection }) => {
+ const scrollContainerRef = useRef<HTMLDivElement | null>(null);
+ const [showLeftScrollHint, setShowLeftScrollHint] = useState(false);
+ const [showRightScrollHint, setShowRightScrollHint] = useState(false);
+
+ const scrollLeft = () => {
+ const container = scrollContainerRef.current;
+ if (!container) {
+ return;
+ }
+
+ container.scrollBy({
+ left: -Math.max(container.clientWidth * 0.6, 160),
+ behavior: "smooth",
+ });
+ };
+
+ const scrollRight = () => {
+ const container = scrollContainerRef.current;
+ if (!container) {
+ return;
+ }
+
+ container.scrollBy({
+ left: Math.max(container.clientWidth * 0.6, 160),
+ behavior: "smooth",
+ });
+ };
+
+ useEffect(() => {
+ const container = scrollContainerRef.current;
+ if (!container) {
+ return;
+ }
+
+ const updateScrollHint = () => {
+ setShowLeftScrollHint(container.scrollLeft > 8);
+ const remainingScroll =
+ container.scrollWidth -
+ container.clientWidth -
+ container.scrollLeft;
+ setShowRightScrollHint(remainingScroll > 8);
+ };
+
+ updateScrollHint();
+ container.addEventListener("scroll", updateScrollHint, {
+ passive: true,
+ });
+ window.addEventListener("resize", updateScrollHint);
+
+ return () => {
+ container.removeEventListener("scroll", updateScrollHint);
+ window.removeEventListener("resize", updateScrollHint);
+ };
+ }, [collections, selectedCollectionIDs]);
+
+ return (
+ <Box
+ sx={{ width: "100%", maxWidth: lockerContentMaxWidth, mx: "auto" }}
+ >
+ <Stack direction="row" sx={{ alignItems: "stretch", gap: 0 }}>
+ {showLeftScrollHint && (
+ <Box
+ sx={{
+ width: 28,
+ flexShrink: 0,
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center",
+ }}
+ >
+ <ButtonBase
+ onClick={scrollLeft}
+ sx={(theme) => ({
+ width: 28,
+ height: "100%",
+ borderRadius: "999px",
+ ...lockerColorSx(theme, { color: "iconColor" }),
+ })}
+ >
+ <ChevronLeftRoundedIcon sx={{ fontSize: 28 }} />
+ </ButtonBase>
+ </Box>
+ )}
+ <Box sx={{ position: "relative", flex: 1, minWidth: 0 }}>
+ <Stack
+ ref={scrollContainerRef}
+ direction="row"
+ sx={{
+ gap: 1,
+ flexWrap: "nowrap",
+ overflowX: "auto",
+ overflowY: "hidden",
+ justifyContent: "flex-start",
+ pr: 2,
+ pb: 0.5,
+ scrollbarWidth: "none",
+ "&::-webkit-scrollbar": { display: "none" },
+ }}
+ >
+ {collections.map((collection) => {
+ const isSelected = selectedCollectionIDs.includes(
+ collection.id,
+ );
+
+ return (
+ <ButtonBase
+ key={collection.id}
+ onClick={() =>
+ onToggleCollection(collection.id)
+ }
+ sx={(theme) => ({
+ minHeight: 44,
+ padding: "12px 20px",
+ borderRadius: "16px",
+ whiteSpace: "nowrap",
+ flexShrink: 0,
+ ...lockerColorSx(theme, {
+ backgroundColor: isSelected
+ ? "primary"
+ : "fillLight",
+ color: isSelected
+ ? "specialWhite"
+ : "textLight",
+ }),
+ })}
+ >
+ <Typography
+ variant="small"
+ sx={lockerTextBodySx}
+ >
+ {collection.name}
+ </Typography>
+ </ButtonBase>
+ );
+ })}
+ </Stack>
+ {showLeftScrollHint && (
+ <Box
+ sx={(theme) => ({
+ position: "absolute",
+ top: 0,
+ left: 0,
+ bottom: 0,
+ width: 40,
+ pointerEvents: "none",
+ background: `linear-gradient(90deg, ${lockerColors.backgroundBase.dark} 0%, ${lockerColors.backgroundBase.dark}00 100%)`,
+ ...theme.applyStyles("light", {
+ background: `linear-gradient(90deg, ${lockerColors.backgroundBase.light} 0%, ${lockerColors.backgroundBase.light}00 100%)`,
+ }),
+ })}
+ />
+ )}
+ {showRightScrollHint && (
+ <Box
+ sx={(theme) => ({
+ position: "absolute",
+ top: 0,
+ right: 0,
+ bottom: 0,
+ width: 72,
+ pointerEvents: "none",
+ background: `linear-gradient(90deg, ${lockerColors.backgroundBase.dark}00 0%, ${lockerColors.backgroundBase.dark} 100%)`,
+ ...theme.applyStyles("light", {
+ background: `linear-gradient(90deg, ${lockerColors.backgroundBase.light}00 0%, ${lockerColors.backgroundBase.light} 100%)`,
+ }),
+ })}
+ />
+ )}
+ </Box>
+ {showRightScrollHint && (
+ <Box
+ sx={{
+ width: 28,
+ flexShrink: 0,
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center",
+ }}
+ >
+ <ButtonBase
+ onClick={scrollRight}
+ sx={(theme) => ({
+ width: 28,
+ height: "100%",
+ borderRadius: "999px",
+ ...lockerColorSx(theme, { color: "iconColor" }),
+ })}
+ >
+ <ChevronRightRoundedIcon sx={{ fontSize: 28 }} />
+ </ButtonBase>
+ </Box>
+ )}
+ </Stack>
+ </Box>
+ );
+};
diff --git a/web/apps/locker/src/components/collections/CollectionContextMenu.tsx b/web/apps/locker/src/components/collections/CollectionContextMenu.tsx
new file mode 100644
index 0000000000..917503a938
--- /dev/null
+++ b/web/apps/locker/src/components/collections/CollectionContextMenu.tsx
@@ -0,0 +1,58 @@
+import {
+ LockerMenuOption,
+ LockerOverflowMenu,
+} from "@/components/ui/LockerMenu";
+import DeleteOutlinedIcon from "@mui/icons-material/DeleteOutlined";
+import EditOutlinedIcon from "@mui/icons-material/EditOutlined";
+import LogoutOutlinedIcon from "@mui/icons-material/LogoutOutlined";
+import ShareOutlinedIcon from "@mui/icons-material/ShareOutlined";
+import { t } from "i18next";
+import React from "react";
+
+export const CollectionContextMenu: React.FC<{
+ ariaID: string;
+ onShare?: () => void;
+ onLeave?: () => void;
+ onRename?: () => void;
+ onDelete?: () => void;
+}> = ({ ariaID, onShare, onLeave, onRename, onDelete }) => (
+ <LockerOverflowMenu
+ ariaID={ariaID}
+ triggerButtonSxProps={{ p: 0.25, color: "text.muted" }}
+ >
+ {onShare && (
+ <LockerMenuOption
+ startIcon={<ShareOutlinedIcon />}
+ onClick={onShare}
+ >
+ {t(onLeave ? "sharedWith" : "share")}
+ </LockerMenuOption>
+ )}
+ {onLeave && (
+ <LockerMenuOption
+ startIcon={<LogoutOutlinedIcon />}
+ critical
+ onClick={onLeave}
+ >
+ {t("leaveCollection")}
+ </LockerMenuOption>
+ )}
+ {onRename && (
+ <LockerMenuOption
+ startIcon={<EditOutlinedIcon />}
+ onClick={onRename}
+ >
+ {t("renameCollection")}
+ </LockerMenuOption>
+ )}
+ {onDelete && (
+ <LockerMenuOption
+ startIcon={<DeleteOutlinedIcon />}
+ critical
+ onClick={onDelete}
+ >
+ {t("deleteCollection")}
+ </LockerMenuOption>
+ )}
+ </LockerOverflowMenu>
+);
diff --git a/web/apps/locker/src/components/collections/CollectionFilters.tsx b/web/apps/locker/src/components/collections/CollectionFilters.tsx
new file mode 100644
index 0000000000..e7dc0b5d4f
--- /dev/null
+++ b/web/apps/locker/src/components/collections/CollectionFilters.tsx
@@ -0,0 +1,148 @@
+import { LockerMenuFooter, LockerMenuOption } from "@/components/ui/LockerMenu";
+import { lockerMenuPaperSx } from "@/styles/dialog";
+import { lockerColorSx, lockerContentMaxWidth } from "@/styles/tokens";
+import type { LockerCollection } from "@/types";
+import FilterListRoundedIcon from "@mui/icons-material/FilterListRounded";
+import { Box, ButtonBase, Menu, Stack, Tooltip } from "@mui/material";
+import { t } from "i18next";
+import React, { useCallback, useState } from "react";
+import { CollectionChipFilters } from "./CollectionChipFilters";
+
+interface CollectionFiltersProps {
+ orderedHomeCollections: LockerCollection[];
+ dropdownHomeCollections: LockerCollection[];
+ homeSelectedCollectionIDs: number[];
+ toggleHomeCollection: (collectionID: number) => void;
+ clearHomeCollectionSelection: () => void;
+}
+export function CollectionFilters({
+ orderedHomeCollections,
+ dropdownHomeCollections,
+ homeSelectedCollectionIDs,
+ toggleHomeCollection,
+ clearHomeCollectionSelection,
+}: CollectionFiltersProps) {
+ const [collectionFilterAnchorEl, setCollectionFilterAnchorEl] =
+ useState<HTMLElement | null>(null);
+ const openCollectionFilterMenu = useCallback(
+ (event: React.MouseEvent<HTMLElement>) => {
+ setCollectionFilterAnchorEl(event.currentTarget);
+ },
+ [],
+ );
+ const closeCollectionFilterMenu = useCallback(() => {
+ setCollectionFilterAnchorEl(null);
+ }, []);
+ return (
+ <>
+ <Stack
+ direction="row"
+ sx={{
+ width: "100%",
+ maxWidth: lockerContentMaxWidth,
+ mx: "auto",
+ alignItems: "center",
+ gap: 1,
+ mb: 2,
+ minWidth: 0,
+ }}
+ >
+ <CollectionFilterChip
+ selected={homeSelectedCollectionIDs.length > 0}
+ onClick={openCollectionFilterMenu}
+ />
+ <Box
+ key={orderedHomeCollections
+ .map((collection) => collection.id)
+ .join("-")}
+ sx={{
+ flex: 1,
+ minWidth: 0,
+ "@keyframes chipBarRefresh": {
+ "0%": {
+ opacity: 0.7,
+ transform: "translateY(2px)",
+ },
+ "100%": { opacity: 1, transform: "translateY(0)" },
+ },
+ animation: "chipBarRefresh 220ms ease-out",
+ }}
+ >
+ <CollectionChipFilters
+ collections={orderedHomeCollections}
+ selectedCollectionIDs={homeSelectedCollectionIDs}
+ onToggleCollection={toggleHomeCollection}
+ />
+ </Box>
+ </Stack>
+ <Menu
+ anchorEl={collectionFilterAnchorEl}
+ open={!!collectionFilterAnchorEl}
+ onClose={closeCollectionFilterMenu}
+ slotProps={{
+ paper: { sx: [lockerMenuPaperSx, { mt: 1 }] },
+ list: { disablePadding: true },
+ }}
+ >
+ {dropdownHomeCollections.map((collection) => {
+ const isSelected = homeSelectedCollectionIDs.includes(
+ collection.id,
+ );
+ return (
+ <LockerMenuOption
+ key={collection.id}
+ onClick={() => toggleHomeCollection(collection.id)}
+ selected={isSelected}
+ secondary={new Intl.NumberFormat().format(
+ collection.items.length,
+ )}
+ >
+ {collection.name}
+ </LockerMenuOption>
+ );
+ })}
+ {homeSelectedCollectionIDs.length > 0 && (
+ <LockerMenuFooter
+ onClick={() => {
+ clearHomeCollectionSelection();
+ closeCollectionFilterMenu();
+ }}
+ >
+ {t("clearSelection")}
+ </LockerMenuFooter>
+ )}
+ </Menu>
+ </>
+ );
+}
+const CollectionFilterChip: React.FC<{
+ selected: boolean;
+ onClick: (event: React.MouseEvent<HTMLElement>) => void;
+}> = ({ selected, onClick }) => (
+ <Tooltip title={t("seeAllCollections")}>
+ <ButtonBase
+ onClick={onClick}
+ sx={(theme) => ({
+ width: 36,
+ height: 36,
+ borderRadius: "12px",
+ flexShrink: 0,
+ padding: 0,
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center",
+ ...lockerColorSx(theme, {
+ backgroundColor: selected ? "primary" : "fillLight",
+ color: selected ? "specialWhite" : "iconColor",
+ }),
+ "&:hover": {
+ ...lockerColorSx(theme, {
+ backgroundColor: selected ? "primary" : "fillDark",
+ }),
+ },
+ })}
+ >
+ <FilterListRoundedIcon sx={{ fontSize: 18 }} />
+ </ButtonBase>
+ </Tooltip>
+);
diff --git a/web/apps/locker/src/components/collections/CollectionGrid.tsx b/web/apps/locker/src/components/collections/CollectionGrid.tsx
new file mode 100644
index 0000000000..224451a119
--- /dev/null
+++ b/web/apps/locker/src/components/collections/CollectionGrid.tsx
@@ -0,0 +1,74 @@
+import { lockerContentMaxWidth } from "@/styles/tokens";
+import type { LockerCollection } from "@/types";
+import {
+ canEditCollection,
+ canLeaveCollection,
+ canOpenCollectionSharing,
+} from "@/types";
+import { Box } from "@mui/material";
+import { savedLocalUser } from "ente-accounts/services/accounts-db";
+import React from "react";
+
+import { CollectionCard } from "./CollectionCard";
+
+export const CollectionGrid: React.FC<{
+ collections: LockerCollection[];
+ onSelectCollection: (collectionID: number) => void;
+ onShareCollection?: (collection: LockerCollection) => void;
+ onLeaveCollection?: (collection: LockerCollection) => void;
+ onRequestRenameCollection?: (collection: LockerCollection) => void;
+ onDeleteCollection?: (collectionID: number) => void;
+}> = ({
+ collections,
+ onSelectCollection,
+ onShareCollection,
+ onLeaveCollection,
+ onRequestRenameCollection,
+ onDeleteCollection,
+}) => {
+ const currentUserID = savedLocalUser()?.id;
+
+ return (
+ <Box
+ sx={{
+ width: "100%",
+ maxWidth: lockerContentMaxWidth,
+ mx: "auto",
+ display: "grid",
+ gap: 1,
+ }}
+ >
+ {collections.map((collection) => (
+ <CollectionCard
+ key={collection.id}
+ collection={collection}
+ onClick={() => onSelectCollection(collection.id)}
+ onShare={
+ onShareCollection &&
+ canOpenCollectionSharing(collection)
+ ? () => onShareCollection(collection)
+ : undefined
+ }
+ onLeave={
+ onLeaveCollection &&
+ canLeaveCollection(collection, currentUserID)
+ ? () => onLeaveCollection(collection)
+ : undefined
+ }
+ onRename={
+ onRequestRenameCollection &&
+ canEditCollection(collection, currentUserID)
+ ? () => onRequestRenameCollection(collection)
+ : undefined
+ }
+ onDelete={
+ onDeleteCollection &&
+ canEditCollection(collection, currentUserID)
+ ? () => onDeleteCollection(collection.id)
+ : undefined
+ }
+ />
+ ))}
+ </Box>
+ );
+};
diff --git a/web/apps/locker/src/components/collections/CollectionHeaderMenu.tsx b/web/apps/locker/src/components/collections/CollectionHeaderMenu.tsx
new file mode 100644
index 0000000000..d587a43b5f
--- /dev/null
+++ b/web/apps/locker/src/components/collections/CollectionHeaderMenu.tsx
@@ -0,0 +1,57 @@
+import {
+ LockerMenuOption,
+ LockerOverflowMenu,
+} from "@/components/ui/LockerMenu";
+import DeleteOutlinedIcon from "@mui/icons-material/DeleteOutlined";
+import EditOutlinedIcon from "@mui/icons-material/EditOutlined";
+import LogoutOutlinedIcon from "@mui/icons-material/LogoutOutlined";
+import ShareOutlinedIcon from "@mui/icons-material/ShareOutlined";
+import { t } from "i18next";
+import React from "react";
+
+export const CollectionHeaderMenu: React.FC<{
+ onShare?: () => void;
+ onLeave?: () => void;
+ onRename?: () => void;
+ onDelete?: () => void;
+}> = ({ onShare, onLeave, onRename, onDelete }) => (
+ <LockerOverflowMenu
+ ariaID="collection-header-menu"
+ triggerButtonSxProps={{ color: "text.muted" }}
+ >
+ {onShare && (
+ <LockerMenuOption
+ startIcon={<ShareOutlinedIcon />}
+ onClick={onShare}
+ >
+ {t(onLeave ? "sharedWith" : "share")}
+ </LockerMenuOption>
+ )}
+ {onLeave && (
+ <LockerMenuOption
+ startIcon={<LogoutOutlinedIcon />}
+ critical
+ onClick={onLeave}
+ >
+ {t("leaveCollection")}
+ </LockerMenuOption>
+ )}
+ {onRename && (
+ <LockerMenuOption
+ startIcon={<EditOutlinedIcon />}
+ onClick={onRename}
+ >
+ {t("renameCollection")}
+ </LockerMenuOption>
+ )}
+ {onDelete && (
+ <LockerMenuOption
+ startIcon={<DeleteOutlinedIcon />}
+ critical
+ onClick={onDelete}
+ >
+ {t("deleteCollection")}
+ </LockerMenuOption>
+ )}
+ </LockerOverflowMenu>
+);
diff --git a/web/apps/locker/src/components/collections/CreateCollectionDialog.tsx b/web/apps/locker/src/components/collections/CreateCollectionDialog.tsx
new file mode 100644
index 0000000000..13a3d9c1b6
--- /dev/null
+++ b/web/apps/locker/src/components/collections/CreateCollectionDialog.tsx
@@ -0,0 +1,171 @@
+import { FormField } from "@/components/ui/FormField";
+import { lockerSheetContainerSx, lockerSheetPaperSx } from "@/styles/dialog";
+import {
+ lockerHeaderIconButtonSx,
+ lockerPrimaryButtonSx,
+} from "@/styles/fields";
+import {
+ lockerColorSx,
+ lockerTextBodyBoldSx,
+ lockerTextH2Sx,
+ lockerTextMiniSx,
+} from "@/styles/tokens";
+import { Cancel01Icon } from "@hugeicons/core-free-icons";
+import { HugeiconsIcon } from "@hugeicons/react";
+import { Box, Dialog, IconButton, Stack, Typography } from "@mui/material";
+import { LoadingButton } from "ente-base/components/mui/LoadingButton";
+import { t } from "i18next";
+import { useCallback, useState } from "react";
+
+interface CreateCollectionDialogProps {
+ open: boolean;
+ onClose: () => void;
+ onCreateCollection?: (name: string) => Promise<number>;
+ onSelectCollection: (id: number) => void;
+}
+export function CreateCollectionDialog({
+ open: createCollectionOpen,
+ onClose: onCloseCreateCollectionDialog,
+ onCreateCollection,
+ onSelectCollection,
+}: CreateCollectionDialogProps) {
+ const onClose = onCloseCreateCollectionDialog;
+ const [createCollectionName, setCreateCollectionName] = useState("");
+ const [creatingCollection, setCreatingCollection] = useState(false);
+ const [createCollectionError, setCreateCollectionError] = useState<
+ string | null
+ >(null);
+ const [wasOpen, setWasOpen] = useState(createCollectionOpen);
+ if (wasOpen !== createCollectionOpen) {
+ setWasOpen(createCollectionOpen);
+ if (createCollectionOpen) {
+ setCreateCollectionName("");
+ setCreateCollectionError(null);
+ }
+ }
+ const handleCreateCollectionConfirm = useCallback(async () => {
+ if (!onCreateCollection || !createCollectionName.trim()) {
+ return;
+ }
+
+ setCreatingCollection(true);
+ setCreateCollectionError(null);
+ try {
+ const newCollectionID = await onCreateCollection(
+ createCollectionName.trim(),
+ );
+ onClose();
+ setCreateCollectionName("");
+ onSelectCollection(newCollectionID);
+ } catch (error) {
+ setCreateCollectionError(
+ error instanceof Error
+ ? error.message
+ : t("failedToCreateCollection"),
+ );
+ } finally {
+ setCreatingCollection(false);
+ }
+ }, [createCollectionName, onCreateCollection, onSelectCollection, onClose]);
+
+ const handleNameChange = (value: string) => {
+ setCreateCollectionName(value);
+ setCreateCollectionError(null);
+ };
+ return (
+ <Dialog
+ slotProps={{
+ paper: { sx: lockerSheetPaperSx },
+ container: { sx: lockerSheetContainerSx },
+ }}
+ open={createCollectionOpen}
+ onClose={() => {
+ if (!creatingCollection) {
+ onCloseCreateCollectionDialog();
+ }
+ }}
+ fullWidth
+ maxWidth="xs"
+ >
+ <Stack>
+ <Stack
+ direction="row"
+ sx={{ alignItems: "center", gap: 1.5, minHeight: 38 }}
+ >
+ <Typography
+ sx={{ ...lockerTextH2Sx, flex: 1, minWidth: 0 }}
+ >
+ {t("createCollection")}
+ </Typography>
+ <IconButton
+ aria-label={t("close")}
+ onClick={onCloseCreateCollectionDialog}
+ disabled={creatingCollection}
+ sx={lockerHeaderIconButtonSx}
+ >
+ <HugeiconsIcon
+ icon={Cancel01Icon}
+ size={18}
+ strokeWidth={1.5}
+ />
+ </IconButton>
+ </Stack>
+ <Box sx={{ mt: 2.5 }}>
+ <FormField
+ value={createCollectionName}
+ onChange={(event) =>
+ handleNameChange(event.target.value)
+ }
+ label={t("enterCollectionName")}
+ required
+ autoFocus
+ disabled={creatingCollection}
+ onKeyDown={(event) => {
+ if (event.key === "Enter") {
+ void handleCreateCollectionConfirm();
+ }
+ }}
+ />
+ </Box>
+ {createCollectionError && (
+ <Typography
+ sx={(theme) => ({
+ ...lockerTextMiniSx,
+ mt: 1.5,
+ ...lockerColorSx(theme, { color: "warning" }),
+ })}
+ >
+ {createCollectionError}
+ </Typography>
+ )}
+ <LoadingButton
+ fullWidth
+ color="primary"
+ loading={creatingCollection}
+ disabled={!createCollectionName.trim()}
+ onClick={handleCreateCollectionConfirm}
+ sx={(theme) => ({
+ ...lockerTextBodyBoldSx,
+ mt: 3,
+ borderRadius: "20px",
+ textTransform: "none",
+ ...lockerColorSx(theme, {
+ backgroundColor: "primary",
+ color: "specialWhite",
+ }),
+ "&:hover": {
+ ...lockerColorSx(theme, {
+ backgroundColor: "primaryDark",
+ }),
+ },
+ ...lockerPrimaryButtonSx(theme, {
+ loading: creatingCollection,
+ }),
+ })}
+ >
+ {t("createCollectionButton")}
+ </LoadingButton>
+ </Stack>
+ </Dialog>
+ );
+}
diff --git a/web/apps/locker/src/components/collections/RenameCollectionDialog.tsx b/web/apps/locker/src/components/collections/RenameCollectionDialog.tsx
new file mode 100644
index 0000000000..faa1c655ad
--- /dev/null
+++ b/web/apps/locker/src/components/collections/RenameCollectionDialog.tsx
@@ -0,0 +1,194 @@
+import { FormField } from "@/components/ui/FormField";
+import { lockerSheetContainerSx, lockerSheetPaperSx } from "@/styles/dialog";
+import {
+ lockerHeaderIconButtonSx,
+ lockerPrimaryButtonSx,
+} from "@/styles/fields";
+import {
+ lockerColorSx,
+ lockerTextBodyBoldSx,
+ lockerTextH2Sx,
+ lockerTextMiniSx,
+} from "@/styles/tokens";
+import type { LockerCollection } from "@/types";
+import { Cancel01Icon } from "@hugeicons/core-free-icons";
+import { HugeiconsIcon } from "@hugeicons/react";
+import { Box, Dialog, IconButton, Stack, Typography } from "@mui/material";
+import { LoadingButton } from "ente-base/components/mui/LoadingButton";
+import log from "ente-base/log";
+import { t } from "i18next";
+import { useCallback, useEffect, useState } from "react";
+
+interface RenameCollectionDialogProps {
+ collection: LockerCollection | null;
+ onClose: () => void;
+ onRenameCollection?: (
+ collectionID: number,
+ newName: string,
+ ) => void | Promise<void>;
+}
+export function RenameCollectionDialog({
+ collection,
+ onClose,
+ onRenameCollection,
+}: RenameCollectionDialogProps) {
+ const renameCollectionID = collection?.id ?? null;
+ const renameCollectionOpen = collection !== null;
+ const [renameValue, setRenameValue] = useState(collection?.name ?? "");
+ const [renameError, setRenameError] = useState<string | null>(null);
+ const [renamingCollection, setRenamingCollection] = useState(false);
+ const [previousCollection, setPreviousCollection] = useState(collection);
+ if (previousCollection !== collection) {
+ setPreviousCollection(collection);
+ if (collection) {
+ setRenameValue(collection.name);
+ setRenameError(null);
+ }
+ }
+ useEffect(() => {
+ if (renameCollectionID === null) {
+ setRenameError(null);
+ setRenamingCollection(false);
+ }
+ }, [renameCollectionID]);
+
+ const handleRenameConfirm = useCallback(async () => {
+ if (
+ renameCollectionID === null ||
+ !renameValue.trim() ||
+ !onRenameCollection ||
+ renamingCollection
+ ) {
+ return;
+ }
+
+ setRenamingCollection(true);
+ setRenameError(null);
+ try {
+ await Promise.resolve(
+ onRenameCollection(renameCollectionID, renameValue.trim()),
+ );
+ onClose();
+ setRenameValue("");
+ } catch (error) {
+ log.error("Failed to rename Locker collection", error);
+ setRenameError(
+ error instanceof Error ? error.message : t("generic_error"),
+ );
+ } finally {
+ setRenamingCollection(false);
+ }
+ }, [
+ onClose,
+ onRenameCollection,
+ renameCollectionID,
+ renameValue,
+ renamingCollection,
+ ]);
+
+ const onCloseRenameDialog = () => {
+ if (renamingCollection) return;
+ onClose();
+ setRenameError(null);
+ };
+ const handleNameChange = (value: string) => {
+ setRenameValue(value);
+ setRenameError(null);
+ };
+ return (
+ <Dialog
+ slotProps={{
+ paper: { sx: lockerSheetPaperSx },
+ container: { sx: lockerSheetContainerSx },
+ }}
+ open={renameCollectionOpen}
+ onClose={() => {
+ if (!renamingCollection) {
+ onCloseRenameDialog();
+ }
+ }}
+ fullWidth
+ maxWidth="xs"
+ >
+ <Stack>
+ <Stack
+ direction="row"
+ sx={{ alignItems: "center", gap: 1.5, minHeight: 38 }}
+ >
+ <Typography
+ sx={{ ...lockerTextH2Sx, flex: 1, minWidth: 0 }}
+ >
+ {t("renameCollection")}
+ </Typography>
+ <IconButton
+ aria-label={t("close")}
+ onClick={onCloseRenameDialog}
+ disabled={renamingCollection}
+ sx={lockerHeaderIconButtonSx}
+ >
+ <HugeiconsIcon
+ icon={Cancel01Icon}
+ size={18}
+ strokeWidth={1.5}
+ />
+ </IconButton>
+ </Stack>
+ <Box sx={{ mt: 2.5 }}>
+ <FormField
+ value={renameValue}
+ onChange={(event) =>
+ handleNameChange(event.target.value)
+ }
+ label={t("enterCollectionName")}
+ required
+ autoFocus
+ disabled={renamingCollection}
+ onKeyDown={(event) => {
+ if (event.key === "Enter") {
+ void handleRenameConfirm();
+ }
+ }}
+ />
+ </Box>
+ {renameError && (
+ <Typography
+ sx={(theme) => ({
+ ...lockerTextMiniSx,
+ mt: 1.5,
+ ...lockerColorSx(theme, { color: "warning" }),
+ })}
+ >
+ {renameError}
+ </Typography>
+ )}
+ <LoadingButton
+ fullWidth
+ color="primary"
+ loading={renamingCollection}
+ disabled={!renameValue.trim()}
+ onClick={handleRenameConfirm}
+ sx={(theme) => ({
+ ...lockerTextBodyBoldSx,
+ mt: 3,
+ borderRadius: "20px",
+ textTransform: "none",
+ ...lockerColorSx(theme, {
+ backgroundColor: "primary",
+ color: "specialWhite",
+ }),
+ "&:hover": {
+ ...lockerColorSx(theme, {
+ backgroundColor: "primaryDark",
+ }),
+ },
+ ...lockerPrimaryButtonSx(theme, {
+ loading: renamingCollection,
+ }),
+ })}
+ >
+ {t("save")}
+ </LoadingButton>
+ </Stack>
+ </Dialog>
+ );
+}
diff --git a/web/apps/locker/src/components/items/ItemList.tsx b/web/apps/locker/src/components/items/ItemList.tsx
index 661ace2280..fc3fb7ae0d 100644
--- a/web/apps/locker/src/components/items/ItemList.tsx
+++ b/web/apps/locker/src/components/items/ItemList.tsx
@@ -1,12 +1,22 @@
+import { CollectionFilters } from "@/components/collections/CollectionFilters";
+import { CollectionGrid } from "@/components/collections/CollectionGrid";
+import { CollectionHeaderMenu } from "@/components/collections/CollectionHeaderMenu";
+import { CreateCollectionDialog } from "@/components/collections/CreateCollectionDialog";
+import { RenameCollectionDialog } from "@/components/collections/RenameCollectionDialog";
+import { ItemDetailView } from "@/components/items/ItemDetailView";
+import { ItemsSection } from "@/components/items/ItemsSection";
+import { LockerFileLinkDialog } from "@/components/items/LockerFileLinkDialog";
+import { RestoreItemDialog } from "@/components/items/RestoreItemDialog";
+import { SelectionActionBar } from "@/components/items/SelectionActionBar";
+import { LockerConfirmDialog } from "@/components/ui/LockerConfirmDialog";
+import { downloadLockerFile } from "@/services/remote";
import {
- LockerMenuOption,
- LockerOverflowMenu,
-} from "@/components/ui/LockerMenu";
-import {
- deleteLockerFileShareLink,
- downloadLockerFile,
- getOrCreateLockerFileShareLink,
-} from "@/services/remote";
+ lockerColorSx,
+ lockerContentMaxWidth,
+ lockerTextDisplay2Sx,
+ lockerTextLargeSx,
+ lockerTextMiniSx,
+} from "@/styles/tokens";
import type { LockerCollection, LockerItem } from "@/types";
import {
canEditCollection,
@@ -14,63 +24,28 @@ import {
canOpenCollectionSharing,
canShareLockerFileLink,
getItemTitle,
- hasDownloadableObject,
- isImportantCollection,
isLockerItemOwner,
restoreTargetLockerCollections,
sortLockerCollections,
} from "@/types";
-import {
- Delete02Icon,
- Link01Icon,
- PlusSignIcon,
- StarIcon,
- Wallet05Icon,
-} from "@hugeicons/core-free-icons";
+import { Delete02Icon, PlusSignIcon } from "@hugeicons/core-free-icons";
import { HugeiconsIcon } from "@hugeicons/react";
import ArrowBackRoundedIcon from "@mui/icons-material/ArrowBackRounded";
-import CheckCircleRoundedIcon from "@mui/icons-material/CheckCircleRounded";
-import ChevronLeftRoundedIcon from "@mui/icons-material/ChevronLeftRounded";
-import ChevronRightRoundedIcon from "@mui/icons-material/ChevronRightRounded";
-import ClearRoundedIcon from "@mui/icons-material/ClearRounded";
-import DeleteOutlinedIcon from "@mui/icons-material/DeleteOutlined";
-import EditOutlinedIcon from "@mui/icons-material/EditOutlined";
-import FileDownloadOutlinedIcon from "@mui/icons-material/FileDownloadOutlined";
-import FilterListRoundedIcon from "@mui/icons-material/FilterListRounded";
-import LogoutOutlinedIcon from "@mui/icons-material/LogoutOutlined";
import ShareOutlinedIcon from "@mui/icons-material/ShareOutlined";
import {
Box,
- Button,
- ButtonBase,
IconButton,
+ Snackbar,
Stack,
Tooltip,
Typography,
} from "@mui/material";
import { savedLocalUser } from "ente-accounts/services/accounts-db";
-import { isHTTPErrorWithStatus } from "ente-base/http";
import log from "ente-base/log";
import { t } from "i18next";
-import React, {
- useCallback,
- useEffect,
- useMemo,
- useRef,
- useState,
-} from "react";
-import {
- lockerColors,
- lockerColorSx,
- lockerContentMaxWidth,
- lockerTextBodySx,
- lockerTextDisplay2Sx,
- lockerTextLargeSx,
- lockerTextMiniSx,
-} from "../../styles/tokens";
-import { ItemCard } from "./ItemCard";
-import { ItemDetailView } from "./ItemDetailView";
-import { ItemListDialogs } from "./ItemListDialogs";
+import React, { useCallback, useEffect, useMemo, useState } from "react";
+import { useFileLink } from "./use-file-link";
+import { useItemSelection } from "./use-item-selection";
const uniqueCollectionsByID = (collections: LockerCollection[]) => {
const seen = new Set<number>();
@@ -135,46 +110,17 @@ export const ItemList: React.FC<ItemListProps> = ({
const currentUserID = savedLocalUser()?.id;
const [selectedItemID, setSelectedItemID] = useState<number | null>(null);
const [restoreItemID, setRestoreItemID] = useState<number | null>(null);
- const [restoreCollectionID, setRestoreCollectionID] = useState<
- number | null
- >(null);
- const [restoreError, setRestoreError] = useState<string | null>(null);
- const [restoringItem, setRestoringItem] = useState(false);
- const [renameCollectionID, setRenameCollectionID] = useState<number | null>(
- null,
- );
- const [renameValue, setRenameValue] = useState("");
- const [renameError, setRenameError] = useState<string | null>(null);
- const [renamingCollection, setRenamingCollection] = useState(false);
+ const [renameCollection, setRenameCollection] =
+ useState<LockerCollection | null>(null);
const [createCollectionOpen, setCreateCollectionOpen] = useState(false);
- const [createCollectionName, setCreateCollectionName] = useState("");
- const [creatingCollection, setCreatingCollection] = useState(false);
- const [createCollectionError, setCreateCollectionError] = useState<
- string | null
- >(null);
const [homeSelectedCollectionIDs, setHomeSelectedCollectionIDs] = useState<
number[]
>([]);
- const [collectionFilterAnchorEl, setCollectionFilterAnchorEl] =
- useState<HTMLElement | null>(null);
- const [selectionMode, setSelectionMode] = useState(false);
- const [selectedItemIDs, setSelectedItemIDs] = useState<number[]>([]);
const [bulkDownloading, setBulkDownloading] = useState(false);
const [bulkDownloadProgress, setBulkDownloadProgress] = useState<{
completed: number;
total: number;
} | null>(null);
- const [activeFileLinkItemID, setActiveFileLinkItemID] = useState<
- number | null
- >(null);
- const [activeFileLink, setActiveFileLink] = useState<{
- linkID: string;
- url: string;
- } | null>(null);
- const [isCreatingFileLink, setIsCreatingFileLink] = useState(false);
- const [isDeletingFileLink, setIsDeletingFileLink] = useState(false);
- const [isDeleteFileLinkConfirmOpen, setIsDeleteFileLinkConfirmOpen] =
- useState(false);
const [feedbackMessage, setFeedbackMessage] = useState<string | null>(null);
const displayCollections = useMemo(
@@ -259,13 +205,20 @@ export const ItemList: React.FC<ItemListProps> = ({
: (trashItemsByID.get(restoreItemID) ?? null),
[restoreItemID, trashItemsByID],
);
- const activeFileLinkItem = useMemo(
- () =>
- activeFileLinkItemID === null
- ? null
- : (allItemsByID.get(activeFileLinkItemID) ?? null),
- [activeFileLinkItemID, allItemsByID],
- );
+ const {
+ activeFileLinkItem,
+ activeFileLink,
+ canNativeShare,
+ isCreatingFileLink,
+ isDeletingFileLink,
+ isDeleteFileLinkConfirmOpen,
+ setIsDeleteFileLinkConfirmOpen,
+ closeFileLinkDialog,
+ openFileLinkDialog,
+ copyActiveFileLink,
+ shareActiveFileLink,
+ deleteActiveFileLink,
+ } = useFileLink({ allItemsByID, currentUserID, setFeedbackMessage });
const trimmedSearch = searchTerm.trim();
const searchQuery = trimmedSearch.toLowerCase();
const searchActive = searchQuery.length > 0;
@@ -377,48 +330,33 @@ export const ItemList: React.FC<ItemListProps> = ({
}
return isHomeView ? homeFilteredItems : sortedItems;
}, [homeFilteredItems, isCollectionsView, isHomeView, sortedItems]);
- const visibleSelectableItems = useMemo(() => visibleItems, [visibleItems]);
- const visibleSelectableItemIDs = useMemo(
- () => visibleSelectableItems.map((item) => item.id),
- [visibleSelectableItems],
- );
- const selectedVisibleItems = useMemo(() => {
- const selectedIDSet = new Set(selectedItemIDs);
- return visibleSelectableItems.filter((item) =>
- selectedIDSet.has(item.id),
- );
- }, [selectedItemIDs, visibleSelectableItems]);
- const selectedDownloadableItems = useMemo(
- () =>
- selectedVisibleItems.filter(
- (item) => item.type === "file" && hasDownloadableObject(item),
- ),
- [selectedVisibleItems],
- );
- const selectedOwnedItems = useMemo(
- () =>
- selectedVisibleItems.filter((item) =>
- isLockerItemOwner(item, currentUserID),
- ),
- [currentUserID, selectedVisibleItems],
- );
- const selectedItemIDSet = useMemo(
- () => new Set(selectedItemIDs),
- [selectedItemIDs],
+ const closeItemDetail = useCallback(() => setSelectedItemID(null), []);
+ const clearBulkDownloadProgress = useCallback(
+ () => setBulkDownloadProgress(null),
+ [],
);
- const canBulkSelectVisibleItems =
- !isTrashView && !isCollectionsView && visibleSelectableItems.length > 0;
- const skippedSharedSelectionCount =
- selectedVisibleItems.length - selectedOwnedItems.length;
- const skippedDownloadSelectionCount =
- selectedVisibleItems.length - selectedDownloadableItems.length;
- const allVisibleItemsSelected =
- visibleSelectableItemIDs.length > 0 &&
- selectedVisibleItems.length === visibleSelectableItemIDs.length;
- const canNativeShare =
- typeof navigator !== "undefined" &&
- typeof navigator.share === "function";
-
+ const {
+ selectionMode,
+ selectedItemIDSet,
+ selectedVisibleItems,
+ selectedDownloadableItems,
+ selectedOwnedItems,
+ canBulkSelectVisibleItems,
+ skippedSharedSelectionCount,
+ skippedDownloadSelectionCount,
+ allVisibleItemsSelected,
+ startSelectionModeForItem,
+ stopSelectionMode,
+ toggleItemSelection,
+ toggleSelectAllVisibleItems,
+ } = useItemSelection({
+ visibleItems,
+ currentUserID,
+ isTrashView,
+ isCollectionsView,
+ onStartSelection: closeItemDetail,
+ onStopSelection: clearBulkDownloadProgress,
+ });
useEffect(() => {
if (selectedItemID !== null && !selectedItem) {
setSelectedItemID(null);
@@ -428,131 +366,9 @@ export const ItemList: React.FC<ItemListProps> = ({
useEffect(() => {
if (restoreItemID !== null && !restoreItem) {
setRestoreItemID(null);
- setRestoreCollectionID(null);
}
}, [restoreItem, restoreItemID]);
- useEffect(() => {
- if (
- restoreCollectionID !== null &&
- !restoreCollections.some(
- (collection) => collection.id === restoreCollectionID,
- )
- ) {
- setRestoreCollectionID(null);
- }
- }, [restoreCollectionID, restoreCollections]);
-
- useEffect(() => {
- if (restoreItemID === null) {
- setRestoreError(null);
- setRestoringItem(false);
- }
- }, [restoreItemID]);
-
- useEffect(() => {
- if (renameCollectionID === null) {
- setRenameError(null);
- setRenamingCollection(false);
- }
- }, [renameCollectionID]);
-
- useEffect(() => {
- if (activeFileLinkItemID !== null && !activeFileLinkItem) {
- setActiveFileLinkItemID(null);
- setActiveFileLink(null);
- setIsCreatingFileLink(false);
- setIsDeletingFileLink(false);
- setIsDeleteFileLinkConfirmOpen(false);
- }
- }, [activeFileLinkItem, activeFileLinkItemID]);
-
- const handleRestoreConfirm = useCallback(async () => {
- if (
- !restoreItem ||
- restoreCollectionID === null ||
- !onRestoreItem ||
- restoringItem
- ) {
- return;
- }
-
- setRestoringItem(true);
- setRestoreError(null);
- try {
- await Promise.resolve(
- onRestoreItem(restoreItem, restoreCollectionID),
- );
- setRestoreItemID(null);
- setRestoreCollectionID(null);
- } catch (error) {
- log.error("Failed to restore Locker item", error);
- setRestoreError(
- error instanceof Error ? error.message : t("generic_error"),
- );
- } finally {
- setRestoringItem(false);
- }
- }, [onRestoreItem, restoreCollectionID, restoreItem, restoringItem]);
-
- const handleRenameConfirm = useCallback(async () => {
- if (
- renameCollectionID === null ||
- !renameValue.trim() ||
- !onRenameCollection ||
- renamingCollection
- ) {
- return;
- }
-
- setRenamingCollection(true);
- setRenameError(null);
- try {
- await Promise.resolve(
- onRenameCollection(renameCollectionID, renameValue.trim()),
- );
- setRenameCollectionID(null);
- setRenameValue("");
- } catch (error) {
- log.error("Failed to rename Locker collection", error);
- setRenameError(
- error instanceof Error ? error.message : t("generic_error"),
- );
- } finally {
- setRenamingCollection(false);
- }
- }, [
- onRenameCollection,
- renameCollectionID,
- renameValue,
- renamingCollection,
- ]);
-
- const handleCreateCollectionConfirm = useCallback(async () => {
- if (!onCreateCollection || !createCollectionName.trim()) {
- return;
- }
-
- setCreatingCollection(true);
- setCreateCollectionError(null);
- try {
- const newCollectionID = await onCreateCollection(
- createCollectionName.trim(),
- );
- setCreateCollectionOpen(false);
- setCreateCollectionName("");
- onSelectCollection(newCollectionID);
- } catch (error) {
- setCreateCollectionError(
- error instanceof Error
- ? error.message
- : t("failedToCreateCollection"),
- );
- } finally {
- setCreatingCollection(false);
- }
- }, [createCollectionName, onCreateCollection, onSelectCollection]);
-
const canEditSelectedCollection =
selectedCollection !== null &&
currentUserID !== undefined &&
@@ -579,139 +395,6 @@ export const ItemList: React.FC<ItemListProps> = ({
const clearHomeCollectionSelection = useCallback(() => {
setHomeSelectedCollectionIDs([]);
}, []);
- const openCollectionFilterMenu = useCallback(
- (event: React.MouseEvent<HTMLElement>) => {
- setCollectionFilterAnchorEl(event.currentTarget);
- },
- [],
- );
- const closeCollectionFilterMenu = useCallback(() => {
- setCollectionFilterAnchorEl(null);
- }, []);
- const startSelectionModeForItem = useCallback((item: LockerItem) => {
- setSelectionMode(true);
- setSelectedItemIDs([item.id]);
- setSelectedItemID(null);
- }, []);
- const stopSelectionMode = useCallback(() => {
- setSelectionMode(false);
- setSelectedItemIDs([]);
- setBulkDownloadProgress(null);
- }, []);
- const toggleItemSelection = useCallback((item: LockerItem) => {
- setSelectedItemIDs((current) =>
- current.includes(item.id)
- ? current.filter((id) => id !== item.id)
- : [...current, item.id],
- );
- }, []);
- const toggleSelectAllVisibleItems = useCallback(() => {
- setSelectedItemIDs((current) =>
- current.length === visibleSelectableItemIDs.length
- ? []
- : visibleSelectableItemIDs,
- );
- }, [visibleSelectableItemIDs]);
- const closeFileLinkDialog = useCallback(() => {
- if (
- isCreatingFileLink ||
- isDeletingFileLink ||
- isDeleteFileLinkConfirmOpen
- ) {
- return;
- }
- setActiveFileLinkItemID(null);
- setActiveFileLink(null);
- }, [isCreatingFileLink, isDeleteFileLinkConfirmOpen, isDeletingFileLink]);
- const openFileLinkDialog = useCallback(
- async (item: LockerItem) => {
- if (!canShareLockerFileLink(item, currentUserID)) {
- setFeedbackMessage(t("shareNotSupportedForSharedFiles"));
- return;
- }
-
- setActiveFileLinkItemID(item.id);
- setActiveFileLink(null);
- setIsCreatingFileLink(true);
- try {
- const link = await getOrCreateLockerFileShareLink(item.id);
- setActiveFileLink(link);
- } catch (error) {
- log.error(
- `Failed to create share link for file ${item.id}`,
- error,
- );
- setFeedbackMessage(
- isHTTPErrorWithStatus(error, 402)
- ? t("sharingRequiresPaidPlan")
- : t("failedToCreateShareLink"),
- );
- setActiveFileLinkItemID(null);
- } finally {
- setIsCreatingFileLink(false);
- }
- },
- [currentUserID],
- );
- const copyActiveFileLink = useCallback(async () => {
- if (!activeFileLink?.url) {
- return;
- }
- await navigator.clipboard.writeText(activeFileLink.url);
- setFeedbackMessage(t("linkCopiedToClipboard"));
- }, [activeFileLink?.url]);
- const shareActiveFileLink = useCallback(async () => {
- if (!activeFileLink?.url) {
- return;
- }
-
- if (canNativeShare) {
- try {
- await navigator.share({
- title: activeFileLinkItem
- ? getItemTitle(activeFileLinkItem)
- : undefined,
- url: activeFileLink.url,
- });
- return;
- } catch (error) {
- if (
- error instanceof DOMException &&
- error.name === "AbortError"
- ) {
- return;
- }
- }
- }
-
- await navigator.clipboard.writeText(activeFileLink.url);
- setFeedbackMessage(t("linkCopiedToClipboard"));
- }, [activeFileLink?.url, activeFileLinkItem, canNativeShare]);
- const deleteActiveFileLink = useCallback(async () => {
- if (!activeFileLinkItem) {
- return;
- }
-
- setIsDeletingFileLink(true);
- try {
- await deleteLockerFileShareLink(
- activeFileLinkItem.id,
- activeFileLink?.linkID,
- );
- setFeedbackMessage(t("shareLinkDeletedSuccessfully"));
- setActiveFileLinkItemID(null);
- setActiveFileLink(null);
- } catch (error) {
- log.error(
- `Failed to delete share link for file ${activeFileLinkItem.id}`,
- error,
- );
- setFeedbackMessage(t("failedToDeleteShareLink"));
- } finally {
- setIsDeletingFileLink(false);
- setIsDeleteFileLinkConfirmOpen(false);
- }
- }, [activeFileLink?.linkID, activeFileLinkItem]);
const downloadSelectedFiles = useCallback(async () => {
if (bulkDownloading || selectedDownloadableItems.length === 0) {
return;
@@ -785,28 +468,6 @@ export const ItemList: React.FC<ItemListProps> = ({
setHomeSelectedCollectionIDs([]);
}
}, [homeSelectedCollectionIDs.length, isHomeView]);
- React.useEffect(() => {
- if (selectionMode && selectedItemIDs.length === 0) {
- setSelectionMode(false);
- }
- }, [selectedItemIDs.length, selectionMode]);
- React.useEffect(() => {
- if (
- isTrashView ||
- isCollectionsView ||
- visibleSelectableItemIDs.length === 0
- ) {
- setSelectionMode(false);
- setSelectedItemIDs([]);
- return;
- }
-
- const visibleItemIDSet = new Set(visibleSelectableItemIDs);
- setSelectedItemIDs((current) =>
- current.filter((id) => visibleItemIDSet.has(id)),
- );
- }, [isCollectionsView, isTrashView, visibleSelectableItemIDs]);
-
return (
<Stack
sx={{ flex: 1, minHeight: 0, overflow: "hidden", height: "100%" }}
@@ -838,57 +499,21 @@ export const ItemList: React.FC<ItemListProps> = ({
{isHomeView && (
<>
{displayCollections.length > 0 && (
- <Stack
- direction="row"
- sx={{
- width: "100%",
- maxWidth: lockerContentMaxWidth,
- mx: "auto",
- alignItems: "center",
- gap: 1,
- mb: 2,
- minWidth: 0,
- }}
- >
- <CollectionFilterChip
- selected={
- homeSelectedCollectionIDs.length > 0
- }
- onClick={openCollectionFilterMenu}
- />
- <Box
- key={orderedHomeCollections
- .map((collection) => collection.id)
- .join("-")}
- sx={{
- flex: 1,
- minWidth: 0,
- "@keyframes chipBarRefresh": {
- "0%": {
- opacity: 0.7,
- transform:
- "translateY(2px)",
- },
- "100%": {
- opacity: 1,
- transform: "translateY(0)",
- },
- },
- animation:
- "chipBarRefresh 220ms ease-out",
- }}
- >
- <CollectionChipFilters
- collections={orderedHomeCollections}
- selectedCollectionIDs={
- homeSelectedCollectionIDs
- }
- onToggleCollection={
- toggleHomeCollection
- }
- />
- </Box>
- </Stack>
+ <CollectionFilters
+ orderedHomeCollections={
+ orderedHomeCollections
+ }
+ dropdownHomeCollections={
+ dropdownHomeCollections
+ }
+ homeSelectedCollectionIDs={
+ homeSelectedCollectionIDs
+ }
+ toggleHomeCollection={toggleHomeCollection}
+ clearHomeCollectionSelection={
+ clearHomeCollectionSelection
+ }
+ />
)}
<ItemsSection
@@ -899,7 +524,6 @@ export const ItemList: React.FC<ItemListProps> = ({
onPermanentlyDelete={onPermanentlyDelete}
onRequestRestore={(item) => {
setRestoreItemID(item.id);
- setRestoreCollectionID(null);
}}
onSelectItem={(item) =>
setSelectedItemID(item.id)
@@ -952,10 +576,6 @@ export const ItemList: React.FC<ItemListProps> = ({
"createCollectionButton",
)}
onClick={() => {
- setCreateCollectionError(
- null,
- );
- setCreateCollectionName("");
setCreateCollectionOpen(
true,
);
@@ -1002,10 +622,7 @@ export const ItemList: React.FC<ItemListProps> = ({
onRequestRenameCollection={(
collection,
) => {
- setRenameCollectionID(
- collection.id,
- );
- setRenameValue(collection.name);
+ setRenameCollection(collection);
}}
onDeleteCollection={onDeleteCollection}
/>
@@ -1040,10 +657,7 @@ export const ItemList: React.FC<ItemListProps> = ({
onRequestRenameCollection={(
collection,
) => {
- setRenameCollectionID(
- collection.id,
- );
- setRenameValue(collection.name);
+ setRenameCollection(collection);
}}
onDeleteCollection={onDeleteCollection}
/>
@@ -1065,7 +679,6 @@ export const ItemList: React.FC<ItemListProps> = ({
onPermanentlyDelete={onPermanentlyDelete}
onRequestRestore={(item) => {
setRestoreItemID(item.id);
- setRestoreCollectionID(null);
}}
onSelectItem={(item) =>
setSelectedItemID(item.id)
@@ -1190,11 +803,8 @@ export const ItemList: React.FC<ItemListProps> = ({
canEditSelectedCollection &&
onRenameCollection
? () => {
- setRenameCollectionID(
- selectedCollection.id,
- );
- setRenameValue(
- selectedCollection.name,
+ setRenameCollection(
+ selectedCollection,
);
}
: undefined
@@ -1231,7 +841,6 @@ export const ItemList: React.FC<ItemListProps> = ({
onPermanentlyDelete={onPermanentlyDelete}
onRequestRestore={(item) => {
setRestoreItemID(item.id);
- setRestoreCollectionID(null);
}}
onSelectItem={(item) =>
setSelectedItemID(item.id)
@@ -1333,80 +942,58 @@ export const ItemList: React.FC<ItemListProps> = ({
}
/>
- <ItemListDialogs
- activeFileLinkItemTitle={
+ <LockerFileLinkDialog
+ open={activeFileLinkItem !== null}
+ itemTitle={
activeFileLinkItem ? getItemTitle(activeFileLinkItem) : ""
}
- activeFileLinkURL={activeFileLink?.url ?? null}
- canNativeShare={canNativeShare}
- closeCollectionFilterMenu={closeCollectionFilterMenu}
- closeFileLinkDialog={closeFileLinkDialog}
- clearHomeCollectionSelection={clearHomeCollectionSelection}
- collectionFilterAnchorEl={collectionFilterAnchorEl}
- createCollectionError={createCollectionError}
- createCollectionName={createCollectionName}
- createCollectionOpen={createCollectionOpen}
- creatingCollection={creatingCollection}
- deleteFileLink={() => void deleteActiveFileLink()}
- dropdownHomeCollections={dropdownHomeCollections}
- feedbackMessage={feedbackMessage}
- fileLinkDialogOpen={activeFileLinkItem !== null}
- homeSelectedCollectionIDs={homeSelectedCollectionIDs}
- isCreatingFileLink={isCreatingFileLink}
- isDeleteFileLinkConfirmOpen={isDeleteFileLinkConfirmOpen}
- isDeletingFileLink={isDeletingFileLink}
- onCloseCreateCollectionDialog={() =>
- setCreateCollectionOpen(false)
- }
- onCloseFeedback={() => setFeedbackMessage(null)}
- onCloseRenameDialog={() => {
- if (renamingCollection) {
- return;
- }
- setRenameCollectionID(null);
- setRenameError(null);
- }}
- onCloseRestoreDialog={() => {
- if (restoringItem) {
- return;
+ url={activeFileLink?.url}
+ loading={isCreatingFileLink}
+ deleting={isDeletingFileLink}
+ showShareAction={canNativeShare}
+ onClose={closeFileLinkDialog}
+ onCopy={() => void copyActiveFileLink()}
+ onShare={() => void shareActiveFileLink()}
+ onDelete={() => setIsDeleteFileLinkConfirmOpen(true)}
+ />
+
+ <LockerConfirmDialog
+ open={isDeleteFileLinkConfirmOpen}
+ illustration="/images/file_delete_icon.png"
+ title={t("deleteShareLinkDialogTitle")}
+ body={t("deleteShareLinkConfirmation")}
+ confirmLabel={t("delete")}
+ loading={isDeletingFileLink}
+ onClose={() => {
+ if (!isDeletingFileLink) {
+ setIsDeleteFileLinkConfirmOpen(false);
}
- setRestoreItemID(null);
- setRestoreCollectionID(null);
- setRestoreError(null);
}}
- onConfirmCreateCollection={() =>
- void handleCreateCollectionConfirm()
- }
- onConfirmRename={handleRenameConfirm}
- onConfirmRestore={handleRestoreConfirm}
- onCopyFileLink={() => void copyActiveFileLink()}
- onRequestDeleteFileLink={() =>
- setIsDeleteFileLinkConfirmOpen(true)
- }
- onShareFileLink={() => void shareActiveFileLink()}
- onToggleHomeCollection={toggleHomeCollection}
- renameError={renameError}
- renameCollectionOpen={renameCollectionID !== null}
- renamingCollection={renamingCollection}
- renameValue={renameValue}
+ onConfirm={() => void deleteActiveFileLink()}
+ />
+
+ <RestoreItemDialog
+ restoreItem={restoreItem}
restoreCollections={restoreCollections}
- restoreError={restoreError}
- restoreCollectionID={restoreCollectionID}
- restoreDialogOpen={restoreItem !== null}
- restoringItem={restoringItem}
- setCreateCollectionName={(value) => {
- setCreateCollectionName(value);
- setCreateCollectionError(null);
- }}
- setDeleteFileLinkConfirmOpen={setIsDeleteFileLinkConfirmOpen}
- setRenameValue={(value) => {
- setRenameValue(value);
- setRenameError(null);
- }}
- setRestoreCollectionID={(collectionID) => {
- setRestoreCollectionID(collectionID);
- setRestoreError(null);
- }}
+ onClose={() => setRestoreItemID(null)}
+ onRestoreItem={onRestoreItem}
+ />
+ <RenameCollectionDialog
+ collection={renameCollection}
+ onClose={() => setRenameCollection(null)}
+ onRenameCollection={onRenameCollection}
+ />
+ <CreateCollectionDialog
+ open={createCollectionOpen}
+ onClose={() => setCreateCollectionOpen(false)}
+ onCreateCollection={onCreateCollection}
+ onSelectCollection={onSelectCollection}
+ />
+ <Snackbar
+ open={feedbackMessage !== null}
+ message={feedbackMessage}
+ autoHideDuration={2500}
+ onClose={() => setFeedbackMessage(null)}
/>
</Stack>
);
@@ -1511,566 +1098,6 @@ const SectionHeader: React.FC<{
</Stack>
);
-const ItemsSection: React.FC<{
- items: LockerItem[];
- isTrashView: boolean;
- onEditItem?: (item: LockerItem) => void;
- onDeleteItem?: (item: LockerItem) => void;
- onPermanentlyDelete?: (items: LockerItem[]) => void;
- onRequestRestore: (item: LockerItem) => void;
- onSelectItem: (item: LockerItem) => void;
- currentUserID?: number;
- onShareLink?: (item: LockerItem) => void;
- selectionMode?: boolean;
- selectedItemIDSet?: Set<number>;
- onToggleItemSelection?: (item: LockerItem) => void;
- onStartSelection?: (item: LockerItem) => void;
- emptyState: React.ReactNode;
-}> = ({
- items,
- isTrashView,
- onEditItem,
- onDeleteItem,
- onPermanentlyDelete,
- onRequestRestore,
- onSelectItem,
- currentUserID,
- onShareLink,
- selectionMode,
- selectedItemIDSet,
- onToggleItemSelection,
- onStartSelection,
- emptyState,
-}) =>
- items.length > 0 ? (
- <Stack
- sx={{ maxWidth: lockerContentMaxWidth, mx: "auto", gap: 1, mt: 0 }}
- >
- {items.map((item) => {
- const isOwnedByCurrentUser = isLockerItemOwner(
- item,
- currentUserID,
- );
- return (
- <ItemCard
- key={item.id}
- item={item}
- isTrashView={isTrashView}
- isIncomingShared={!isOwnedByCurrentUser}
- onClick={() => onSelectItem(item)}
- onEdit={
- onEditItem && isOwnedByCurrentUser
- ? onEditItem
- : undefined
- }
- onDelete={
- onDeleteItem && isOwnedByCurrentUser
- ? onDeleteItem
- : undefined
- }
- deleteDisabledHint={
- onDeleteItem &&
- !isTrashView &&
- !isOwnedByCurrentUser
- ? t("actionNotSupportedForSharedFiles", {
- count: 1,
- })
- : undefined
- }
- onPermanentlyDelete={onPermanentlyDelete}
- onRestore={
- isTrashView
- ? (trashItem) => onRequestRestore(trashItem)
- : undefined
- }
- onShareLink={
- onShareLink &&
- canShareLockerFileLink(item, currentUserID)
- ? onShareLink
- : undefined
- }
- selectionMode={selectionMode}
- selectable
- selected={selectedItemIDSet?.has(item.id)}
- onToggleSelection={onToggleItemSelection}
- onLongPressSelect={onStartSelection}
- />
- );
- })}
- </Stack>
- ) : (
- <Box sx={{ maxWidth: lockerContentMaxWidth, mx: "auto" }}>
- {emptyState}
- </Box>
- );
-
-const SelectionActionBar: React.FC<{
- selectedCount: number;
- allSelected: boolean;
- bulkDownloading: boolean;
- bulkDownloadProgress: { completed: number; total: number } | null;
- canDownload: boolean;
- canDelete: boolean;
- onToggleSelectAll: () => void;
- onDownload: () => void;
- onDelete: () => void;
- onDone: () => void;
-}> = ({
- selectedCount,
- allSelected,
- bulkDownloading,
- bulkDownloadProgress,
- canDownload,
- canDelete,
- onToggleSelectAll,
- onDownload,
- onDelete,
- onDone,
-}) => (
- <Box sx={{ px: { xs: 2, sm: 3 }, py: { xs: 1.25, sm: 1.5 } }}>
- <Box
- sx={(theme) => ({
- maxWidth: 760,
- mx: "auto",
- borderRadius: "20px",
- border: `1px solid ${theme.vars.palette.stroke.faint}`,
- backgroundColor: theme.vars.palette.background.paper,
- boxShadow: "0 12px 30px rgba(15, 23, 42, 0.12)",
- backdropFilter: "blur(18px)",
- px: { xs: 1.25, sm: 1.5 },
- py: 1.25,
- })}
- >
- <Stack
- direction={{ xs: "column", sm: "row" }}
- sx={{
- alignItems: { xs: "stretch", sm: "center" },
- justifyContent: "space-between",
- gap: 1,
- }}
- >
- <Stack
- direction="row"
- sx={{
- alignItems: "center",
- justifyContent: "space-between",
- gap: 1,
- }}
- >
- <Box
- sx={{
- display: "flex",
- alignItems: "center",
- gap: 1,
- minWidth: 0,
- px: 1.25,
- py: 0.875,
- borderRadius: "14px",
- backgroundColor: "rgba(16, 113, 255, 0.10)",
- border: "1px solid rgba(16, 113, 255, 0.16)",
- }}
- >
- <CheckCircleRoundedIcon
- sx={(theme) => ({
- fontSize: 18,
- ...lockerColorSx(theme, { color: "primary" }),
- flexShrink: 0,
- })}
- />
- <Typography
- variant="body"
- sx={{ fontWeight: 600, minWidth: 0 }}
- noWrap
- >
- {t("filesSelected", { count: selectedCount })}
- </Typography>
- </Box>
- <IconButton
- onClick={onDone}
- disabled={bulkDownloading}
- sx={(theme) => ({
- color: "text.muted",
- width: 38,
- height: 38,
- flexShrink: 0,
- border: `1px solid ${theme.vars.palette.stroke.faint}`,
- backgroundColor: theme.vars.palette.fill.faint,
- "&:hover": {
- backgroundColor:
- theme.vars.palette.fill.faintHover,
- },
- })}
- >
- <ClearRoundedIcon sx={{ fontSize: 18 }} />
- </IconButton>
- </Stack>
- <Stack
- direction={{ xs: "column", sm: "row" }}
- sx={{ alignItems: { xs: "stretch", sm: "center" }, gap: 1 }}
- >
- <Button
- color="secondary"
- onClick={onToggleSelectAll}
- disabled={bulkDownloading}
- sx={(theme) => ({
- minHeight: 42,
- px: 1.5,
- borderRadius: "14px",
- border: `1px solid ${theme.vars.palette.stroke.faint}`,
- backgroundColor: theme.vars.palette.fill.faint,
- "&:hover": {
- backgroundColor:
- theme.vars.palette.fill.faintHover,
- },
- })}
- >
- {allSelected ? t("deselectAll") : t("selectAll")}
- </Button>
- <Button
- variant="contained"
- startIcon={<FileDownloadOutlinedIcon />}
- onClick={onDownload}
- disabled={bulkDownloading || !canDownload}
- sx={{
- minHeight: 42,
- px: 1.75,
- borderRadius: "14px",
- boxShadow: "none",
- color: "#FFFFFF",
- background:
- "linear-gradient(180deg, #1674FF 0%, #0B5FE0 100%)",
- "& .MuiButton-startIcon": { color: "#FFFFFF" },
- "&:hover": {
- boxShadow: "none",
- background:
- "linear-gradient(180deg, #2A82FF 0%, #1269F0 100%)",
- },
- }}
- >
- {bulkDownloading && bulkDownloadProgress
- ? `${t("downloading")} ${bulkDownloadProgress.completed}/${bulkDownloadProgress.total}`
- : t("download")}
- </Button>
- <Button
- color="critical"
- startIcon={<DeleteOutlinedIcon />}
- onClick={onDelete}
- disabled={bulkDownloading || !canDelete}
- sx={{
- minHeight: 42,
- px: 1.75,
- borderRadius: "14px",
- color: "#FFFFFF",
- border: "1px solid rgba(185, 28, 28, 0.26)",
- backgroundColor: "#D14343",
- "& .MuiButton-startIcon": { color: "#FFFFFF" },
- "&:hover": { backgroundColor: "#B93838" },
- }}
- >
- {t("delete")}
- </Button>
- </Stack>
- </Stack>
- </Box>
- </Box>
-);
-
-const CollectionGrid: React.FC<{
- collections: LockerCollection[];
- onSelectCollection: (collectionID: number) => void;
- onShareCollection?: (collection: LockerCollection) => void;
- onLeaveCollection?: (collection: LockerCollection) => void;
- onRequestRenameCollection?: (collection: LockerCollection) => void;
- onDeleteCollection?: (collectionID: number) => void;
-}> = ({
- collections,
- onSelectCollection,
- onShareCollection,
- onLeaveCollection,
- onRequestRenameCollection,
- onDeleteCollection,
-}) => {
- const currentUserID = savedLocalUser()?.id;
-
- return (
- <Box
- sx={{
- width: "100%",
- maxWidth: lockerContentMaxWidth,
- mx: "auto",
- display: "grid",
- gap: 1,
- }}
- >
- {collections.map((collection) => (
- <CollectionCard
- key={collection.id}
- collection={collection}
- onClick={() => onSelectCollection(collection.id)}
- onShare={
- onShareCollection &&
- canOpenCollectionSharing(collection)
- ? () => onShareCollection(collection)
- : undefined
- }
- onLeave={
- onLeaveCollection &&
- canLeaveCollection(collection, currentUserID)
- ? () => onLeaveCollection(collection)
- : undefined
- }
- onRename={
- onRequestRenameCollection &&
- canEditCollection(collection, currentUserID)
- ? () => onRequestRenameCollection(collection)
- : undefined
- }
- onDelete={
- onDeleteCollection &&
- canEditCollection(collection, currentUserID)
- ? () => onDeleteCollection(collection.id)
- : undefined
- }
- />
- ))}
- </Box>
- );
-};
-
-const CollectionChipFilters: React.FC<{
- collections: LockerCollection[];
- selectedCollectionIDs: number[];
- onToggleCollection: (collectionID: number) => void;
-}> = ({ collections, selectedCollectionIDs, onToggleCollection }) => {
- const scrollContainerRef = useRef<HTMLDivElement | null>(null);
- const [showLeftScrollHint, setShowLeftScrollHint] = useState(false);
- const [showRightScrollHint, setShowRightScrollHint] = useState(false);
-
- const scrollLeft = () => {
- const container = scrollContainerRef.current;
- if (!container) {
- return;
- }
-
- container.scrollBy({
- left: -Math.max(container.clientWidth * 0.6, 160),
- behavior: "smooth",
- });
- };
-
- const scrollRight = () => {
- const container = scrollContainerRef.current;
- if (!container) {
- return;
- }
-
- container.scrollBy({
- left: Math.max(container.clientWidth * 0.6, 160),
- behavior: "smooth",
- });
- };
-
- useEffect(() => {
- const container = scrollContainerRef.current;
- if (!container) {
- return;
- }
-
- const updateScrollHint = () => {
- setShowLeftScrollHint(container.scrollLeft > 8);
- const remainingScroll =
- container.scrollWidth -
- container.clientWidth -
- container.scrollLeft;
- setShowRightScrollHint(remainingScroll > 8);
- };
-
- updateScrollHint();
- container.addEventListener("scroll", updateScrollHint, {
- passive: true,
- });
- window.addEventListener("resize", updateScrollHint);
-
- return () => {
- container.removeEventListener("scroll", updateScrollHint);
- window.removeEventListener("resize", updateScrollHint);
- };
- }, [collections, selectedCollectionIDs]);
-
- return (
- <Box
- sx={{ width: "100%", maxWidth: lockerContentMaxWidth, mx: "auto" }}
- >
- <Stack direction="row" sx={{ alignItems: "stretch", gap: 0 }}>
- {showLeftScrollHint && (
- <Box
- sx={{
- width: 28,
- flexShrink: 0,
- display: "flex",
- alignItems: "center",
- justifyContent: "center",
- }}
- >
- <ButtonBase
- onClick={scrollLeft}
- sx={(theme) => ({
- width: 28,
- height: "100%",
- borderRadius: "999px",
- ...lockerColorSx(theme, { color: "iconColor" }),
- })}
- >
- <ChevronLeftRoundedIcon sx={{ fontSize: 28 }} />
- </ButtonBase>
- </Box>
- )}
- <Box sx={{ position: "relative", flex: 1, minWidth: 0 }}>
- <Stack
- ref={scrollContainerRef}
- direction="row"
- sx={{
- gap: 1,
- flexWrap: "nowrap",
- overflowX: "auto",
- overflowY: "hidden",
- justifyContent: "flex-start",
- pr: 2,
- pb: 0.5,
- scrollbarWidth: "none",
- "&::-webkit-scrollbar": { display: "none" },
- }}
- >
- {collections.map((collection) => {
- const isSelected = selectedCollectionIDs.includes(
- collection.id,
- );
-
- return (
- <ButtonBase
- key={collection.id}
- onClick={() =>
- onToggleCollection(collection.id)
- }
- sx={(theme) => ({
- minHeight: 44,
- padding: "12px 20px",
- borderRadius: "16px",
- whiteSpace: "nowrap",
- flexShrink: 0,
- ...lockerColorSx(theme, {
- backgroundColor: isSelected
- ? "primary"
- : "fillLight",
- color: isSelected
- ? "specialWhite"
- : "textLight",
- }),
- })}
- >
- <Typography
- variant="small"
- sx={lockerTextBodySx}
- >
- {collection.name}
- </Typography>
- </ButtonBase>
- );
- })}
- </Stack>
- {showLeftScrollHint && (
- <Box
- sx={(theme) => ({
- position: "absolute",
- top: 0,
- left: 0,
- bottom: 0,
- width: 40,
- pointerEvents: "none",
- background: `linear-gradient(90deg, ${lockerColors.backgroundBase.dark} 0%, ${lockerColors.backgroundBase.dark}00 100%)`,
- ...theme.applyStyles("light", {
- background: `linear-gradient(90deg, ${lockerColors.backgroundBase.light} 0%, ${lockerColors.backgroundBase.light}00 100%)`,
- }),
- })}
- />
- )}
- {showRightScrollHint && (
- <Box
- sx={(theme) => ({
- position: "absolute",
- top: 0,
- right: 0,
- bottom: 0,
- width: 72,
- pointerEvents: "none",
- background: `linear-gradient(90deg, ${lockerColors.backgroundBase.dark}00 0%, ${lockerColors.backgroundBase.dark} 100%)`,
- ...theme.applyStyles("light", {
- background: `linear-gradient(90deg, ${lockerColors.backgroundBase.light}00 0%, ${lockerColors.backgroundBase.light} 100%)`,
- }),
- })}
- />
- )}
- </Box>
- {showRightScrollHint && (
- <Box
- sx={{
- width: 28,
- flexShrink: 0,
- display: "flex",
- alignItems: "center",
- justifyContent: "center",
- }}
- >
- <ButtonBase
- onClick={scrollRight}
- sx={(theme) => ({
- width: 28,
- height: "100%",
- borderRadius: "999px",
- ...lockerColorSx(theme, { color: "iconColor" }),
- })}
- >
- <ChevronRightRoundedIcon sx={{ fontSize: 28 }} />
- </ButtonBase>
- </Box>
- )}
- </Stack>
- </Box>
- );
-};
-
-const CollectionFilterChip: React.FC<{
- selected: boolean;
- onClick: (event: React.MouseEvent<HTMLElement>) => void;
-}> = ({ selected, onClick }) => (
- <Tooltip title={t("seeAllCollections")}>
- <ButtonBase
- onClick={onClick}
- sx={(theme) => ({
- width: 36,
- height: 36,
- borderRadius: "12px",
- flexShrink: 0,
- padding: 0,
- display: "flex",
- alignItems: "center",
- justifyContent: "center",
- ...lockerColorSx(theme, {
- backgroundColor: selected ? "primary" : "fillLight",
- color: selected ? "specialWhite" : "iconColor",
- }),
- "&:hover": {
- ...lockerColorSx(theme, {
- backgroundColor: selected ? "primary" : "fillDark",
- }),
- },
- })}
- >
- <FilterListRoundedIcon sx={{ fontSize: 18 }} />
- </ButtonBase>
- </Tooltip>
-);
-
const EmptyState: React.FC<{
title: string;
subtitle?: string;
@@ -2105,253 +1132,3 @@ const EmptyState: React.FC<{
)}
</Box>
);
-
-const CollectionCard: React.FC<{
- collection: LockerCollection;
- onClick: () => void;
- onShare?: () => void;
- onLeave?: () => void;
- onRename?: () => void;
- onDelete?: () => void;
-}> = ({ collection, onClick, onShare, onLeave, onRename, onDelete }) => {
- return (
- <ButtonBase
- component="div"
- onClick={onClick}
- sx={(theme) => ({
- width: "100%",
- display: "flex",
- alignItems: "center",
- justifyContent: "space-between",
- gap: 1.5,
- pl: 1.5,
- pr: 0,
- py: 1.5,
- borderRadius: "20px",
- border: "1.5px solid",
- transition: "background-color 0.15s, border-color 0.15s",
- ...lockerColorSx(theme, {
- backgroundColor: "fillLight",
- borderColor: "fillLight",
- }),
- "&:hover": {
- ...lockerColorSx(theme, { backgroundColor: "fillDark" }),
- },
- })}
- >
- <Stack
- direction="row"
- sx={{ flex: 1, minWidth: 0, alignItems: "center", gap: 1.25 }}
- >
- <Box
- sx={(theme) => ({
- position: "relative",
- display: "flex",
- alignItems: "center",
- justifyContent: "center",
- width: 40,
- height: 40,
- flexShrink: 0,
- borderRadius: "12px",
- ...lockerColorSx(theme, {
- backgroundColor: "backgroundBase",
- }),
- })}
- >
- {isImportantCollection(collection) ? (
- <Box
- sx={(theme) => ({
- display: "flex",
- ...lockerColorSx(theme, { color: "primary" }),
- })}
- >
- <HugeiconsIcon
- icon={StarIcon}
- size={24}
- strokeWidth={1.5}
- />
- </Box>
- ) : (
- <Box
- sx={(theme) => ({
- display: "flex",
- ...lockerColorSx(theme, { color: "textBase" }),
- })}
- >
- <HugeiconsIcon
- icon={Wallet05Icon}
- size={24}
- strokeWidth={1.5}
- />
- </Box>
- )}
- {collection.isShared && <SharedCollectionBadge />}
- </Box>
- <Box sx={{ flex: 1, minWidth: 0 }}>
- <Typography
- sx={(theme) => ({
- ...lockerTextBodySx,
- minWidth: 0,
- ...lockerColorSx(theme, { color: "textBase" }),
- })}
- noWrap
- >
- {collection.name}
- </Typography>
- <Typography
- sx={(theme) => ({
- ...lockerTextMiniSx,
- mt: "4px",
- ...lockerColorSx(theme, { color: "textLight" }),
- })}
- >
- {t("lockerItemsCount", {
- count: collection.items.length,
- })}
- </Typography>
- </Box>
- </Stack>
- <Box
- sx={{
- flexShrink: 0,
- mr: 1.5,
- width: 44,
- height: 24,
- display: "flex",
- alignItems: "center",
- justifyContent: "flex-end",
- }}
- onClick={(event) => event.stopPropagation()}
- >
- {(onShare || onLeave || onRename || onDelete) && (
- <CollectionContextMenu
- ariaID={`collection-context-menu-${collection.id}`}
- onShare={onShare}
- onLeave={onLeave}
- onRename={onRename}
- onDelete={onDelete}
- />
- )}
- </Box>
- </ButtonBase>
- );
-};
-
-const SharedCollectionBadge: React.FC = () => {
- return (
- <Box
- sx={(theme) => ({
- position: "absolute",
- right: -4,
- bottom: -4,
- width: 18,
- height: 18,
- borderRadius: "50%",
- display: "flex",
- alignItems: "center",
- justifyContent: "center",
- ...lockerColorSx(theme, {
- backgroundColor: "fillLight",
- color: "primary",
- }),
- })}
- >
- <HugeiconsIcon icon={Link01Icon} size={12} strokeWidth={2} />
- </Box>
- );
-};
-
-const CollectionContextMenu: React.FC<{
- ariaID: string;
- onShare?: () => void;
- onLeave?: () => void;
- onRename?: () => void;
- onDelete?: () => void;
-}> = ({ ariaID, onShare, onLeave, onRename, onDelete }) => (
- <LockerOverflowMenu
- ariaID={ariaID}
- triggerButtonSxProps={{ p: 0.25, color: "text.muted" }}
- >
- {onShare && (
- <LockerMenuOption
- startIcon={<ShareOutlinedIcon />}
- onClick={onShare}
- >
- {t(onLeave ? "sharedWith" : "share")}
- </LockerMenuOption>
- )}
- {onLeave && (
- <LockerMenuOption
- startIcon={<LogoutOutlinedIcon />}
- critical
- onClick={onLeave}
- >
- {t("leaveCollection")}
- </LockerMenuOption>
- )}
- {onRename && (
- <LockerMenuOption
- startIcon={<EditOutlinedIcon />}
- onClick={onRename}
- >
- {t("renameCollection")}
- </LockerMenuOption>
- )}
- {onDelete && (
- <LockerMenuOption
- startIcon={<DeleteOutlinedIcon />}
- critical
- onClick={onDelete}
- >
- {t("deleteCollection")}
- </LockerMenuOption>
- )}
- </LockerOverflowMenu>
-);
-
-const CollectionHeaderMenu: React.FC<{
- onShare?: () => void;
- onLeave?: () => void;
- onRename?: () => void;
- onDelete?: () => void;
-}> = ({ onShare, onLeave, onRename, onDelete }) => (
- <LockerOverflowMenu
- ariaID="collection-header-menu"
- triggerButtonSxProps={{ color: "text.muted" }}
- >
- {onShare && (
- <LockerMenuOption
- startIcon={<ShareOutlinedIcon />}
- onClick={onShare}
- >
- {t(onLeave ? "sharedWith" : "share")}
- </LockerMenuOption>
- )}
- {onLeave && (
- <LockerMenuOption
- startIcon={<LogoutOutlinedIcon />}
- critical
- onClick={onLeave}
- >
- {t("leaveCollection")}
- </LockerMenuOption>
- )}
- {onRename && (
- <LockerMenuOption
- startIcon={<EditOutlinedIcon />}
- onClick={onRename}
- >
- {t("renameCollection")}
- </LockerMenuOption>
- )}
- {onDelete && (
- <LockerMenuOption
- startIcon={<DeleteOutlinedIcon />}
- critical
- onClick={onDelete}
- >
- {t("deleteCollection")}
- </LockerMenuOption>
- )}
- </LockerOverflowMenu>
-);
diff --git a/web/apps/locker/src/components/items/ItemListDialogs.tsx b/web/apps/locker/src/components/items/ItemListDialogs.tsx
deleted file mode 100644
index 9e7373d844..0000000000
--- a/web/apps/locker/src/components/items/ItemListDialogs.tsx
+++ /dev/null
@@ -1,586 +0,0 @@
-import { FormField } from "@/components/ui/FormField";
-import { LockerMenuFooter, LockerMenuOption } from "@/components/ui/LockerMenu";
-import { lockerMenuPaperSx } from "@/styles/dialog";
-import {
- lockerHeaderIconButtonSx,
- lockerPrimaryButtonSx,
-} from "@/styles/fields";
-import {
- lockerColorSx,
- lockerTextBodyBoldSx,
- lockerTextBodySx,
- lockerTextH2Sx,
- lockerTextMiniSx,
-} from "@/styles/tokens";
-import type { LockerCollection } from "@/types";
-import { Cancel01Icon } from "@hugeicons/core-free-icons";
-import { HugeiconsIcon } from "@hugeicons/react";
-import CheckRoundedIcon from "@mui/icons-material/CheckRounded";
-import {
- Box,
- Chip,
- Dialog,
- IconButton,
- Menu,
- Snackbar,
- Stack,
- Typography,
-} from "@mui/material";
-import { LoadingButton } from "ente-base/components/mui/LoadingButton";
-import { t } from "i18next";
-import React, { useId } from "react";
-import {
- lockerSheetContainerSx,
- lockerSheetPaperSx,
-} from "../../styles/dialog";
-import { LockerConfirmDialog } from "../ui/LockerConfirmDialog";
-import { LockerFileLinkDialog } from "./LockerFileLinkDialog";
-
-interface ItemListDialogsProps {
- activeFileLinkItemTitle: string;
- activeFileLinkURL: string | null;
- canNativeShare: boolean;
- closeCollectionFilterMenu: () => void;
- closeFileLinkDialog: () => void;
- clearHomeCollectionSelection: () => void;
- createCollectionError: string | null;
- createCollectionName: string;
- createCollectionOpen: boolean;
- creatingCollection: boolean;
- deleteFileLink: () => void;
- dropdownHomeCollections: LockerCollection[];
- feedbackMessage: string | null;
- homeSelectedCollectionIDs: number[];
- isCreatingFileLink: boolean;
- isDeleteFileLinkConfirmOpen: boolean;
- isDeletingFileLink: boolean;
- onCloseFeedback: () => void;
- onCloseRenameDialog: () => void;
- onCloseRestoreDialog: () => void;
- onCloseCreateCollectionDialog: () => void;
- onConfirmCreateCollection: () => void;
- onConfirmRename: () => void | Promise<void>;
- onConfirmRestore: () => void | Promise<void>;
- onCopyFileLink: () => void;
- onRequestDeleteFileLink: () => void;
- onShareFileLink: () => void;
- onToggleHomeCollection: (collectionID: number) => void;
- renameError: string | null;
- renameCollectionOpen: boolean;
- renamingCollection: boolean;
- renameValue: string;
- restoreCollections: LockerCollection[];
- restoreError: string | null;
- restoreCollectionID: number | null;
- restoreDialogOpen: boolean;
- restoringItem: boolean;
- setCreateCollectionName: (value: string) => void;
- setDeleteFileLinkConfirmOpen: (open: boolean) => void;
- setRenameValue: (value: string) => void;
- setRestoreCollectionID: (collectionID: number) => void;
- collectionFilterAnchorEl: HTMLElement | null;
- fileLinkDialogOpen: boolean;
-}
-
-export const ItemListDialogs: React.FC<ItemListDialogsProps> = ({
- activeFileLinkItemTitle,
- activeFileLinkURL,
- canNativeShare,
- closeCollectionFilterMenu,
- closeFileLinkDialog,
- clearHomeCollectionSelection,
- createCollectionError,
- createCollectionName,
- createCollectionOpen,
- creatingCollection,
- deleteFileLink,
- dropdownHomeCollections,
- feedbackMessage,
- homeSelectedCollectionIDs,
- isCreatingFileLink,
- isDeleteFileLinkConfirmOpen,
- isDeletingFileLink,
- onCloseFeedback,
- onCloseRenameDialog,
- onCloseRestoreDialog,
- onCloseCreateCollectionDialog,
- onConfirmCreateCollection,
- onConfirmRename,
- onConfirmRestore,
- onCopyFileLink,
- onRequestDeleteFileLink,
- onShareFileLink,
- onToggleHomeCollection,
- renameError,
- renameCollectionOpen,
- renamingCollection,
- renameValue,
- restoreCollections,
- restoreError,
- restoreCollectionID,
- restoreDialogOpen,
- restoringItem,
- setCreateCollectionName,
- setDeleteFileLinkConfirmOpen,
- setRenameValue,
- setRestoreCollectionID,
- collectionFilterAnchorEl,
- fileLinkDialogOpen,
-}) => {
- const restoreTitleID = useId();
- return (
- <>
- <LockerFileLinkDialog
- open={fileLinkDialogOpen}
- itemTitle={activeFileLinkItemTitle}
- url={activeFileLinkURL ?? undefined}
- loading={isCreatingFileLink}
- deleting={isDeletingFileLink}
- showShareAction={canNativeShare}
- onClose={closeFileLinkDialog}
- onCopy={onCopyFileLink}
- onShare={onShareFileLink}
- onDelete={onRequestDeleteFileLink}
- />
-
- <LockerConfirmDialog
- open={isDeleteFileLinkConfirmOpen}
- illustration="/images/file_delete_icon.png"
- title={t("deleteShareLinkDialogTitle")}
- body={t("deleteShareLinkConfirmation")}
- confirmLabel={t("delete")}
- loading={isDeletingFileLink}
- onClose={() => {
- if (!isDeletingFileLink) {
- setDeleteFileLinkConfirmOpen(false);
- }
- }}
- onConfirm={deleteFileLink}
- />
-
- <Dialog
- slotProps={{
- paper: { sx: lockerSheetPaperSx },
- container: { sx: lockerSheetContainerSx },
- }}
- open={restoreDialogOpen}
- aria-labelledby={restoreTitleID}
- onClose={() => {
- if (!restoringItem) {
- onCloseRestoreDialog();
- }
- }}
- fullWidth
- maxWidth="xs"
- >
- <Stack>
- <Stack
- direction="row"
- sx={{ alignItems: "center", gap: 1.5, minHeight: 38 }}
- >
- <Typography
- id={restoreTitleID}
- noWrap
- sx={{ ...lockerTextH2Sx, flex: 1, minWidth: 0 }}
- >
- {t("restoreToCollection")}
- </Typography>
- <IconButton
- aria-label={t("cancel")}
- disabled={restoringItem}
- onClick={() => {
- if (!restoringItem) {
- onCloseRestoreDialog();
- }
- }}
- sx={(theme) => ({
- width: 36,
- height: 36,
- borderRadius: "50%",
- p: 0,
- flexShrink: 0,
- ...lockerColorSx(theme, {
- backgroundColor: "fillLight",
- color: "iconColor",
- }),
- "&:hover": {
- ...lockerColorSx(theme, {
- backgroundColor: "fillDark",
- }),
- },
- })}
- >
- <HugeiconsIcon
- icon={Cancel01Icon}
- size={18}
- strokeWidth={1.5}
- />
- </IconButton>
- </Stack>
- <Typography
- sx={(theme) => ({
- ...lockerTextMiniSx,
- mt: 2.5,
- mb: 1,
- ...lockerColorSx(theme, { color: "textLight" }),
- })}
- >
- {t("collections")}
- </Typography>
- <Box sx={{ display: "flex", flexWrap: "wrap", gap: 1 }}>
- {restoreCollections.length > 0 ? (
- restoreCollections.map((collection) => (
- <Chip
- key={collection.id}
- label={collection.name}
- icon={
- restoreCollectionID ===
- collection.id ? (
- <CheckRoundedIcon
- sx={{ fontSize: 14 }}
- />
- ) : undefined
- }
- disabled={restoringItem}
- onClick={() =>
- setRestoreCollectionID(collection.id)
- }
- sx={(theme) => ({
- height: 36,
- borderRadius: "9999px",
- px: "14px",
- border: "1px solid",
- ...lockerColorSx(theme, {
- backgroundColor:
- restoreCollectionID ===
- collection.id
- ? "primaryLight"
- : "fillLight",
- color:
- restoreCollectionID ===
- collection.id
- ? "primary"
- : "textBase",
- ...(restoreCollectionID ===
- collection.id
- ? {
- borderColor:
- "primaryStroke" as const,
- }
- : {}),
- }),
- ...(restoreCollectionID ===
- collection.id
- ? {}
- : { borderColor: "transparent" }),
- "& .MuiChip-label": {
- ...lockerTextBodySx,
- px: 0,
- },
- "& .MuiChip-icon": {
- ml: 0,
- mr: 0.75,
- ...lockerColorSx(theme, {
- color: "primary",
- }),
- },
- })}
- />
- ))
- ) : (
- <Typography
- sx={(theme) => ({
- ...lockerTextBodySx,
- ...lockerColorSx(theme, {
- color: "textLight",
- }),
- })}
- >
- {t("noCollectionsAvailableForSelection")}
- </Typography>
- )}
- </Box>
- {restoreError && (
- <Typography
- sx={(theme) => ({
- ...lockerTextMiniSx,
- mt: 1.5,
- ...lockerColorSx(theme, { color: "warning" }),
- })}
- >
- {restoreError}
- </Typography>
- )}
- <LoadingButton
- fullWidth
- variant="contained"
- loading={restoringItem}
- disabled={restoreCollectionID === null}
- onClick={onConfirmRestore}
- sx={(theme) => ({
- ...lockerTextBodyBoldSx,
- mt: 3,
- minHeight: 52,
- borderRadius: "20px",
- textTransform: "none",
- ...lockerColorSx(theme, {
- backgroundColor: "primary",
- color: "specialWhite",
- }),
- "&:hover": {
- ...lockerColorSx(theme, {
- backgroundColor: "primaryDark",
- }),
- },
- "&.Mui-disabled": {
- ...lockerColorSx(theme, {
- backgroundColor: "fillDarkest",
- color: "textLighter",
- }),
- },
- })}
- >
- {t("restore")}
- </LoadingButton>
- </Stack>
- </Dialog>
-
- <Dialog
- slotProps={{
- paper: { sx: lockerSheetPaperSx },
- container: { sx: lockerSheetContainerSx },
- }}
- open={renameCollectionOpen}
- onClose={() => {
- if (!renamingCollection) {
- onCloseRenameDialog();
- }
- }}
- fullWidth
- maxWidth="xs"
- >
- <Stack>
- <Stack
- direction="row"
- sx={{ alignItems: "center", gap: 1.5, minHeight: 38 }}
- >
- <Typography
- sx={{ ...lockerTextH2Sx, flex: 1, minWidth: 0 }}
- >
- {t("renameCollection")}
- </Typography>
- <IconButton
- aria-label={t("close")}
- onClick={onCloseRenameDialog}
- disabled={renamingCollection}
- sx={lockerHeaderIconButtonSx}
- >
- <HugeiconsIcon
- icon={Cancel01Icon}
- size={18}
- strokeWidth={1.5}
- />
- </IconButton>
- </Stack>
- <Box sx={{ mt: 2.5 }}>
- <FormField
- value={renameValue}
- onChange={(event) =>
- setRenameValue(event.target.value)
- }
- label={t("enterCollectionName")}
- required
- autoFocus
- disabled={renamingCollection}
- onKeyDown={(event) => {
- if (event.key === "Enter") {
- void onConfirmRename();
- }
- }}
- />
- </Box>
- {renameError && (
- <Typography
- sx={(theme) => ({
- ...lockerTextMiniSx,
- mt: 1.5,
- ...lockerColorSx(theme, { color: "warning" }),
- })}
- >
- {renameError}
- </Typography>
- )}
- <LoadingButton
- fullWidth
- color="primary"
- loading={renamingCollection}
- disabled={!renameValue.trim()}
- onClick={onConfirmRename}
- sx={(theme) => ({
- ...lockerTextBodyBoldSx,
- mt: 3,
- borderRadius: "20px",
- textTransform: "none",
- ...lockerColorSx(theme, {
- backgroundColor: "primary",
- color: "specialWhite",
- }),
- "&:hover": {
- ...lockerColorSx(theme, {
- backgroundColor: "primaryDark",
- }),
- },
- ...lockerPrimaryButtonSx(theme, {
- loading: renamingCollection,
- }),
- })}
- >
- {t("save")}
- </LoadingButton>
- </Stack>
- </Dialog>
-
- <Dialog
- slotProps={{
- paper: { sx: lockerSheetPaperSx },
- container: { sx: lockerSheetContainerSx },
- }}
- open={createCollectionOpen}
- onClose={() => {
- if (!creatingCollection) {
- onCloseCreateCollectionDialog();
- }
- }}
- fullWidth
- maxWidth="xs"
- >
- <Stack>
- <Stack
- direction="row"
- sx={{ alignItems: "center", gap: 1.5, minHeight: 38 }}
- >
- <Typography
- sx={{ ...lockerTextH2Sx, flex: 1, minWidth: 0 }}
- >
- {t("createCollection")}
- </Typography>
- <IconButton
- aria-label={t("close")}
- onClick={onCloseCreateCollectionDialog}
- disabled={creatingCollection}
- sx={lockerHeaderIconButtonSx}
- >
- <HugeiconsIcon
- icon={Cancel01Icon}
- size={18}
- strokeWidth={1.5}
- />
- </IconButton>
- </Stack>
- <Box sx={{ mt: 2.5 }}>
- <FormField
- value={createCollectionName}
- onChange={(event) =>
- setCreateCollectionName(event.target.value)
- }
- label={t("enterCollectionName")}
- required
- autoFocus
- disabled={creatingCollection}
- onKeyDown={(event) => {
- if (event.key === "Enter") {
- onConfirmCreateCollection();
- }
- }}
- />
- </Box>
- {createCollectionError && (
- <Typography
- sx={(theme) => ({
- ...lockerTextMiniSx,
- mt: 1.5,
- ...lockerColorSx(theme, { color: "warning" }),
- })}
- >
- {createCollectionError}
- </Typography>
- )}
- <LoadingButton
- fullWidth
- color="primary"
- loading={creatingCollection}
- disabled={!createCollectionName.trim()}
- onClick={onConfirmCreateCollection}
- sx={(theme) => ({
- ...lockerTextBodyBoldSx,
- mt: 3,
- borderRadius: "20px",
- textTransform: "none",
- ...lockerColorSx(theme, {
- backgroundColor: "primary",
- color: "specialWhite",
- }),
- "&:hover": {
- ...lockerColorSx(theme, {
- backgroundColor: "primaryDark",
- }),
- },
- ...lockerPrimaryButtonSx(theme, {
- loading: creatingCollection,
- }),
- })}
- >
- {t("createCollectionButton")}
- </LoadingButton>
- </Stack>
- </Dialog>
-
- <Menu
- anchorEl={collectionFilterAnchorEl}
- open={!!collectionFilterAnchorEl}
- onClose={closeCollectionFilterMenu}
- slotProps={{
- paper: { sx: [lockerMenuPaperSx, { mt: 1 }] },
- list: { disablePadding: true },
- }}
- >
- {dropdownHomeCollections.map((collection) => {
- const isSelected = homeSelectedCollectionIDs.includes(
- collection.id,
- );
- return (
- <LockerMenuOption
- key={collection.id}
- onClick={() =>
- onToggleHomeCollection(collection.id)
- }
- selected={isSelected}
- secondary={new Intl.NumberFormat().format(
- collection.items.length,
- )}
- >
- {collection.name}
- </LockerMenuOption>
- );
- })}
- {homeSelectedCollectionIDs.length > 0 && (
- <LockerMenuFooter
- onClick={() => {
- clearHomeCollectionSelection();
- closeCollectionFilterMenu();
- }}
- >
- {t("clearSelection")}
- </LockerMenuFooter>
- )}
- </Menu>
-
- <Snackbar
- open={feedbackMessage !== null}
- message={feedbackMessage}
- autoHideDuration={2500}
- onClose={onCloseFeedback}
- />
- </>
- );
-};
diff --git a/web/apps/locker/src/components/items/ItemsSection.tsx b/web/apps/locker/src/components/items/ItemsSection.tsx
new file mode 100644
index 0000000000..f01981fcc8
--- /dev/null
+++ b/web/apps/locker/src/components/items/ItemsSection.tsx
@@ -0,0 +1,100 @@
+import { ItemCard } from "@/components/items/ItemCard";
+import { lockerContentMaxWidth } from "@/styles/tokens";
+import type { LockerItem } from "@/types";
+import { canShareLockerFileLink, isLockerItemOwner } from "@/types";
+import { Box, Stack } from "@mui/material";
+import { t } from "i18next";
+import React from "react";
+
+export const ItemsSection: React.FC<{
+ items: LockerItem[];
+ isTrashView: boolean;
+ onEditItem?: (item: LockerItem) => void;
+ onDeleteItem?: (item: LockerItem) => void;
+ onPermanentlyDelete?: (items: LockerItem[]) => void;
+ onRequestRestore: (item: LockerItem) => void;
+ onSelectItem: (item: LockerItem) => void;
+ currentUserID?: number;
+ onShareLink?: (item: LockerItem) => void;
+ selectionMode?: boolean;
+ selectedItemIDSet?: Set<number>;
+ onToggleItemSelection?: (item: LockerItem) => void;
+ onStartSelection?: (item: LockerItem) => void;
+ emptyState: React.ReactNode;
+}> = ({
+ items,
+ isTrashView,
+ onEditItem,
+ onDeleteItem,
+ onPermanentlyDelete,
+ onRequestRestore,
+ onSelectItem,
+ currentUserID,
+ onShareLink,
+ selectionMode,
+ selectedItemIDSet,
+ onToggleItemSelection,
+ onStartSelection,
+ emptyState,
+}) =>
+ items.length > 0 ? (
+ <Stack
+ sx={{ maxWidth: lockerContentMaxWidth, mx: "auto", gap: 1, mt: 0 }}
+ >
+ {items.map((item) => {
+ const isOwnedByCurrentUser = isLockerItemOwner(
+ item,
+ currentUserID,
+ );
+ return (
+ <ItemCard
+ key={item.id}
+ item={item}
+ isTrashView={isTrashView}
+ isIncomingShared={!isOwnedByCurrentUser}
+ onClick={() => onSelectItem(item)}
+ onEdit={
+ onEditItem && isOwnedByCurrentUser
+ ? onEditItem
+ : undefined
+ }
+ onDelete={
+ onDeleteItem && isOwnedByCurrentUser
+ ? onDeleteItem
+ : undefined
+ }
+ deleteDisabledHint={
+ onDeleteItem &&
+ !isTrashView &&
+ !isOwnedByCurrentUser
+ ? t("actionNotSupportedForSharedFiles", {
+ count: 1,
+ })
+ : undefined
+ }
+ onPermanentlyDelete={onPermanentlyDelete}
+ onRestore={
+ isTrashView
+ ? (trashItem) => onRequestRestore(trashItem)
+ : undefined
+ }
+ onShareLink={
+ onShareLink &&
+ canShareLockerFileLink(item, currentUserID)
+ ? onShareLink
+ : undefined
+ }
+ selectionMode={selectionMode}
+ selectable
+ selected={selectedItemIDSet?.has(item.id)}
+ onToggleSelection={onToggleItemSelection}
+ onLongPressSelect={onStartSelection}
+ />
+ );
+ })}
+ </Stack>
+ ) : (
+ <Box sx={{ maxWidth: lockerContentMaxWidth, mx: "auto" }}>
+ {emptyState}
+ </Box>
+ );
diff --git a/web/apps/locker/src/components/items/RestoreItemDialog.tsx b/web/apps/locker/src/components/items/RestoreItemDialog.tsx
new file mode 100644
index 0000000000..38f15f3d3b
--- /dev/null
+++ b/web/apps/locker/src/components/items/RestoreItemDialog.tsx
@@ -0,0 +1,301 @@
+import { lockerSheetContainerSx, lockerSheetPaperSx } from "@/styles/dialog";
+import {
+ lockerColorSx,
+ lockerTextBodyBoldSx,
+ lockerTextBodySx,
+ lockerTextH2Sx,
+ lockerTextMiniSx,
+} from "@/styles/tokens";
+import type { LockerCollection, LockerItem } from "@/types";
+import { Cancel01Icon } from "@hugeicons/core-free-icons";
+import { HugeiconsIcon } from "@hugeicons/react";
+import CheckRoundedIcon from "@mui/icons-material/CheckRounded";
+import {
+ Box,
+ Chip,
+ Dialog,
+ IconButton,
+ Stack,
+ Typography,
+} from "@mui/material";
+import { LoadingButton } from "ente-base/components/mui/LoadingButton";
+import log from "ente-base/log";
+import { t } from "i18next";
+import { useCallback, useEffect, useId, useState } from "react";
+
+interface RestoreItemDialogProps {
+ restoreItem: LockerItem | null;
+ restoreCollections: LockerCollection[];
+ onClose: () => void;
+ onRestoreItem?: (
+ item: LockerItem,
+ collectionID: number,
+ ) => void | Promise<void>;
+}
+export function RestoreItemDialog({
+ restoreItem,
+ restoreCollections,
+ onClose,
+ onRestoreItem,
+}: RestoreItemDialogProps) {
+ const restoreTitleID = useId();
+ const restoreDialogOpen = restoreItem !== null;
+ const [restoreCollectionID, setRestoreCollectionID] = useState<
+ number | null
+ >(null);
+ const [restoreError, setRestoreError] = useState<string | null>(null);
+ const [restoringItem, setRestoringItem] = useState(false);
+ const restoreItemID = restoreItem?.id ?? null;
+ const [previousItemID, setPreviousItemID] = useState(restoreItemID);
+ if (previousItemID !== restoreItemID) {
+ setPreviousItemID(restoreItemID);
+ setRestoreCollectionID(null);
+ }
+
+ useEffect(() => {
+ if (
+ restoreCollectionID !== null &&
+ !restoreCollections.some(
+ (collection) => collection.id === restoreCollectionID,
+ )
+ ) {
+ setRestoreCollectionID(null);
+ }
+ }, [restoreCollectionID, restoreCollections]);
+
+ useEffect(() => {
+ if (restoreItem === null) {
+ setRestoreError(null);
+ setRestoringItem(false);
+ }
+ }, [restoreItem]);
+
+ const handleRestoreConfirm = useCallback(async () => {
+ if (
+ !restoreItem ||
+ restoreCollectionID === null ||
+ !onRestoreItem ||
+ restoringItem
+ ) {
+ return;
+ }
+
+ setRestoringItem(true);
+ setRestoreError(null);
+ try {
+ await Promise.resolve(
+ onRestoreItem(restoreItem, restoreCollectionID),
+ );
+ onClose();
+ setRestoreCollectionID(null);
+ } catch (error) {
+ log.error("Failed to restore Locker item", error);
+ setRestoreError(
+ error instanceof Error ? error.message : t("generic_error"),
+ );
+ } finally {
+ setRestoringItem(false);
+ }
+ }, [
+ onRestoreItem,
+ restoreCollectionID,
+ restoreItem,
+ restoringItem,
+ onClose,
+ ]);
+
+ const onCloseRestoreDialog = () => {
+ if (restoringItem) return;
+ onClose();
+ setRestoreCollectionID(null);
+ setRestoreError(null);
+ };
+ const handleSelectCollection = (id: number) => {
+ setRestoreCollectionID(id);
+ setRestoreError(null);
+ };
+ return (
+ <Dialog
+ slotProps={{
+ paper: { sx: lockerSheetPaperSx },
+ container: { sx: lockerSheetContainerSx },
+ }}
+ open={restoreDialogOpen}
+ aria-labelledby={restoreTitleID}
+ onClose={() => {
+ if (!restoringItem) {
+ onCloseRestoreDialog();
+ }
+ }}
+ fullWidth
+ maxWidth="xs"
+ >
+ <Stack>
+ <Stack
+ direction="row"
+ sx={{ alignItems: "center", gap: 1.5, minHeight: 38 }}
+ >
+ <Typography
+ id={restoreTitleID}
+ noWrap
+ sx={{ ...lockerTextH2Sx, flex: 1, minWidth: 0 }}
+ >
+ {t("restoreToCollection")}
+ </Typography>
+ <IconButton
+ aria-label={t("cancel")}
+ disabled={restoringItem}
+ onClick={() => {
+ if (!restoringItem) {
+ onCloseRestoreDialog();
+ }
+ }}
+ sx={(theme) => ({
+ width: 36,
+ height: 36,
+ borderRadius: "50%",
+ p: 0,
+ flexShrink: 0,
+ ...lockerColorSx(theme, {
+ backgroundColor: "fillLight",
+ color: "iconColor",
+ }),
+ "&:hover": {
+ ...lockerColorSx(theme, {
+ backgroundColor: "fillDark",
+ }),
+ },
+ })}
+ >
+ <HugeiconsIcon
+ icon={Cancel01Icon}
+ size={18}
+ strokeWidth={1.5}
+ />
+ </IconButton>
+ </Stack>
+ <Typography
+ sx={(theme) => ({
+ ...lockerTextMiniSx,
+ mt: 2.5,
+ mb: 1,
+ ...lockerColorSx(theme, { color: "textLight" }),
+ })}
+ >
+ {t("collections")}
+ </Typography>
+ <Box sx={{ display: "flex", flexWrap: "wrap", gap: 1 }}>
+ {restoreCollections.length > 0 ? (
+ restoreCollections.map((collection) => (
+ <Chip
+ key={collection.id}
+ label={collection.name}
+ icon={
+ restoreCollectionID === collection.id ? (
+ <CheckRoundedIcon
+ sx={{ fontSize: 14 }}
+ />
+ ) : undefined
+ }
+ disabled={restoringItem}
+ onClick={() =>
+ handleSelectCollection(collection.id)
+ }
+ sx={(theme) => ({
+ height: 36,
+ borderRadius: "9999px",
+ px: "14px",
+ border: "1px solid",
+ ...lockerColorSx(theme, {
+ backgroundColor:
+ restoreCollectionID ===
+ collection.id
+ ? "primaryLight"
+ : "fillLight",
+ color:
+ restoreCollectionID ===
+ collection.id
+ ? "primary"
+ : "textBase",
+ ...(restoreCollectionID ===
+ collection.id
+ ? {
+ borderColor:
+ "primaryStroke" as const,
+ }
+ : {}),
+ }),
+ ...(restoreCollectionID === collection.id
+ ? {}
+ : { borderColor: "transparent" }),
+ "& .MuiChip-label": {
+ ...lockerTextBodySx,
+ px: 0,
+ },
+ "& .MuiChip-icon": {
+ ml: 0,
+ mr: 0.75,
+ ...lockerColorSx(theme, {
+ color: "primary",
+ }),
+ },
+ })}
+ />
+ ))
+ ) : (
+ <Typography
+ sx={(theme) => ({
+ ...lockerTextBodySx,
+ ...lockerColorSx(theme, { color: "textLight" }),
+ })}
+ >
+ {t("noCollectionsAvailableForSelection")}
+ </Typography>
+ )}
+ </Box>
+ {restoreError && (
+ <Typography
+ sx={(theme) => ({
+ ...lockerTextMiniSx,
+ mt: 1.5,
+ ...lockerColorSx(theme, { color: "warning" }),
+ })}
+ >
+ {restoreError}
+ </Typography>
+ )}
+ <LoadingButton
+ fullWidth
+ variant="contained"
+ loading={restoringItem}
+ disabled={restoreCollectionID === null}
+ onClick={handleRestoreConfirm}
+ sx={(theme) => ({
+ ...lockerTextBodyBoldSx,
+ mt: 3,
+ minHeight: 52,
+ borderRadius: "20px",
+ textTransform: "none",
+ ...lockerColorSx(theme, {
+ backgroundColor: "primary",
+ color: "specialWhite",
+ }),
+ "&:hover": {
+ ...lockerColorSx(theme, {
+ backgroundColor: "primaryDark",
+ }),
+ },
+ "&.Mui-disabled": {
+ ...lockerColorSx(theme, {
+ backgroundColor: "fillDarkest",
+ color: "textLighter",
+ }),
+ },
+ })}
+ >
+ {t("restore")}
+ </LoadingButton>
+ </Stack>
+ </Dialog>
+ );
+}
diff --git a/web/apps/locker/src/components/items/SelectionActionBar.tsx b/web/apps/locker/src/components/items/SelectionActionBar.tsx
new file mode 100644
index 0000000000..fdacc2b5c3
--- /dev/null
+++ b/web/apps/locker/src/components/items/SelectionActionBar.tsx
@@ -0,0 +1,179 @@
+import { lockerColorSx } from "@/styles/tokens";
+import CheckCircleRoundedIcon from "@mui/icons-material/CheckCircleRounded";
+import ClearRoundedIcon from "@mui/icons-material/ClearRounded";
+import DeleteOutlinedIcon from "@mui/icons-material/DeleteOutlined";
+import FileDownloadOutlinedIcon from "@mui/icons-material/FileDownloadOutlined";
+import { Box, Button, IconButton, Stack, Typography } from "@mui/material";
+import { t } from "i18next";
+import React from "react";
+
+export const SelectionActionBar: React.FC<{
+ selectedCount: number;
+ allSelected: boolean;
+ bulkDownloading: boolean;
+ bulkDownloadProgress: { completed: number; total: number } | null;
+ canDownload: boolean;
+ canDelete: boolean;
+ onToggleSelectAll: () => void;
+ onDownload: () => void;
+ onDelete: () => void;
+ onDone: () => void;
+}> = ({
+ selectedCount,
+ allSelected,
+ bulkDownloading,
+ bulkDownloadProgress,
+ canDownload,
+ canDelete,
+ onToggleSelectAll,
+ onDownload,
+ onDelete,
+ onDone,
+}) => (
+ <Box sx={{ px: { xs: 2, sm: 3 }, py: { xs: 1.25, sm: 1.5 } }}>
+ <Box
+ sx={(theme) => ({
+ maxWidth: 760,
+ mx: "auto",
+ borderRadius: "20px",
+ border: `1px solid ${theme.vars.palette.stroke.faint}`,
+ backgroundColor: theme.vars.palette.background.paper,
+ boxShadow: "0 12px 30px rgba(15, 23, 42, 0.12)",
+ backdropFilter: "blur(18px)",
+ px: { xs: 1.25, sm: 1.5 },
+ py: 1.25,
+ })}
+ >
+ <Stack
+ direction={{ xs: "column", sm: "row" }}
+ sx={{
+ alignItems: { xs: "stretch", sm: "center" },
+ justifyContent: "space-between",
+ gap: 1,
+ }}
+ >
+ <Stack
+ direction="row"
+ sx={{
+ alignItems: "center",
+ justifyContent: "space-between",
+ gap: 1,
+ }}
+ >
+ <Box
+ sx={{
+ display: "flex",
+ alignItems: "center",
+ gap: 1,
+ minWidth: 0,
+ px: 1.25,
+ py: 0.875,
+ borderRadius: "14px",
+ backgroundColor: "rgba(16, 113, 255, 0.10)",
+ border: "1px solid rgba(16, 113, 255, 0.16)",
+ }}
+ >
+ <CheckCircleRoundedIcon
+ sx={(theme) => ({
+ fontSize: 18,
+ ...lockerColorSx(theme, { color: "primary" }),
+ flexShrink: 0,
+ })}
+ />
+ <Typography
+ variant="body"
+ sx={{ fontWeight: 600, minWidth: 0 }}
+ noWrap
+ >
+ {t("filesSelected", { count: selectedCount })}
+ </Typography>
+ </Box>
+ <IconButton
+ onClick={onDone}
+ disabled={bulkDownloading}
+ sx={(theme) => ({
+ color: "text.muted",
+ width: 38,
+ height: 38,
+ flexShrink: 0,
+ border: `1px solid ${theme.vars.palette.stroke.faint}`,
+ backgroundColor: theme.vars.palette.fill.faint,
+ "&:hover": {
+ backgroundColor:
+ theme.vars.palette.fill.faintHover,
+ },
+ })}
+ >
+ <ClearRoundedIcon sx={{ fontSize: 18 }} />
+ </IconButton>
+ </Stack>
+ <Stack
+ direction={{ xs: "column", sm: "row" }}
+ sx={{ alignItems: { xs: "stretch", sm: "center" }, gap: 1 }}
+ >
+ <Button
+ color="secondary"
+ onClick={onToggleSelectAll}
+ disabled={bulkDownloading}
+ sx={(theme) => ({
+ minHeight: 42,
+ px: 1.5,
+ borderRadius: "14px",
+ border: `1px solid ${theme.vars.palette.stroke.faint}`,
+ backgroundColor: theme.vars.palette.fill.faint,
+ "&:hover": {
+ backgroundColor:
+ theme.vars.palette.fill.faintHover,
+ },
+ })}
+ >
+ {allSelected ? t("deselectAll") : t("selectAll")}
+ </Button>
+ <Button
+ variant="contained"
+ startIcon={<FileDownloadOutlinedIcon />}
+ onClick={onDownload}
+ disabled={bulkDownloading || !canDownload}
+ sx={{
+ minHeight: 42,
+ px: 1.75,
+ borderRadius: "14px",
+ boxShadow: "none",
+ color: "#FFFFFF",
+ background:
+ "linear-gradient(180deg, #1674FF 0%, #0B5FE0 100%)",
+ "& .MuiButton-startIcon": { color: "#FFFFFF" },
+ "&:hover": {
+ boxShadow: "none",
+ background:
+ "linear-gradient(180deg, #2A82FF 0%, #1269F0 100%)",
+ },
+ }}
+ >
+ {bulkDownloading && bulkDownloadProgress
+ ? `${t("downloading")} ${bulkDownloadProgress.completed}/${bulkDownloadProgress.total}`
+ : t("download")}
+ </Button>
+ <Button
+ color="critical"
+ startIcon={<DeleteOutlinedIcon />}
+ onClick={onDelete}
+ disabled={bulkDownloading || !canDelete}
+ sx={{
+ minHeight: 42,
+ px: 1.75,
+ borderRadius: "14px",
+ color: "#FFFFFF",
+ border: "1px solid rgba(185, 28, 28, 0.26)",
+ backgroundColor: "#D14343",
+ "& .MuiButton-startIcon": { color: "#FFFFFF" },
+ "&:hover": { backgroundColor: "#B93838" },
+ }}
+ >
+ {t("delete")}
+ </Button>
+ </Stack>
+ </Stack>
+ </Box>
+ </Box>
+);
diff --git a/web/apps/locker/src/components/items/use-file-link.ts b/web/apps/locker/src/components/items/use-file-link.ts
new file mode 100644
index 0000000000..d8e2289b41
--- /dev/null
+++ b/web/apps/locker/src/components/items/use-file-link.ts
@@ -0,0 +1,173 @@
+import {
+ deleteLockerFileShareLink,
+ getOrCreateLockerFileShareLink,
+} from "@/services/remote";
+import type { LockerItem } from "@/types";
+import { canShareLockerFileLink, getItemTitle } from "@/types";
+import { isHTTPErrorWithStatus } from "ente-base/http";
+import log from "ente-base/log";
+import { t } from "i18next";
+import { useCallback, useEffect, useMemo, useState } from "react";
+
+interface FileLinkOptions {
+ allItemsByID: Map<number, LockerItem>;
+ currentUserID: number | undefined;
+ setFeedbackMessage: (message: string | null) => void;
+}
+export function useFileLink({
+ allItemsByID,
+ currentUserID,
+ setFeedbackMessage,
+}: FileLinkOptions) {
+ const [activeFileLinkItemID, setActiveFileLinkItemID] = useState<
+ number | null
+ >(null);
+ const [activeFileLink, setActiveFileLink] = useState<{
+ linkID: string;
+ url: string;
+ } | null>(null);
+ const [isCreatingFileLink, setIsCreatingFileLink] = useState(false);
+ const [isDeletingFileLink, setIsDeletingFileLink] = useState(false);
+ const [isDeleteFileLinkConfirmOpen, setIsDeleteFileLinkConfirmOpen] =
+ useState(false);
+ const activeFileLinkItem = useMemo(
+ () =>
+ activeFileLinkItemID === null
+ ? null
+ : (allItemsByID.get(activeFileLinkItemID) ?? null),
+ [activeFileLinkItemID, allItemsByID],
+ );
+ const canNativeShare =
+ typeof navigator !== "undefined" &&
+ typeof navigator.share === "function";
+
+ useEffect(() => {
+ if (activeFileLinkItemID !== null && !activeFileLinkItem) {
+ setActiveFileLinkItemID(null);
+ setActiveFileLink(null);
+ setIsCreatingFileLink(false);
+ setIsDeletingFileLink(false);
+ setIsDeleteFileLinkConfirmOpen(false);
+ }
+ }, [activeFileLinkItem, activeFileLinkItemID]);
+
+ const closeFileLinkDialog = useCallback(() => {
+ if (
+ isCreatingFileLink ||
+ isDeletingFileLink ||
+ isDeleteFileLinkConfirmOpen
+ ) {
+ return;
+ }
+ setActiveFileLinkItemID(null);
+ setActiveFileLink(null);
+ }, [isCreatingFileLink, isDeleteFileLinkConfirmOpen, isDeletingFileLink]);
+ const openFileLinkDialog = useCallback(
+ async (item: LockerItem) => {
+ if (!canShareLockerFileLink(item, currentUserID)) {
+ setFeedbackMessage(t("shareNotSupportedForSharedFiles"));
+ return;
+ }
+
+ setActiveFileLinkItemID(item.id);
+ setActiveFileLink(null);
+ setIsCreatingFileLink(true);
+ try {
+ const link = await getOrCreateLockerFileShareLink(item.id);
+ setActiveFileLink(link);
+ } catch (error) {
+ log.error(
+ `Failed to create share link for file ${item.id}`,
+ error,
+ );
+ setFeedbackMessage(
+ isHTTPErrorWithStatus(error, 402)
+ ? t("sharingRequiresPaidPlan")
+ : t("failedToCreateShareLink"),
+ );
+ setActiveFileLinkItemID(null);
+ } finally {
+ setIsCreatingFileLink(false);
+ }
+ },
+ [currentUserID, setFeedbackMessage],
+ );
+ const copyActiveFileLink = useCallback(async () => {
+ if (!activeFileLink?.url) {
+ return;
+ }
+ await navigator.clipboard.writeText(activeFileLink.url);
+ setFeedbackMessage(t("linkCopiedToClipboard"));
+ }, [activeFileLink?.url, setFeedbackMessage]);
+ const shareActiveFileLink = useCallback(async () => {
+ if (!activeFileLink?.url) {
+ return;
+ }
+
+ if (canNativeShare) {
+ try {
+ await navigator.share({
+ title: activeFileLinkItem
+ ? getItemTitle(activeFileLinkItem)
+ : undefined,
+ url: activeFileLink.url,
+ });
+ return;
+ } catch (error) {
+ if (
+ error instanceof DOMException &&
+ error.name === "AbortError"
+ ) {
+ return;
+ }
+ }
+ }
+
+ await navigator.clipboard.writeText(activeFileLink.url);
+ setFeedbackMessage(t("linkCopiedToClipboard"));
+ }, [
+ activeFileLink?.url,
+ activeFileLinkItem,
+ canNativeShare,
+ setFeedbackMessage,
+ ]);
+ const deleteActiveFileLink = useCallback(async () => {
+ if (!activeFileLinkItem) {
+ return;
+ }
+
+ setIsDeletingFileLink(true);
+ try {
+ await deleteLockerFileShareLink(
+ activeFileLinkItem.id,
+ activeFileLink?.linkID,
+ );
+ setFeedbackMessage(t("shareLinkDeletedSuccessfully"));
+ setActiveFileLinkItemID(null);
+ setActiveFileLink(null);
+ } catch (error) {
+ log.error(
+ `Failed to delete share link for file ${activeFileLinkItem.id}`,
+ error,
+ );
+ setFeedbackMessage(t("failedToDeleteShareLink"));
+ } finally {
+ setIsDeletingFileLink(false);
+ setIsDeleteFileLinkConfirmOpen(false);
+ }
+ }, [activeFileLink?.linkID, activeFileLinkItem, setFeedbackMessage]);
+ return {
+ activeFileLinkItem,
+ activeFileLink,
+ canNativeShare,
+ isCreatingFileLink,
+ isDeletingFileLink,
+ isDeleteFileLinkConfirmOpen,
+ setIsDeleteFileLinkConfirmOpen,
+ closeFileLinkDialog,
+ openFileLinkDialog,
+ copyActiveFileLink,
+ shareActiveFileLink,
+ deleteActiveFileLink,
+ };
+}
diff --git a/web/apps/locker/src/components/items/use-item-selection.ts b/web/apps/locker/src/components/items/use-item-selection.ts
new file mode 100644
index 0000000000..67f8032400
--- /dev/null
+++ b/web/apps/locker/src/components/items/use-item-selection.ts
@@ -0,0 +1,125 @@
+import type { LockerItem } from "@/types";
+import { hasDownloadableObject, isLockerItemOwner } from "@/types";
+import React, { useCallback, useMemo, useState } from "react";
+
+interface ItemSelectionOptions {
+ visibleItems: LockerItem[];
+ currentUserID: number | undefined;
+ isTrashView: boolean;
+ isCollectionsView: boolean;
+ onStartSelection: () => void;
+ onStopSelection: () => void;
+}
+export function useItemSelection({
+ visibleItems,
+ currentUserID,
+ isTrashView,
+ isCollectionsView,
+ onStartSelection,
+ onStopSelection,
+}: ItemSelectionOptions) {
+ const [selectionMode, setSelectionMode] = useState(false);
+ const [selectedItemIDs, setSelectedItemIDs] = useState<number[]>([]);
+ const visibleSelectableItems = useMemo(() => visibleItems, [visibleItems]);
+ const visibleSelectableItemIDs = useMemo(
+ () => visibleSelectableItems.map((item) => item.id),
+ [visibleSelectableItems],
+ );
+ const selectedVisibleItems = useMemo(() => {
+ const selectedIDSet = new Set(selectedItemIDs);
+ return visibleSelectableItems.filter((item) =>
+ selectedIDSet.has(item.id),
+ );
+ }, [selectedItemIDs, visibleSelectableItems]);
+ const selectedDownloadableItems = useMemo(
+ () =>
+ selectedVisibleItems.filter(
+ (item) => item.type === "file" && hasDownloadableObject(item),
+ ),
+ [selectedVisibleItems],
+ );
+ const selectedOwnedItems = useMemo(
+ () =>
+ selectedVisibleItems.filter((item) =>
+ isLockerItemOwner(item, currentUserID),
+ ),
+ [currentUserID, selectedVisibleItems],
+ );
+ const selectedItemIDSet = useMemo(
+ () => new Set(selectedItemIDs),
+ [selectedItemIDs],
+ );
+ const canBulkSelectVisibleItems =
+ !isTrashView && !isCollectionsView && visibleSelectableItems.length > 0;
+ const skippedSharedSelectionCount =
+ selectedVisibleItems.length - selectedOwnedItems.length;
+ const skippedDownloadSelectionCount =
+ selectedVisibleItems.length - selectedDownloadableItems.length;
+ const allVisibleItemsSelected =
+ visibleSelectableItemIDs.length > 0 &&
+ selectedVisibleItems.length === visibleSelectableItemIDs.length;
+ const startSelectionModeForItem = useCallback(
+ (item: LockerItem) => {
+ setSelectionMode(true);
+ setSelectedItemIDs([item.id]);
+ onStartSelection();
+ },
+ [onStartSelection],
+ );
+ const stopSelectionMode = useCallback(() => {
+ setSelectionMode(false);
+ setSelectedItemIDs([]);
+ onStopSelection();
+ }, [onStopSelection]);
+ const toggleItemSelection = useCallback((item: LockerItem) => {
+ setSelectedItemIDs((current) =>
+ current.includes(item.id)
+ ? current.filter((id) => id !== item.id)
+ : [...current, item.id],
+ );
+ }, []);
+ const toggleSelectAllVisibleItems = useCallback(() => {
+ setSelectedItemIDs((current) =>
+ current.length === visibleSelectableItemIDs.length
+ ? []
+ : visibleSelectableItemIDs,
+ );
+ }, [visibleSelectableItemIDs]);
+ React.useEffect(() => {
+ if (selectionMode && selectedItemIDs.length === 0) {
+ setSelectionMode(false);
+ }
+ }, [selectedItemIDs.length, selectionMode]);
+ React.useEffect(() => {
+ if (
+ isTrashView ||
+ isCollectionsView ||
+ visibleSelectableItemIDs.length === 0
+ ) {
+ setSelectionMode(false);
+ setSelectedItemIDs([]);
+ return;
+ }
+
+ const visibleItemIDSet = new Set(visibleSelectableItemIDs);
+ setSelectedItemIDs((current) =>
+ current.filter((id) => visibleItemIDSet.has(id)),
+ );
+ }, [isCollectionsView, isTrashView, visibleSelectableItemIDs]);
+
+ return {
+ selectionMode,
+ selectedItemIDSet,
+ selectedVisibleItems,
+ selectedDownloadableItems,
+ selectedOwnedItems,
+ canBulkSelectVisibleItems,
+ skippedSharedSelectionCount,
+ skippedDownloadSelectionCount,
+ allVisibleItemsSelected,
+ startSelectionModeForItem,
+ stopSelectionMode,
+ toggleItemSelection,
+ toggleSelectAllVisibleItems,
+ };
+}