π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Move new collections to the front for easy access
Vishnu Mohandas22511e70e915
diff --git a/web/apps/locker/src/components/CreateItemDialog.tsx b/web/apps/locker/src/components/CreateItemDialog.tsxindex 91ffee3b45..ad9c8be421 100644--- a/web/apps/locker/src/components/CreateItemDialog.tsx+++ b/web/apps/locker/src/components/CreateItemDialog.tsx@@ -398,6 +398,9 @@ export const CreateItemDialog: React.FC<CreateItemDialogProps> = ({/><CollectionSelector+ key={`${open ? "open" : "closed"}:${+ editItem?.id ?? "create"+ }:${formType}`}collections={displayCollections}selectedIDs={selectedCollectionIDs}initialSelectedIDs={diff --git a/web/apps/locker/src/components/createItemDialog/ItemFormFields.tsx b/web/apps/locker/src/components/createItemDialog/ItemFormFields.tsxindex 87edf702db..e1f6e6b660 100644--- a/web/apps/locker/src/components/createItemDialog/ItemFormFields.tsx+++ b/web/apps/locker/src/components/createItemDialog/ItemFormFields.tsx@@ -221,24 +221,38 @@ export const CollectionSelector: React.FC<{const [createName, setCreateName] = useState("");const [creating, setCreating] = useState(false);const [createError, setCreateError] = useState<string | null>(null);+ const [newlyCreatedCollectionIDs, setNewlyCreatedCollectionIDs] = useState<+ number[]+ >([]);const orderedCollections = useMemo(() => {const sortedCollections = [...collections].sort((a, b) =>a.name.localeCompare(b.name, undefined, { sensitivity: "base" }),);- const initialSelectedIDSet = new Set(initialSelectedIDs ?? []);- if (initialSelectedIDSet.size === 0) {+ const pinnedCollectionIDs = [+ ...newlyCreatedCollectionIDs,+ ...(initialSelectedIDs ?? []).filter(+ (id) => !newlyCreatedCollectionIDs.includes(id),+ ),+ ];+ if (pinnedCollectionIDs.length === 0) {return sortedCollections;}- const initialSelectedCollections = sortedCollections.filter(- (collection) => initialSelectedIDSet.has(collection.id),+ const sortedCollectionsByID = new Map(+ sortedCollections.map((collection) => [collection.id, collection]),);+ const pinnedCollectionIDSet = new Set(pinnedCollectionIDs);+ const pinnedCollections = pinnedCollectionIDs+ .map((id) => sortedCollectionsByID.get(id))+ .filter(+ (collection): collection is LockerCollection => !!collection,+ );const remainingCollections = sortedCollections.filter(- (collection) => !initialSelectedIDSet.has(collection.id),+ (collection) => !pinnedCollectionIDSet.has(collection.id),);- return [...initialSelectedCollections, ...remainingCollections];- }, [collections, initialSelectedIDs]);+ return [...pinnedCollections, ...remainingCollections];+ }, [collections, initialSelectedIDs, newlyCreatedCollectionIDs]);const handleCreateCollection = useCallback(async () => {const name = createName.trim();@@ -250,6 +264,10 @@ export const CollectionSelector: React.FC<{setCreateError(null);try {const newCollectionID = await onCreateCollection(name);+ setNewlyCreatedCollectionIDs((current) => [+ newCollectionID,+ ...current.filter((id) => id !== newCollectionID),+ ]);onToggle(newCollectionID);setCreateName("");setCreateOpen(false);