π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
feat(photos):group-search-results-and-add-empty-state
Aswin Asokcddced40cbe9
diff --git a/web/apps/photos/src/components/SearchBar.tsx b/web/apps/photos/src/components/SearchBar.tsxindex daf3e0cf0f..8c701775e2 100644--- a/web/apps/photos/src/components/SearchBar.tsx+++ b/web/apps/photos/src/components/SearchBar.tsx@@ -1,5 +1,6 @@import { sidebarTheme } from "@/components/sidebar/theme";import {+ groupSearchOptions,matchesSearchCategory,searchCategories,searchCategoryCounts,@@ -18,6 +19,7 @@ import CameraIcon from "@mui/icons-material/PhotoCameraOutlined";import SettingsIcon from "@mui/icons-material/Settings";import {Box,+ Button,Dialog,IconButton,Stack,@@ -59,6 +61,7 @@ import React, { useEffect, useId, useMemo, useRef, useState } from "react";import {components as SelectComponents,type ControlProps,+ type GroupHeadingProps,type InputActionMeta,type InputProps,type MenuProps,@@ -214,7 +217,13 @@ const SearchInput: React.FC<[theme, isKeyboardNavigating],);const components = useMemo(- () => ({ Control, Input, Option, Menu: SearchMenu }),+ () => ({+ Control,+ Input,+ Option,+ Menu: SearchMenu,+ GroupHeading: SearchGroupHeading,+ }),[],);@@ -364,7 +373,12 @@ const SearchInput: React.FC<loadingMessage={() => t("loading")}noOptionsMessage={({ inputValue }) => {if (inputValue) {- return t("no_results");+ return (+ <SearchNoMatches+ category={category}+ onSeeAll={() => setCategory("all")}+ />+ );}if (shouldShowEmptyState(inputValue)) {return (@@ -395,7 +409,9 @@ function SearchMenu(props: MenuProps<SearchOption, false>) {const id = useId();const hasQuery = !!props.selectProps.inputValue.trim();const counts = searchCategoryCounts(- props.options as readonly SearchOption[],+ props.options.flatMap((option) =>+ "options" in option ? [...option.options] : [option],+ ),);return (@@ -482,6 +498,72 @@ function SearchMenu(props: MenuProps<SearchOption, false>) {);}+function SearchGroupHeading(props: GroupHeadingProps<SearchOption, false>) {+ const {+ searchCategory: { category },+ } = props.selectProps as typeof props.selectProps & SearchCategoryProps;+ if (category !== "all") return null;+ return (+ <SelectComponents.GroupHeading {...props}>+ <Typography+ variant="h6"+ sx={{ color: "text.base", textTransform: "none", mb: 1 }}+ >+ {t(+ props.data.label === "places"+ ? "search_places"+ : props.data.label!,+ )}+ </Typography>+ </SelectComponents.GroupHeading>+ );+}++function SearchNoMatches({+ category,+ onSeeAll,+}: {+ category: SearchCategory;+ onSeeAll: () => void;+}) {+ return (+ <Stack+ sx={{+ alignItems: "center",+ textAlign: "center",+ gap: "16px",+ py: "20px",+ }}+ >+ <Box+ component="img"+ src="/images/auth-ducky.svg"+ alt=""+ sx={{ width: 130, height: 100, objectFit: "contain" }}+ />+ <Typography variant="h3" sx={{ color: "text.base" }}>+ {t("search_no_matches")}+ </Typography>+ <Typography variant="small" sx={{ color: "text.muted" }}>+ {t(+ category === "all"+ ? "search_try_another"+ : "search_empty_category",+ )}+ </Typography>+ {category !== "all" && (+ <Button+ color="secondary"+ onMouseDown={(event) => event.stopPropagation()}+ onClick={onSeeAll}+ >+ {t("search_see_all")}+ </Button>+ )}+ </Stack>+ );+}+const SearchInputWrapper = styled("div")`display: flex;width: 100%;@@ -496,7 +578,7 @@ const loadOptions = pDebounce(async (input: string) => {const sidebarActions = sidebarSearchOptionsForString(input);const photoOptions = await searchOptionsForString(input);- return [...photoOptions, ...sidebarActions];+ return groupSearchOptions([...photoOptions, ...sidebarActions]);}, 250);const createSelectStyles = (@@ -554,6 +636,14 @@ const createSelectStyles = ("&::-webkit-scrollbar-button": { display: "none" },},}),+ group: (style) => ({+ ...style,+ display: "flex",+ flexDirection: "column",+ gap: "8px",+ padding: 0,+ }),+ groupHeading: (style) => ({ ...style, margin: 0, padding: 0 }),option: (style, { isFocused }) => ({...style,padding: 0,diff --git a/web/apps/photos/src/services/search/search-categories.ts b/web/apps/photos/src/services/search/search-categories.tsindex f2a29ea39d..39f415f408 100644--- a/web/apps/photos/src/services/search/search-categories.ts+++ b/web/apps/photos/src/services/search/search-categories.ts@@ -52,3 +52,14 @@ export const searchCategoryCounts = (options: readonly SearchOption[]) => {counts[searchCategoryForType(option.suggestion.type)]++;return counts;};++export const groupSearchOptions = (options: readonly SearchOption[]) =>+ searchCategories+ .filter((category) => category !== "all")+ .map((category) => ({+ label: category,+ options: options.filter((option) =>+ matchesSearchCategory(option, category),+ ),+ }))+ .filter((group) => group.options.length > 0);diff --git a/web/apps/photos/tests/search-categories.test.ts b/web/apps/photos/tests/search-categories.test.tsindex 6ce8518de1..f7743f1c97 100644--- a/web/apps/photos/tests/search-categories.test.ts+++ b/web/apps/photos/tests/search-categories.test.ts@@ -4,6 +4,7 @@ import type {} from "ente-new/photos/services/search/types";import { describe, expect, test } from "vitest";import {+ groupSearchOptions,matchesSearchCategory,searchCategories,searchCategoryCounts,@@ -98,3 +99,20 @@ describe("search categories", () => {});});});++test("groups results in tab order while preserving rows within each category", () => {+ const firstPhoto = option("clip");+ const secondPhoto = option("fileName");+ const album = option("collection");+ const place = option("city");+ const setting = option("sidebarAction");+ const options = [firstPhoto, setting, place, secondPhoto, album];+ expect(groupSearchOptions(options)).toEqual([+ { label: "albums", options: [album] },+ { label: "places", options: [place] },+ { label: "photos", options: [firstPhoto, secondPhoto] },+ { label: "settings", options: [setting] },+ ]);+ expect(options).toEqual([firstPhoto, setting, place, secondPhoto, album]);+ expect(groupSearchOptions([])).toEqual([]);+});diff --git a/web/packages/base/locales/en-US/translation.json b/web/packages/base/locales/en-US/translation.jsonindex 1a822f3450..315accdfaf 100644--- a/web/packages/base/locales/en-US/translation.json+++ b/web/packages/base/locales/en-US/translation.json@@ -478,6 +478,10 @@"people_search_hint": "Search people","search_results": "Search results","search_places": "Places",+ "search_no_matches": "No matches found!",+ "search_try_another": "Try another name, date or description.",+ "search_empty_category": "No matches in this category.",+ "search_see_all": "See all results","no_results": "No results found","no_photos_found_here": "No photos found here","zoom_out_to_see_photos": "Zoom out to see photos",