Skip to content

armgit / ente

Public Imported from GitHub
0

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

fix(SelectedFileOptions):added-unfavorite-option

Aswin Asok0fbbe9c0580c
diff --git a/web/apps/photos/src/components/FileList.tsx b/web/apps/photos/src/components/FileList.tsx
index 4693bbe0bc..3822de3a80 100644
--- a/web/apps/photos/src/components/FileList.tsx
+++ b/web/apps/photos/src/components/FileList.tsx
@@ -669,7 +669,10 @@ export const FileList: React.FC<FileListProps> = ({
showEditLocation: !!showEditLocationAction && selected.ownCount > 0,
});
if (!actions.includes("favorite")) return actions;
- if (selectedFavoriteCount > 0 && selectedFavoriteCount < selected.count) {
+ if (
+ selectedFavoriteCount > 0 &&
+ selectedFavoriteCount < selected.count
+ ) {
return actions.filter(
(action) => action !== "favorite" && action !== "unfavorite",
);
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index 1b75ea951f..03d1167d54 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -1273,6 +1273,18 @@ const Page: React.FC = () => {
const selectedCount = selected.count;
const selectedOwnCount = selected.ownCount;
+ const selectedFavoriteCount = useMemo(() => {
+ if (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]);
/**
* Handle a context menu action on a file.
@@ -1598,6 +1610,7 @@ const Page: React.FC = () => {
}
selectedFileCount={selected.count}
selectedOwnFileCount={selected.ownCount}
+ selectedFavoriteCount={selectedFavoriteCount}
onClearSelection={clearSelection}
onRemoveFilesFromCollection={
handleRemoveFilesFromCollection
diff --git a/web/packages/new/photos/components/SelectedFileOptions.tsx b/web/packages/new/photos/components/SelectedFileOptions.tsx
index eada1a1a08..3d1767c1be 100644
--- a/web/packages/new/photos/components/SelectedFileOptions.tsx
+++ b/web/packages/new/photos/components/SelectedFileOptions.tsx
@@ -22,6 +22,7 @@ import type { Collection } from "ente-media/collection";
import type { CollectionSelectorAttributes } from "ente-new/photos/components/CollectionSelector";
import type { GalleryBarMode } from "ente-new/photos/components/gallery/reducer";
import { StarBorderIcon } from "ente-new/photos/components/icons/StarIcon";
+import { StarOffIcon } from "ente-new/photos/components/icons/StartOffIcon";
import {
PseudoCollectionID,
type CollectionSummary,
@@ -71,6 +72,10 @@ interface SelectedFileOptionsProps {
* The subset of {@link selectedFileCount} that are also owned by the user.
*/
selectedOwnFileCount: number;
+ /**
+ * The number of selected files that are currently favorited.
+ */
+ selectedFavoriteCount: number;
/**
* Called when the user clears the selection by pressing the cancel button
* on the selection bar.
@@ -176,6 +181,7 @@ export const SelectedFileOptions: React.FC<SelectedFileOptionsProps> = ({
collectionSummary,
selectedFileCount,
selectedOwnFileCount,
+ selectedFavoriteCount,
onClearSelection,
onRemoveFilesFromCollection,
onOpenCollectionSelector,
@@ -193,6 +199,7 @@ export const SelectedFileOptions: React.FC<SelectedFileOptionsProps> = ({
!!collectionSummary?.attributes.has("userFavorites");
const handleFavorite = createFileOpHandler("favorite");
+ const handleUnfavorite = createFileOpHandler("unfavorite");
const handleFixTime = createFileOpHandler("fixTime");
@@ -244,6 +251,18 @@ export const SelectedFileOptions: React.FC<SelectedFileOptionsProps> = ({
const isSharedOutgoing =
collectionSummary?.attributes.has("sharedOutgoing");
const isRemovingOthers = selectedFileCount != selectedOwnFileCount;
+ const favoriteAction =
+ selectedFavoriteCount === 0
+ ? "favorite"
+ : selectedFavoriteCount === selectedFileCount
+ ? "unfavorite"
+ : "none";
+ const favoriteActionButton =
+ favoriteAction === "favorite" ? (
+ <FavoriteButton onClick={handleFavorite} />
+ ) : favoriteAction === "unfavorite" ? (
+ <UnfavoriteButton onClick={handleUnfavorite} />
+ ) : null;
const handleRemoveFromCollection = () => {
if (!collection) return;
@@ -336,7 +355,7 @@ export const SelectedFileOptions: React.FC<SelectedFileOptionsProps> = ({
{isInSearchMode ? (
<>
- <FavoriteButton onClick={handleFavorite} />
+ {favoriteActionButton}
<FixTimeButton onClick={handleFixTime} />
{onEditLocation && selectedOwnFileCount > 0 && (
<EditLocationButton onClick={onEditLocation} />
@@ -356,7 +375,7 @@ export const SelectedFileOptions: React.FC<SelectedFileOptionsProps> = ({
</>
) : barMode == "people" ? (
<>
- <FavoriteButton onClick={handleFavorite} />
+ {favoriteActionButton}
<DownloadButton onClick={handleDownload} />
<AddToCollectionButton
onClick={handleAddToCollection}
@@ -417,9 +436,8 @@ export const SelectedFileOptions: React.FC<SelectedFileOptionsProps> = ({
<>
{!isUserFavorites &&
collectionSummary?.id !=
- PseudoCollectionID.archiveItems && (
- <FavoriteButton onClick={handleFavorite} />
- )}
+ PseudoCollectionID.archiveItems &&
+ favoriteActionButton}
<FixTimeButton onClick={handleFixTime} />
{onEditLocation && selectedOwnFileCount > 0 && (
<EditLocationButton onClick={onEditLocation} />
@@ -475,6 +493,14 @@ const FavoriteButton: React.FC<ButtonishProps> = ({ onClick }) => (
</Tooltip>
);
+const UnfavoriteButton: React.FC<ButtonishProps> = ({ onClick }) => (
+ <Tooltip title={t("remove_favorite")}>
+ <IconButton {...{ onClick }}>
+ <StarOffIcon fontSize="small" />
+ </IconButton>
+ </Tooltip>
+);
+
const ArchiveButton: React.FC<ButtonishProps> = ({ onClick }) => (
<Tooltip title={t("archive")}>
<IconButton {...{ onClick }}>