Skip to content

armgit / ente

Public Imported from GitHub
0

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

Style

vishnukvmdcbe30f20337b
diff --git a/web/apps/locker/src/components/CreateItemDialog.tsx b/web/apps/locker/src/components/CreateItemDialog.tsx
index 8f8638baf5..bb617a272f 100644
--- a/web/apps/locker/src/components/CreateItemDialog.tsx
+++ b/web/apps/locker/src/components/CreateItemDialog.tsx
@@ -14,7 +14,7 @@ import {
TextField,
Typography,
} from "@mui/material";
-import { FileUploadSection } from "components/createItemDialog/FileUploadSection";
+import { CollectionChipRow } from "components/createItemDialog/CollectionChipRow";
import {
addCollectionName,
collectionNamesByUploadItem,
@@ -23,6 +23,7 @@ import {
toggleCollectionName,
uploadQueueItemKey,
} from "components/createItemDialog/fileUploadHelpers";
+import { FileUploadSection } from "components/createItemDialog/FileUploadSection";
import { lockerDialogPaperSx } from "components/lockerDialogStyles";
import {
createDocumentIcon,
@@ -315,6 +316,29 @@ export const CreateItemDialog: React.FC<CreateItemDialogProps> = ({
);
}, [displayCollections, isEditMode, open, selectedCollectionIDs]);
+ useEffect(() => {
+ if (
+ !open ||
+ isEditMode ||
+ selectedCollectionIDs.length > 0 ||
+ defaultCollectionID === null ||
+ defaultCollectionID === undefined ||
+ !displayCollections.some(
+ (collection) => collection.id === defaultCollectionID,
+ )
+ ) {
+ return;
+ }
+
+ setSelectedCollectionIDs([defaultCollectionID]);
+ }, [
+ defaultCollectionID,
+ displayCollections,
+ isEditMode,
+ open,
+ selectedCollectionIDs.length,
+ ]);
+
useEffect(() => {
if (!uploading) {
return;
@@ -814,7 +838,7 @@ export const CreateItemDialog: React.FC<CreateItemDialogProps> = ({
disabled={!canSave}
onClick={() => void handleSave()}
>
- {isEditMode ? t("saveRecord") : t("create")}
+ {t("saveRecord")}
</LoadingButton>
</Stack>
</Stack>
@@ -1100,6 +1124,19 @@ const CollectionSelector: React.FC<{
const [createName, setCreateName] = useState("");
const [creating, setCreating] = useState(false);
const [createError, setCreateError] = useState<string | null>(null);
+ const orderedCollections = useMemo(() => {
+ const selectedIDSet = new Set(selectedIDs);
+ const sortedCollections = [...collections].sort((a, b) =>
+ a.name.localeCompare(b.name, undefined, { sensitivity: "base" }),
+ );
+ const selectedCollections = sortedCollections.filter((collection) =>
+ selectedIDSet.has(collection.id),
+ );
+ const remainingCollections = sortedCollections.filter(
+ (collection) => !selectedIDSet.has(collection.id),
+ );
+ return [...selectedCollections, ...remainingCollections];
+ }, [collections, selectedIDs]);
const handleCreateCollection = useCallback(async () => {
const name = createName.trim();
@@ -1127,82 +1164,23 @@ const CollectionSelector: React.FC<{
return (
<Box>
- <Stack
- direction="row"
- sx={{
- alignItems: "center",
- justifyContent: "space-between",
- gap: 1,
- mb: 1.5,
- }}
- >
- <Typography
- variant="small"
- sx={{
- color: "text.faint",
- fontWeight: "bold",
- textTransform: "uppercase",
- letterSpacing: "0.08em",
- display: "block",
- }}
- >
- {t("collections")}
- </Typography>
- </Stack>
-
- {collections.length > 0 || onCreateCollection ? (
- <Stack direction="row" sx={{ gap: 1.5, flexWrap: "wrap" }}>
- {onCreateCollection && (
- <ButtonBase
- onClick={() => {
- setCreateOpen((open) => !open);
- setCreateError(null);
- }}
- sx={(theme) => ({
- borderRadius: "999px",
- px: 1.5,
- py: 0.875,
- border: `1px dotted ${theme.vars.palette.stroke.muted}`,
- color: theme.vars.palette.text.muted,
- backgroundColor: createOpen
- ? theme.vars.palette.fill.faint
- : "transparent",
- })}
- >
- <Typography variant="small">
- + {t("collection")}
- </Typography>
- </ButtonBase>
- )}
- {collections.map((collection) => (
- <ButtonBase
- key={collection.id}
- onClick={() => onToggle(collection.id)}
- sx={(theme) => ({
- borderRadius: "999px",
- px: 1.5,
- py: 0.875,
- backgroundColor: selectedIDs.includes(
- collection.id,
- )
- ? theme.vars.palette.primary.main
- : theme.vars.palette.fill.faint,
- color: selectedIDs.includes(collection.id)
- ? theme.vars.palette.primary.contrastText
- : theme.vars.palette.text.base,
- })}
- >
- <Typography variant="small">
- {collection.name}
- </Typography>
- </ButtonBase>
- ))}
- </Stack>
- ) : (
- <Typography variant="body" sx={{ color: "text.muted" }}>
- {t("noCollectionsAvailableForSelection")}
- </Typography>
- )}
+ <CollectionChipRow
+ items={orderedCollections.map((collection) => ({
+ key: String(collection.id),
+ label: collection.name,
+ selected: selectedIDs.includes(collection.id),
+ onClick: () => onToggle(collection.id),
+ }))}
+ createOpen={createOpen}
+ onCreateClick={
+ onCreateCollection
+ ? () => {
+ setCreateOpen((open) => !open);
+ setCreateError(null);
+ }
+ : undefined
+ }
+ />
{createOpen && onCreateCollection && (
<Stack sx={{ gap: 1, mt: 1.5 }}>
diff --git a/web/apps/locker/src/components/ItemList.tsx b/web/apps/locker/src/components/ItemList.tsx
index 12ddab2c75..c96649746e 100644
--- a/web/apps/locker/src/components/ItemList.tsx
+++ b/web/apps/locker/src/components/ItemList.tsx
@@ -1,6 +1,7 @@
import AddOutlinedIcon from "@mui/icons-material/AddOutlined";
import ArrowBackRoundedIcon from "@mui/icons-material/ArrowBackRounded";
import CheckCircleRoundedIcon from "@mui/icons-material/CheckCircleRounded";
+import ChevronRightRoundedIcon from "@mui/icons-material/ChevronRightRounded";
import ClearRoundedIcon from "@mui/icons-material/ClearRounded";
import DeleteOutlineIcon from "@mui/icons-material/DeleteOutline";
import DeleteSweepOutlinedIcon from "@mui/icons-material/DeleteSweepOutlined";
@@ -35,7 +36,13 @@ import {
import { isHTTPErrorWithStatus } from "ente-base/http";
import log from "ente-base/log";
import { t } from "i18next";
-import React, { useCallback, useMemo, useState } from "react";
+import React, {
+ useCallback,
+ useEffect,
+ useMemo,
+ useRef,
+ useState,
+} from "react";
import {
deleteLockerFileShareLink,
downloadLockerFile,
@@ -1825,130 +1832,219 @@ const CollectionChipFilters: React.FC<{
collections: LockerCollection[];
selectedCollectionIDs: number[];
onToggleCollection: (collectionID: number) => void;
-}> = ({ collections, selectedCollectionIDs, onToggleCollection }) => (
- <Box
- sx={{
- position: "relative",
- width: "100%",
- maxWidth: contentMaxWidth,
- mx: "auto",
- mt: 0.5,
- }}
- >
- <Stack
- direction="row"
+}> = ({ collections, selectedCollectionIDs, onToggleCollection }) => {
+ const scrollContainerRef = useRef<HTMLDivElement | null>(null);
+ const [showLeftScrollHint, setShowLeftScrollHint] = useState(false);
+ const [showRightScrollHint, setShowRightScrollHint] = useState(false);
+
+ 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={{
- flexWrap: "nowrap",
- overflowX: "auto",
- overflowY: "hidden",
- justifyContent: "flex-start",
- gap: 0,
- pb: 0.5,
- scrollbarWidth: "none",
- "&::-webkit-scrollbar": { display: "none" },
+ width: "100%",
+ maxWidth: contentMaxWidth,
+ mx: "auto",
+ mt: 0.5,
}}
>
- {collections.map((collection) => {
- const isSelected = selectedCollectionIDs.includes(
- collection.id,
- );
+ <Stack direction="row" sx={{ alignItems: "stretch", gap: 0 }}>
+ <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 (
- <Box key={collection.id} sx={{ pr: 1, flexShrink: 0 }}>
- <Chip
- clickable
- label={collection.name}
- onClick={() => onToggleCollection(collection.id)}
+ return (
+ <ButtonBase
+ key={collection.id}
+ onClick={() =>
+ onToggleCollection(collection.id)
+ }
+ sx={(theme) => ({
+ borderRadius: "999px",
+ px: 1.5,
+ py: 0.875,
+ whiteSpace: "nowrap",
+ flexShrink: 0,
+ backgroundColor: isSelected
+ ? "#1071FF"
+ : theme.vars.palette.fill.faint,
+ color: isSelected
+ ? "#FFFFFF"
+ : theme.vars.palette.text.base,
+ ...theme.applyStyles("light", {
+ backgroundColor: isSelected
+ ? "#1071FF"
+ : "#FFFFFF",
+ border: isSelected
+ ? "none"
+ : "1px solid rgba(17, 24, 39, 0.06)",
+ }),
+ })}
+ >
+ <Typography variant="small">
+ {collection.name}
+ </Typography>
+ </ButtonBase>
+ );
+ })}
+ </Stack>
+ {showLeftScrollHint && (
+ <Box
sx={(theme) => ({
- height: 36,
- flexShrink: 0,
- borderRadius: "999px",
- fontWeight: isSelected ? 700 : 600,
- color: isSelected
- ? theme.vars.palette.primary.main
- : theme.vars.palette.text.base,
- backgroundColor: isSelected
- ? "rgba(16, 113, 255, 0.10)"
- : theme.vars.palette.fill.faint,
- border: "1px solid transparent",
- boxShadow: isSelected
- ? `inset 0 0 0 1px ${theme.vars.palette.primary.main}`
- : "none",
- transition:
- "background-color 180ms ease, color 180ms ease, box-shadow 180ms ease",
- "& .MuiChip-label": { px: 1.5 },
- "&:hover": {
- backgroundColor: isSelected
- ? "rgba(16, 113, 255, 0.14)"
- : theme.vars.palette.fill.faintHover,
- },
+ position: "absolute",
+ top: 0,
+ left: 0,
+ bottom: 0,
+ width: 40,
+ pointerEvents: "none",
+ background:
+ "linear-gradient(90deg, #08090A 0%, rgba(8, 9, 10, 0) 100%)",
...theme.applyStyles("light", {
- backgroundColor: isSelected
- ? "rgba(16, 113, 255, 0.10)"
- : "#FFFFFF",
- border: isSelected
- ? "1px solid rgba(16, 113, 255, 0.24)"
- : "1px solid rgba(17, 24, 39, 0.06)",
- "&:hover": {
- backgroundColor: isSelected
- ? "rgba(16, 113, 255, 0.14)"
- : "#F8FAFC",
- },
+ background:
+ "linear-gradient(90deg, #F3F4F6 0%, rgba(243, 244, 246, 0) 100%)",
}),
})}
/>
- </Box>
- );
- })}
- </Stack>
- </Box>
-);
+ )}
+ {showRightScrollHint && (
+ <Box
+ sx={(theme) => ({
+ position: "absolute",
+ top: 0,
+ right: 0,
+ bottom: 0,
+ width: 72,
+ pointerEvents: "none",
+ background:
+ "linear-gradient(90deg, rgba(8, 9, 10, 0) 0%, #08090A 100%)",
+ ...theme.applyStyles("light", {
+ background:
+ "linear-gradient(90deg, rgba(243, 244, 246, 0) 0%, #F3F4F6 100%)",
+ }),
+ })}
+ />
+ )}
+ </Box>
+ <Box
+ sx={{
+ width: 28,
+ flexShrink: 0,
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center",
+ }}
+ >
+ {showRightScrollHint && (
+ <ButtonBase
+ onClick={scrollRight}
+ sx={(theme) => ({
+ width: 28,
+ height: "100%",
+ color: "#4A4A4A",
+ borderRadius: "999px",
+ ...theme.applyStyles("dark", {
+ color: "#FFFFFF",
+ }),
+ })}
+ >
+ <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")}>
- <Chip
- clickable
- icon={<FilterListRoundedIcon sx={{ fontSize: 18 }} />}
+ <ButtonBase
onClick={onClick}
sx={(theme) => ({
- height: 36,
- flexShrink: 0,
borderRadius: "999px",
- fontWeight: selected ? 700 : 600,
- color: selected ? "primary.main" : theme.vars.palette.text.base,
+ px: 1.25,
+ py: 0.875,
+ flexShrink: 0,
+ minWidth: 44,
+ color: selected ? "#FFFFFF" : theme.vars.palette.text.base,
backgroundColor: selected
- ? "rgba(16, 113, 255, 0.10)"
+ ? "#1071FF"
: theme.vars.palette.fill.faint,
- border: "1px solid transparent",
- boxShadow: selected
- ? `inset 0 0 0 1px ${theme.vars.palette.primary.main}`
- : "none",
- "& .MuiChip-icon": { color: "inherit", m: 0 },
- "& .MuiChip-label": { display: "none" },
- px: 1.125,
"&:hover": {
backgroundColor: selected
- ? "rgba(16, 113, 255, 0.14)"
+ ? "#1071FF"
: theme.vars.palette.fill.faintHover,
},
...theme.applyStyles("light", {
- backgroundColor: selected
- ? "rgba(16, 113, 255, 0.10)"
- : "#FFFFFF",
+ backgroundColor: selected ? "#1071FF" : "#FFFFFF",
border: selected
- ? "1px solid rgba(16, 113, 255, 0.24)"
+ ? "none"
: "1px solid rgba(17, 24, 39, 0.06)",
"&:hover": {
- backgroundColor: selected
- ? "rgba(16, 113, 255, 0.14)"
- : "#F8FAFC",
+ backgroundColor: selected ? "#1071FF" : "#F8FAFC",
},
}),
})}
- />
+ >
+ <FilterListRoundedIcon sx={{ fontSize: 18 }} />
+ </ButtonBase>
</Tooltip>
);
diff --git a/web/apps/locker/src/components/createItemDialog/CollectionChipRow.tsx b/web/apps/locker/src/components/createItemDialog/CollectionChipRow.tsx
new file mode 100644
index 0000000000..4bbafc33a0
--- /dev/null
+++ b/web/apps/locker/src/components/createItemDialog/CollectionChipRow.tsx
@@ -0,0 +1,199 @@
+import ChevronRightRoundedIcon from "@mui/icons-material/ChevronRightRounded";
+import { Box, ButtonBase, Stack, Typography } from "@mui/material";
+import type { Theme } from "@mui/material/styles";
+import { t } from "i18next";
+import React, { useEffect, useRef, useState } from "react";
+
+interface CollectionChipRowItem {
+ key: string;
+ label: string;
+ selected: boolean;
+ onClick: () => void;
+}
+
+export const CollectionChipRow: React.FC<{
+ items: CollectionChipRowItem[];
+ createOpen: boolean;
+ disabled?: boolean;
+ onCreateClick?: () => void;
+ fadeColor?: (theme: Theme) => string;
+}> = ({
+ items,
+ createOpen,
+ disabled,
+ onCreateClick,
+ fadeColor = (theme) => theme.vars.palette.background.paper,
+}) => {
+ const scrollContainerRef = useRef<HTMLDivElement | null>(null);
+ const [showScrollHint, setShowScrollHint] = useState(false);
+
+ 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 = () => {
+ const remainingScroll =
+ container.scrollWidth -
+ container.clientWidth -
+ container.scrollLeft;
+ setShowScrollHint(remainingScroll > 8);
+ };
+
+ updateScrollHint();
+ container.addEventListener("scroll", updateScrollHint, {
+ passive: true,
+ });
+ window.addEventListener("resize", updateScrollHint);
+
+ return () => {
+ container.removeEventListener("scroll", updateScrollHint);
+ window.removeEventListener("resize", updateScrollHint);
+ };
+ }, [createOpen, items.length]);
+
+ return (
+ <Box>
+ <Stack
+ direction="row"
+ sx={{
+ alignItems: "center",
+ justifyContent: "space-between",
+ gap: 1,
+ mb: 1.25,
+ }}
+ >
+ <Typography
+ variant="small"
+ sx={{
+ color: "text.faint",
+ fontWeight: "bold",
+ textTransform: "uppercase",
+ letterSpacing: "0.08em",
+ display: "block",
+ }}
+ >
+ {t("collections")}
+ </Typography>
+ </Stack>
+ <Stack direction="row" sx={{ alignItems: "stretch", gap: 0 }}>
+ <Box sx={{ position: "relative", flex: 1, minWidth: 0 }}>
+ <Stack
+ ref={scrollContainerRef}
+ direction="row"
+ sx={{
+ gap: 1,
+ flexWrap: "nowrap",
+ overflowX: "auto",
+ overflowY: "hidden",
+ pr: 2,
+ pb: 0.5,
+ scrollbarWidth: "none",
+ "&::-webkit-scrollbar": { display: "none" },
+ }}
+ >
+ {onCreateClick && (
+ <ButtonBase
+ onClick={onCreateClick}
+ disabled={disabled}
+ sx={(theme) => ({
+ borderRadius: "999px",
+ px: 1.5,
+ py: 0.875,
+ whiteSpace: "nowrap",
+ flexShrink: 0,
+ border: `1px dotted ${theme.vars.palette.stroke.muted}`,
+ color: theme.vars.palette.text.muted,
+ backgroundColor: createOpen
+ ? theme.vars.palette.fill.faint
+ : "transparent",
+ })}
+ >
+ <Typography variant="small">
+ + {t("collection")}
+ </Typography>
+ </ButtonBase>
+ )}
+ {items.map((item) => (
+ <ButtonBase
+ key={item.key}
+ onClick={item.onClick}
+ disabled={disabled}
+ sx={(theme) => ({
+ borderRadius: "999px",
+ px: 1.5,
+ py: 0.875,
+ whiteSpace: "nowrap",
+ flexShrink: 0,
+ backgroundColor: item.selected
+ ? "#1071FF"
+ : theme.vars.palette.fill.faint,
+ color: item.selected
+ ? "#FFFFFF"
+ : theme.vars.palette.text.base,
+ })}
+ >
+ <Typography variant="small">
+ {item.label}
+ </Typography>
+ </ButtonBase>
+ ))}
+ </Stack>
+ {showScrollHint && (
+ <Box
+ sx={(theme) => ({
+ position: "absolute",
+ top: 0,
+ right: 0,
+ bottom: 0,
+ width: 64,
+ pointerEvents: "none",
+ background: `linear-gradient(90deg, rgba(0, 0, 0, 0) 0%, ${fadeColor(theme)} 100%)`,
+ })}
+ />
+ )}
+ </Box>
+ <Box
+ sx={{
+ width: 28,
+ flexShrink: 0,
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center",
+ }}
+ >
+ {showScrollHint && (
+ <ButtonBase
+ onClick={scrollRight}
+ disabled={disabled}
+ sx={(theme) => ({
+ width: 28,
+ height: "100%",
+ color: "#4A4A4A",
+ borderRadius: "999px",
+ ...theme.applyStyles("dark", {
+ color: "#FFFFFF",
+ }),
+ })}
+ >
+ <ChevronRightRoundedIcon sx={{ fontSize: 28 }} />
+ </ButtonBase>
+ )}
+ </Box>
+ </Stack>
+ </Box>
+ );
+};
diff --git a/web/apps/locker/src/components/createItemDialog/FileUploadSection.tsx b/web/apps/locker/src/components/createItemDialog/FileUploadSection.tsx
index 9af6cdbd02..28f2a3eb32 100644
--- a/web/apps/locker/src/components/createItemDialog/FileUploadSection.tsx
+++ b/web/apps/locker/src/components/createItemDialog/FileUploadSection.tsx
@@ -1,5 +1,4 @@
import CheckRoundedIcon from "@mui/icons-material/CheckRounded";
-import ChevronRightRoundedIcon from "@mui/icons-material/ChevronRightRounded";
import CloudUploadOutlinedIcon from "@mui/icons-material/CloudUploadOutlined";
import DeleteOutlineRoundedIcon from "@mui/icons-material/DeleteOutlineRounded";
import ErrorOutlineRoundedIcon from "@mui/icons-material/ErrorOutlineRounded";
@@ -13,6 +12,7 @@ import {
TextField,
Typography,
} from "@mui/material";
+import { CollectionChipRow } from "components/createItemDialog/CollectionChipRow";
import {
lockerItemIcon,
lockerItemIconConfig,
@@ -20,13 +20,7 @@ import {
import { FocusVisibleButton } from "ente-base/components/mui/FocusVisibleButton";
import { LoadingButton } from "ente-base/components/mui/LoadingButton";
import { t } from "i18next";
-import React, {
- useCallback,
- useEffect,
- useMemo,
- useRef,
- useState,
-} from "react";
+import React, { useCallback, useMemo, useState } from "react";
import type { LockerUploadProgress } from "services/remote";
import type { LockerCollection, LockerUploadCandidate } from "types";
@@ -255,7 +249,7 @@ export function FileUploadSection({
sx={{ borderRadius: "16px", py: 1.25 }}
onClick={() => void onUpload()}
>
- {t("upload")}
+ {t("saveRecord")}
</LoadingButton>
</Stack>
</Stack>
@@ -452,8 +446,6 @@ const CollectionNameSelector: React.FC<{
}) => {
const [createOpen, setCreateOpen] = useState(false);
const [createName, setCreateName] = useState("");
- const scrollContainerRef = useRef<HTMLDivElement | null>(null);
- const [showScrollHint, setShowScrollHint] = useState(false);
const selectedNameMap = useMemo(
() =>
new Map(
@@ -465,56 +457,69 @@ const CollectionNameSelector: React.FC<{
[selectedNames],
);
const displayNames = useMemo(() => {
- const sortedSuggestedNames = [
- ...dedupeCollectionNames(suggestedNames),
- ].sort((a, b) =>
- a.localeCompare(b, undefined, { sensitivity: "base" }),
- );
- const sortedRemainingNames = dedupeCollectionNames([
+ const allNames = dedupeCollectionNames([
...collections.map((collection) => collection.name),
...availableNames,
...selectedNames,
- ])
- .filter(
- (name) =>
- !sortedSuggestedNames.some(
- (suggestedName) =>
- normalizeCollectionName(suggestedName) ===
- normalizeCollectionName(name),
- ),
- )
+ ]);
+ const selectedNameSet = new Set(
+ selectedNames.map((name) => normalizeCollectionName(name)),
+ );
+ const suggestedNameSet = new Set(
+ suggestedNames.map((name) => normalizeCollectionName(name)),
+ );
+ const sortedSelectedSuggestedNames = allNames
+ .filter((name) => {
+ const normalizedName = normalizeCollectionName(name);
+ return (
+ selectedNameSet.has(normalizedName) &&
+ suggestedNameSet.has(normalizedName)
+ );
+ })
.sort((a, b) =>
a.localeCompare(b, undefined, { sensitivity: "base" }),
);
- return [...sortedSuggestedNames, ...sortedRemainingNames];
+ const sortedSelectedNames = allNames
+ .filter((name) => {
+ const normalizedName = normalizeCollectionName(name);
+ return (
+ selectedNameSet.has(normalizedName) &&
+ !suggestedNameSet.has(normalizedName)
+ );
+ })
+ .sort((a, b) =>
+ a.localeCompare(b, undefined, { sensitivity: "base" }),
+ );
+ const sortedSuggestedNames = allNames
+ .filter((name) => {
+ const normalizedName = normalizeCollectionName(name);
+ return (
+ suggestedNameSet.has(normalizedName) &&
+ !selectedNameSet.has(normalizedName)
+ );
+ })
+ .sort((a, b) =>
+ a.localeCompare(b, undefined, { sensitivity: "base" }),
+ );
+ const sortedRemainingNames = allNames
+ .filter((name) => {
+ const normalizedName = normalizeCollectionName(name);
+ return (
+ !selectedNameSet.has(normalizedName) &&
+ !suggestedNameSet.has(normalizedName)
+ );
+ })
+ .sort((a, b) =>
+ a.localeCompare(b, undefined, { sensitivity: "base" }),
+ );
+ return [
+ ...sortedSelectedSuggestedNames,
+ ...sortedSelectedNames,
+ ...sortedSuggestedNames,
+ ...sortedRemainingNames,
+ ];
}, [availableNames, collections, selectedNames, suggestedNames]);
- useEffect(() => {
- const container = scrollContainerRef.current;
- if (!container) {
- return;
- }
-
- const updateScrollHint = () => {
- const remainingScroll =
- container.scrollWidth -
- container.clientWidth -
- container.scrollLeft;
- setShowScrollHint(remainingScroll > 8);
- };
-
- updateScrollHint();
- container.addEventListener("scroll", updateScrollHint, {
- passive: true,
- });
- window.addEventListener("resize", updateScrollHint);
-
- return () => {
- container.removeEventListener("scroll", updateScrollHint);
- window.removeEventListener("resize", updateScrollHint);
- };
- }, [displayNames.length, createOpen]);
-
const handleAddCollectionName = useCallback(() => {
const trimmedName = createName.trim();
if (!trimmedName) {
@@ -528,127 +533,19 @@ const CollectionNameSelector: React.FC<{
return (
<Box>
- <Stack
- direction="row"
- sx={{
- alignItems: "center",
- justifyContent: "space-between",
- gap: 1,
- mb: 1.25,
- }}
- >
- <Typography
- variant="small"
- sx={{
- color: "text.faint",
- fontWeight: "bold",
- textTransform: "uppercase",
- letterSpacing: "0.08em",
- display: "block",
- }}
- >
- {t("collections")}
- </Typography>
- </Stack>
- <Box sx={{ position: "relative" }}>
- <Stack
- ref={scrollContainerRef}
- direction="row"
- sx={{
- gap: 1,
- flexWrap: "nowrap",
- overflowX: "auto",
- overflowY: "hidden",
- pr: 6,
- pb: 0.5,
- scrollbarWidth: "none",
- "&::-webkit-scrollbar": { display: "none" },
- }}
- >
- <ButtonBase
- onClick={() => setCreateOpen((open) => !open)}
- disabled={disabled}
- sx={(theme) => ({
- borderRadius: "999px",
- px: 1.5,
- py: 0.875,
- whiteSpace: "nowrap",
- flexShrink: 0,
- border: `1px dotted ${theme.vars.palette.stroke.muted}`,
- color: theme.vars.palette.text.muted,
- backgroundColor: createOpen
- ? theme.vars.palette.fill.faint
- : "transparent",
- })}
- >
- <Typography variant="small">
- + {t("collection")}
- </Typography>
- </ButtonBase>
- {displayNames.map((name) => {
- const isSelected = selectedNameMap.has(
- normalizeCollectionName(name),
- );
- return (
- <ButtonBase
- key={name}
- onClick={() => onToggleName(name)}
- disabled={disabled}
- sx={(theme) => ({
- borderRadius: "999px",
- px: 1.5,
- py: 0.875,
- whiteSpace: "nowrap",
- flexShrink: 0,
- backgroundColor: isSelected
- ? "#1071FF"
- : theme.vars.palette.fill.faint,
- color: isSelected
- ? "#FFFFFF"
- : theme.vars.palette.text.base,
- })}
- >
- <Typography variant="small">{name}</Typography>
- </ButtonBase>
- );
- })}
- </Stack>
- {showScrollHint && (
- <Box
- sx={(theme) => ({
- position: "absolute",
- top: 0,
- right: 0,
- bottom: 0,
- width: 72,
- display: "flex",
- alignItems: "center",
- justifyContent: "flex-end",
- pr: 0.5,
- pointerEvents: "none",
- background: `linear-gradient(90deg, ${theme.vars.palette.background.default}00 0%, ${theme.vars.palette.background.default}E6 52%, ${theme.vars.palette.background.default} 74%)`,
- })}
- >
- <Box
- sx={(theme) => ({
- width: 22,
- height: 22,
- borderRadius: "999px",
- backgroundColor:
- theme.vars.palette.background.default,
- display: "flex",
- alignItems: "center",
- justifyContent: "center",
- })}
- >
- <ChevronRightRoundedIcon
- sx={{ color: "text.faint", fontSize: 20 }}
- />
- </Box>
- </Box>
- )}
- </Box>
-
+ <CollectionChipRow
+ items={displayNames.map((name) => ({
+ key: name,
+ label: name,
+ selected: selectedNameMap.has(
+ normalizeCollectionName(name),
+ ),
+ onClick: () => onToggleName(name),
+ }))}
+ createOpen={createOpen}
+ disabled={disabled}
+ onCreateClick={() => setCreateOpen((open) => !open)}
+ />
{createOpen && (
<Stack sx={{ gap: 1, mt: 1.25 }}>
<Stack