Skip to content

armgit / ente

Public Imported from GitHub
0

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

Fix context-menu selection UI flicker in gallery

Anand Baburajanae2967f78540
diff --git a/web/apps/photos/src/components/FileList.tsx b/web/apps/photos/src/components/FileList.tsx
index dd1f5745b2..a3c76ad57f 100644
--- a/web/apps/photos/src/components/FileList.tsx
+++ b/web/apps/photos/src/components/FileList.tsx
@@ -270,6 +270,9 @@ export interface FileListProps {
onContextMenuAction?: (
action: FileContextAction,
targetFile?: EnteFile,
+ meta?: {
+ isEphemeralSingleSelection: boolean;
+ },
) => void;
/**
* Whether to show the "Add Person" action in the context menu.
@@ -283,6 +286,10 @@ export interface FileListProps {
* Called when the context menu opens or closes.
*/
onContextMenuOpenChange?: (open: boolean) => void;
+ /**
+ * Hide selection visuals/interactions while keeping selection data.
+ */
+ suppressSelectionUI?: boolean;
}
/**
@@ -314,6 +321,7 @@ export const FileList: React.FC<FileListProps> = ({
showAddPersonAction,
showEditLocationAction,
onContextMenuOpenChange,
+ suppressSelectionUI = false,
}) => {
const [_items, setItems] = useState<FileListItem[]>([]);
const items = useDeferredValue(_items);
@@ -775,15 +783,20 @@ export const FileList: React.FC<FileListProps> = ({
const handleContextMenuActionWithTracking = useCallback(
(action: FileContextAction) => {
+ const isEphemeralSingleSelection =
+ selected.count === 1 &&
+ previousSelectionRef.current?.count === 0;
contextMenuActionTakenRef.current = true;
- onContextMenuAction?.(action, contextMenu?.file);
+ onContextMenuAction?.(action, contextMenu?.file, {
+ isEphemeralSingleSelection,
+ });
},
- [onContextMenuAction, contextMenu],
+ [onContextMenuAction, contextMenu, selected.count],
);
const renderListItem = useCallback(
(item: FileListItem, isScrolling: boolean) => {
- const haveSelection = selected.count > 0;
+ const haveSelection = !suppressSelectionUI && selected.count > 0;
const showGroupCheckbox =
haveSelection && !(contextMenu && selected.count === 1);
switch (item.type) {
@@ -824,10 +837,13 @@ export const FileList: React.FC<FileListProps> = ({
{...{
user,
emailByUserID,
- enableSelect,
+ enableSelect:
+ !!enableSelect &&
+ !suppressSelectionUI,
}}
file={file}
selected={
+ !suppressSelectionUI &&
(!mode
? selected.collectionID ===
activeCollectionID
@@ -843,10 +859,10 @@ export const FileList: React.FC<FileListProps> = ({
activeCollectionID)) &&
!!selected[file.id]
}
- selectOnClick={selected.count > 0}
+ selectOnClick={haveSelection}
isRangeSelectActive={
isShiftKeyPressed &&
- selected.count > 0
+ haveSelection
}
isInSelectRange={
rangeStartIndex !== undefined &&
@@ -904,6 +920,7 @@ export const FileList: React.FC<FileListProps> = ({
onItemClick,
rangeStartIndex,
enableSelect,
+ suppressSelectionUI,
selected,
user,
],
diff --git a/web/apps/photos/src/components/FileListWithViewer.tsx b/web/apps/photos/src/components/FileListWithViewer.tsx
index 6676065f30..24ae045559 100644
--- a/web/apps/photos/src/components/FileListWithViewer.tsx
+++ b/web/apps/photos/src/components/FileListWithViewer.tsx
@@ -112,6 +112,7 @@ export type FileListWithViewerProps = {
| "onContextMenuOpenChange"
| "showAddPersonAction"
| "showEditLocationAction"
+ | "suppressSelectionUI"
> &
Pick<
FileViewerProps,
@@ -166,6 +167,7 @@ export const FileListWithViewer: React.FC<FileListWithViewerProps> = ({
onContextMenuOpenChange,
showAddPersonAction,
showEditLocationAction,
+ suppressSelectionUI,
isInIncomingSharedCollection,
isInHiddenSection,
fileNormalCollectionIDs,
@@ -365,6 +367,7 @@ export const FileListWithViewer: React.FC<FileListWithViewerProps> = ({
onContextMenuOpenChange,
showAddPersonAction,
showEditLocationAction,
+ suppressSelectionUI,
}}
onItemClick={handleThumbnailClick}
/>
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index 479574bbb5..611cef2c01 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -189,6 +189,8 @@ const Page: React.FC = () => {
const [isFirstLoad, setIsFirstLoad] = useState(false);
const [isContextMenuOpen, setIsContextMenuOpen] = useState(false);
+ const [suppressContextSelectionBar, setSuppressContextSelectionBar] =
+ useState(false);
const [selected, setSelected] = useState<SelectedState>({
ownCount: 0,
count: 0,
@@ -949,8 +951,12 @@ const Page: React.FC = () => {
[createOnSelectForCollectionOp, remotePull],
);
- const createFileOpHandler = (op: FileOp) => () => {
+ const createFileOpHandler =
+ (op: FileOp, options?: { suppressSelectionBar?: boolean }) => () => {
void (async () => {
+ if (options?.suppressSelectionBar) {
+ setSuppressContextSelectionBar(true);
+ }
showLoadingBar();
try {
if (op == "sendLink") {
@@ -1043,6 +1049,9 @@ const Page: React.FC = () => {
} catch (e) {
onGenericError(e);
} finally {
+ if (options?.suppressSelectionBar) {
+ setSuppressContextSelectionBar(false);
+ }
hideLoadingBar();
}
})();
@@ -1379,33 +1388,54 @@ const Page: React.FC = () => {
* and selects an action from the context menu.
*/
const handleContextMenuAction = useCallback(
- (action: FileContextAction) => {
+ (
+ action: FileContextAction,
+ _targetFile?: EnteFile,
+ meta?: { isEphemeralSingleSelection: boolean },
+ ) => {
+ const suppressSelectionBar = !!meta?.isEphemeralSingleSelection;
// The selection should already be set by FileList's handleContextMenu
// We just need to invoke the appropriate action handler
switch (action) {
case "sendLink":
- createFileOpHandler("sendLink")();
+ createFileOpHandler("sendLink", {
+ suppressSelectionBar,
+ })();
break;
case "download":
- createFileOpHandler("download")();
+ createFileOpHandler("download", {
+ suppressSelectionBar,
+ })();
break;
case "favorite":
- createFileOpHandler("favorite")();
+ createFileOpHandler("favorite", {
+ suppressSelectionBar,
+ })();
break;
case "unfavorite":
- createFileOpHandler("unfavorite")();
+ createFileOpHandler("unfavorite", {
+ suppressSelectionBar,
+ })();
break;
case "archive":
- createFileOpHandler("archive")();
+ createFileOpHandler("archive", {
+ suppressSelectionBar,
+ })();
break;
case "unarchive":
- createFileOpHandler("unarchive")();
+ createFileOpHandler("unarchive", {
+ suppressSelectionBar,
+ })();
break;
case "hide":
- createFileOpHandler("hide")();
+ createFileOpHandler("hide", {
+ suppressSelectionBar,
+ })();
break;
case "fixTime":
- createFileOpHandler("fixTime")();
+ createFileOpHandler("fixTime", {
+ suppressSelectionBar,
+ })();
break;
case "trash":
showMiniDialog({
@@ -1414,7 +1444,9 @@ const Page: React.FC = () => {
continue: {
text: t("move_to_trash"),
color: "critical",
- action: createFileOpHandler("trash"),
+ action: createFileOpHandler("trash", {
+ suppressSelectionBar,
+ }),
},
});
break;
@@ -1425,7 +1457,9 @@ const Page: React.FC = () => {
continue: {
text: t("delete"),
color: "critical",
- action: createFileOpHandler("deletePermanently"),
+ action: createFileOpHandler("deletePermanently", {
+ suppressSelectionBar,
+ }),
},
});
break;
@@ -1632,6 +1666,7 @@ const Page: React.FC = () => {
const showSelectionBar =
selected.count > 0 &&
selected.collectionID === activeCollectionID &&
+ !suppressContextSelectionBar &&
!(isContextMenuOpen && selected.count === 1);
if (!user) {
@@ -1863,6 +1898,7 @@ const Page: React.FC = () => {
isInHiddenSection={barMode == "hidden-albums"}
onContextMenuAction={handleContextMenuAction}
onContextMenuOpenChange={setIsContextMenuOpen}
+ suppressSelectionUI={suppressContextSelectionBar}
showAddPersonAction={showAddPersonAction}
showEditLocationAction={selected.ownCount > 0}
{...{