Skip to content

armgit / ente

Public Imported from GitHub
0

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

feat(searchBar):sort-added

Aswin Asok2f7163f07ed6
diff --git a/web/apps/photos/src/components/FileListWithViewer.tsx b/web/apps/photos/src/components/FileListWithViewer.tsx
index 467054d9bc..30a04287a9 100644
--- a/web/apps/photos/src/components/FileListWithViewer.tsx
+++ b/web/apps/photos/src/components/FileListWithViewer.tsx
@@ -222,6 +222,7 @@ export const FileListWithViewer: React.FC<FileListWithViewerProps> = ({
}, [enableImageEditing]);
const shouldShowMapButton =
+ modePlus !== "search" &&
activeCollectionSummary?.type === "all" &&
activeCollectionSummary.fileCount > 0;
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index 098c7049c2..15b1122108 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -522,6 +522,9 @@ const Page: React.FC = () => {
<SearchResultsHeader
searchSuggestion={state.searchSuggestion}
fileCount={state.searchResults?.length ?? 0}
+ onSortOrderChange={(asc) =>
+ dispatch({ type: "setSearchSortOrder", asc })
+ }
/>
),
height: 104,
diff --git a/web/packages/new/photos/components/gallery/index.tsx b/web/packages/new/photos/components/gallery/index.tsx
index cda89d8d59..e4ef423e64 100644
--- a/web/packages/new/photos/components/gallery/index.tsx
+++ b/web/packages/new/photos/components/gallery/index.tsx
@@ -9,14 +9,25 @@
import AddPhotoAlternateIcon from "@mui/icons-material/AddPhotoAlternateOutlined";
import FolderIcon from "@mui/icons-material/FolderOutlined";
-import { Paper, Stack, styled, Typography } from "@mui/material";
-import { CenteredFill } from "ente-base/components/containers";
+import SortIcon from "@mui/icons-material/Sort";
+import {
+ IconButton,
+ Menu,
+ Paper,
+ Stack,
+ styled,
+ Tooltip,
+ Typography,
+} from "@mui/material";
+import { CenteredFill, SpacedRow } from "ente-base/components/containers";
import { EnteLogo } from "ente-base/components/EnteLogo";
import { FocusVisibleButton } from "ente-base/components/mui/FocusVisibleButton";
+import { OverflowMenuOption } from "ente-base/components/OverflowMenu";
+import { useModalVisibility } from "ente-base/components/utils/modal";
import { type UploadTypeSelectorIntent } from "ente-gallery/components/Upload";
import type { SearchSuggestion } from "ente-new/photos/services/search/types";
import { t } from "i18next";
-import React, { useState } from "react";
+import React, { useRef, useState } from "react";
import { Trans } from "react-i18next";
import { enableML } from "../../services/ml";
import { EnableML, FaceConsent } from "../sidebar/MLSettings";
@@ -49,25 +60,110 @@ export type SelectionContext =
interface SearchResultsHeaderProps {
searchSuggestion: SearchSuggestion;
fileCount: number;
+ /** Called when the user changes the sort order. */
+ onSortOrderChange: (asc: boolean) => void;
}
export const SearchResultsHeader: React.FC<SearchResultsHeaderProps> = ({
searchSuggestion,
fileCount,
-}) => (
- <GalleryItemsHeaderAdapter>
- <Typography
- variant="h6"
- sx={{ fontWeight: "regular", color: "text.muted" }}
+ onSortOrderChange,
+}) => {
+ const sortButtonRef = useRef<HTMLButtonElement | null>(null);
+ const { show: showSortOrderMenu, props: sortOrderMenuVisibilityProps } =
+ useModalVisibility();
+
+ const handleAscClick = () => {
+ onSortOrderChange(true);
+ };
+
+ const handleDescClick = () => {
+ onSortOrderChange(false);
+ };
+
+ return (
+ <GalleryItemsHeaderAdapter>
+ <Typography
+ variant="h6"
+ sx={{ fontWeight: "regular", color: "text.muted" }}
+ >
+ {t("search_results")}
+ </Typography>
+ <SpacedRow>
+ <GalleryItemsSummary
+ name={searchSuggestion.label}
+ fileCount={fileCount}
+ />
+ {fileCount > 0 && (
+ <Tooltip title={t("sort_by")}>
+ <IconButton
+ ref={sortButtonRef}
+ onClick={showSortOrderMenu}
+ >
+ <SortIcon />
+ </IconButton>
+ </Tooltip>
+ )}
+ </SpacedRow>
+ <SearchSortOrderMenu
+ {...sortOrderMenuVisibilityProps}
+ sortButtonRef={sortButtonRef}
+ onAscClick={handleAscClick}
+ onDescClick={handleDescClick}
+ />
+ </GalleryItemsHeaderAdapter>
+ );
+};
+
+interface SearchSortOrderMenuProps {
+ open: boolean;
+ onClose: () => void;
+ sortButtonRef: React.RefObject<HTMLButtonElement | null>;
+ onAscClick: () => void;
+ onDescClick: () => void;
+}
+
+const SearchSortOrderMenu: React.FC<SearchSortOrderMenuProps> = ({
+ open,
+ onClose,
+ sortButtonRef,
+ onAscClick,
+ onDescClick,
+}) => {
+ const handleAscClick = () => {
+ onAscClick();
+ onClose();
+ };
+
+ const handleDescClick = () => {
+ onDescClick();
+ onClose();
+ };
+
+ return (
+ <Menu
+ id="search-results-sort"
+ anchorEl={sortButtonRef.current}
+ open={open}
+ onClose={onClose}
+ slotProps={{
+ list: {
+ disablePadding: true,
+ "aria-labelledby": "search-results-sort",
+ },
+ }}
+ anchorOrigin={{ vertical: "bottom", horizontal: "right" }}
+ transformOrigin={{ vertical: "top", horizontal: "right" }}
>
- {t("search_results")}
- </Typography>
- <GalleryItemsSummary
- name={searchSuggestion.label}
- fileCount={fileCount}
- />
- </GalleryItemsHeaderAdapter>
-);
+ <OverflowMenuOption onClick={handleDescClick}>
+ {t("newest_first")}
+ </OverflowMenuOption>
+ <OverflowMenuOption onClick={handleAscClick}>
+ {t("oldest_first")}
+ </OverflowMenuOption>
+ </Menu>
+ );
+};
interface GalleryEmptyStateProps {
/**
diff --git a/web/packages/new/photos/components/gallery/reducer.ts b/web/packages/new/photos/components/gallery/reducer.ts
index 984961b277..7d971fb671 100644
--- a/web/packages/new/photos/components/gallery/reducer.ts
+++ b/web/packages/new/photos/components/gallery/reducer.ts
@@ -441,6 +441,13 @@ export interface GalleryState {
* `true` and {@link searchResults} is defined.
*/
isInSearchMode: boolean;
+ /**
+ * Sort order for search results.
+ *
+ * If `true`, search results are sorted in ascending order (oldest first).
+ * Default is `false` (newest first).
+ */
+ searchSortAsc: boolean;
/**
* The files to show, uniqued and sorted appropriately.
*/
@@ -486,7 +493,8 @@ export type GalleryAction =
| { type: "enterSearchMode"; searchSuggestion?: SearchSuggestion }
| { type: "updatingSearchResults" }
| { type: "setSearchResults"; searchResults: EnteFile[] }
- | { type: "exitSearch"; shouldExitSearchMode?: boolean };
+ | { type: "exitSearch"; shouldExitSearchMode?: boolean }
+ | { type: "setSearchSortOrder"; asc: boolean };
const initialGalleryState: GalleryState = {
user: undefined,
@@ -526,6 +534,7 @@ const initialGalleryState: GalleryState = {
view: undefined,
filteredFiles: [],
isInSearchMode: false,
+ searchSortAsc: false,
};
const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (
@@ -1154,6 +1163,12 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (
: state.isInSearchMode,
});
}
+
+ case "setSearchSortOrder":
+ return stateByUpdatingFilteredFiles({
+ ...state,
+ searchSortAsc: action.asc,
+ });
}
};
@@ -1833,7 +1848,9 @@ const stateForUpdatedCollectionFiles = (
*/
const stateByUpdatingFilteredFiles = (state: GalleryState) => {
if (state.isInSearchMode) {
- const filteredFiles = state.searchResults ?? state.filteredFiles;
+ const searchFiles = state.searchResults ?? state.filteredFiles;
+ // Create a copy before sorting since sortFiles mutates the array
+ const filteredFiles = sortFiles([...searchFiles], state.searchSortAsc);
return { ...state, filteredFiles };
} else if (
state.view?.type == "albums" ||