π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
fix(ContextMenu):add-unfavorite-option
Aswin Asoke59abd0d3d76
diff --git a/web/apps/photos/src/components/FileList.tsx b/web/apps/photos/src/components/FileList.tsxindex 00182f5ac6..4693bbe0bc 100644--- a/web/apps/photos/src/components/FileList.tsx+++ b/web/apps/photos/src/components/FileList.tsx@@ -644,18 +644,42 @@ export const FileList: React.FC<FileListProps> = ({if (selected.count == 0) setRangeStartIndex(undefined);}, [selected]);- // Compute available context menu actions based on stable context- // Note: We don't include contextMenu in deps since actions only depend on- // the gallery mode/context, not on whether the menu is open+ const selectedFavoriteCount = useMemo(() => {+ if (!favoriteFileIDs || selected.count == 0) return 0;+ let count = 0;+ for (const [key, value] of Object.entries(selected)) {+ if (typeof value === "boolean" && value) {+ if (favoriteFileIDs.has(Number(key))) {+ count += 1;+ }+ }+ }+ return count;+ }, [favoriteFileIDs, selected]);++ // Compute available context menu actions based on stable context and+ // the favorite status of the current selection (for toggling).const contextMenuActions = useMemo(() => {if (!onContextMenuAction) return [];- return getAvailableFileActions({+ const actions = getAvailableFileActions({barMode: mode,isInSearchMode: modePlus === "search",collectionSummary,showAddPerson: !!showAddPersonAction,showEditLocation: !!showEditLocationAction && selected.ownCount > 0,});+ if (!actions.includes("favorite")) return actions;+ if (selectedFavoriteCount > 0 && selectedFavoriteCount < selected.count) {+ return actions.filter(+ (action) => action !== "favorite" && action !== "unfavorite",+ );+ }+ if (selectedFavoriteCount === selected.count && selected.count > 0) {+ return actions.map((action) =>+ action === "favorite" ? "unfavorite" : action,+ );+ }+ return actions;}, [onContextMenuAction,mode,@@ -664,6 +688,8 @@ export const FileList: React.FC<FileListProps> = ({showAddPersonAction,showEditLocationAction,selected.ownCount,+ selectedFavoriteCount,+ selected.count,]);// Handle context menu opendiff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsxindex 85fe9188b5..1b75ea951f 100644--- a/web/apps/photos/src/pages/gallery.tsx+++ b/web/apps/photos/src/pages/gallery.tsx@@ -951,13 +951,19 @@ const Page: React.FC = () => {): filteredFiles;const selectedFiles = getSelectedFiles(selected, opFiles);- const toProcessFiles =+ const ownedSelectedFiles =op == "download"? selectedFiles: selectedFiles.filter(// There'll be a user if files are being selected.(file) => file.ownerID == user!.id,);+ const toProcessFiles =+ op == "unfavorite"+ ? ownedSelectedFiles.filter((file) =>+ favoriteFileIDs.has(file.id),+ )+ : ownedSelectedFiles;if (toProcessFiles.length > 0) {await performFileOp(op,@@ -977,7 +983,10 @@ const Page: React.FC = () => {// on the user's own files.//// See: [Note: Add and move of non-user files].- if (toProcessFiles.length != selectedFiles.length) {+ if (+ op != "download" &&+ ownedSelectedFiles.length != selectedFiles.length+ ) {showMiniDialog(notifyOthersFilesDialogAttributes());}clearSelection();@@ -1282,6 +1291,9 @@ const Page: React.FC = () => {case "favorite":createFileOpHandler("favorite")();break;+ case "unfavorite":+ createFileOpHandler("unfavorite")();+ break;case "archive":createFileOpHandler("archive")();break;diff --git a/web/apps/photos/src/utils/file/index.ts b/web/apps/photos/src/utils/file/index.tsindex 6482c3dd63..aa8f5035c4 100644--- a/web/apps/photos/src/utils/file/index.ts+++ b/web/apps/photos/src/utils/file/index.ts@@ -9,6 +9,7 @@ import {deleteFromTrash,hideFiles,moveToTrash,+ removeFromFavoritesCollection,} from "ente-new/photos/services/collection";import { updateFilesVisibility } from "ente-new/photos/services/file";import { t } from "i18next";@@ -68,6 +69,9 @@ export const performFileOp = async (case "favorite":await addToFavoritesCollection(files);break;+ case "unfavorite":+ await removeFromFavoritesCollection(files);+ break;case "archive":await updateFilesVisibility(files, ItemVisibility.archived);break;diff --git a/web/packages/base/locales/en-US/translation.json b/web/packages/base/locales/en-US/translation.jsonindex f980e9da20..fbd549b315 100644--- a/web/packages/base/locales/en-US/translation.json+++ b/web/packages/base/locales/en-US/translation.json@@ -171,6 +171,7 @@"join_album_and_comment": "Join album and comment","like_all": "Like all","favorite": "Favorite",+ "remove_favorite": "Unfavorite","convert": "Convert","multi_folder_upload": "Multiple folders detected","upload_to_choice": "Would you like to upload them into",diff --git a/web/packages/new/photos/components/FileContextMenu.tsx b/web/packages/new/photos/components/FileContextMenu.tsxindex 3d265c0770..56e3d86320 100644--- a/web/packages/new/photos/components/FileContextMenu.tsx+++ b/web/packages/new/photos/components/FileContextMenu.tsx@@ -23,6 +23,7 @@ import { StarBorderIcon } from "ente-new/photos/components/icons/StarIcon";import type { FileContextAction } from "ente-new/photos/utils/file-actions";import { t } from "i18next";import React, { memo, useCallback, useMemo } from "react";+import { StarOffIcon } from "./icons/StartOffIcon";/*** Position for anchoring the context menu.@@ -57,6 +58,7 @@ const actionConfigs: Record<FileContextAction, ActionConfig> = {fixTime: { label: "fix_creation_time", Icon: ClockIcon },editLocation: { label: "edit_location", Icon: EditLocationAltIcon },favorite: { label: "favorite", Icon: StarBorderIcon },+ unfavorite: { label: "remove_favorite", Icon: StarOffIcon },archive: { label: "archive", Icon: ArchiveIcon },unarchive: { label: "unarchive", Icon: UnArchiveIcon },hide: { label: "hide", Icon: VisibilityOffOutlinedIcon },diff --git a/web/packages/new/photos/components/SelectedFileOptions.tsx b/web/packages/new/photos/components/SelectedFileOptions.tsxindex 40ccc69309..eada1a1a08 100644--- a/web/packages/new/photos/components/SelectedFileOptions.tsx+++ b/web/packages/new/photos/components/SelectedFileOptions.tsx@@ -35,6 +35,7 @@ export type FileOp =| "download"| "fixTime"| "favorite"+ | "unfavorite"| "archive"| "unarchive"| "hide"diff --git a/web/packages/new/photos/components/icons/StartOffIcon.tsx b/web/packages/new/photos/components/icons/StartOffIcon.tsxnew file mode 100644index 0000000000..2dc2e9093f--- /dev/null+++ b/web/packages/new/photos/components/icons/StartOffIcon.tsx@@ -0,0 +1,28 @@+import SvgIcon, { type SvgIconProps } from "@mui/material/SvgIcon";+import React from "react";++/**+ * Custom star icon (filled).+ *+ * This is the app's custom star shape used for favorites.+ */+export const StarOffIcon: React.FC<SvgIconProps> = (props) => (+ <SvgIcon {...props} viewBox="0 0 21 20">+ <svg+ xmlns="http://www.w3.org/2000/svg"+ viewBox="0 0 24 24"+ width="24"+ height="24"+ color="#ffffff"+ fill="none"+ stroke="#ffffff"+ strokeWidth="1.5"+ strokeLinecap="round"+ strokeLinejoin="round"+ >+ <path d="M18.5038 14.5L21.1477 11.8925C22.616 10.4206 22.1366 8.92853 20.099 8.58575L16.9128 8.05143C16.3734 7.9607 15.7342 7.48687 15.4945 6.99288L13.7366 3.44418C12.7877 1.51861 11.2296 1.51861 10.2707 3.44418L9.5 5" />+ <path d="M7.29561 7.99998C7.22668 8.02267 7.15848 8.04006 7.09201 8.05144L3.90008 8.58576C1.85885 8.92853 1.38856 10.4206 2.84945 11.8925L5.33095 14.3927C5.7512 14.8161 5.98134 15.6327 5.85126 16.2175L5.14083 19.3125C4.58049 21.7522 5.88128 22.7099 8.02257 21.4296L11.0144 19.6452C11.5647 19.3226 12.4553 19.3226 12.9956 19.6452L15.9874 21.4296C18.1387 22.7099 19.4295 21.7623 18.8691 19.3125L18.7974 19" />+ <path d="M2 2L22 22" />+ </svg>+ </SvgIcon>+);diff --git a/web/packages/new/photos/utils/file-actions.ts b/web/packages/new/photos/utils/file-actions.tsindex 12c20c0212..58515800a7 100644--- a/web/packages/new/photos/utils/file-actions.ts+++ b/web/packages/new/photos/utils/file-actions.ts@@ -14,6 +14,7 @@ export type FileContextAction =| "fixTime"| "editLocation"| "favorite"+ | "unfavorite"| "archive"| "unarchive"| "hide"