Skip to content

armgit / ente

Public Imported from GitHub
0

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

feat(spotlight):suggestions-expanded

Aswin Asok3e79c216dd66
diff --git a/web/packages/base/locales/en-US/translation.json b/web/packages/base/locales/en-US/translation.json
index a3e05d8cf9..6f00699afb 100644
--- a/web/packages/base/locales/en-US/translation.json
+++ b/web/packages/base/locales/en-US/translation.json
@@ -242,6 +242,7 @@
"date": "Date",
"description": "Description",
"file_type": "File type",
+ "settings": "Settings",
"magic": "Magic",
"photos_count_zero": "No memories",
"photos_count_one": "1 memory",
diff --git a/web/packages/new/photos/components/SearchBar.tsx b/web/packages/new/photos/components/SearchBar.tsx
index b3ca0d8f55..5796fa1e92 100644
--- a/web/packages/new/photos/components/SearchBar.tsx
+++ b/web/packages/new/photos/components/SearchBar.tsx
@@ -3,6 +3,7 @@ import CloseIcon from "@mui/icons-material/Close";
import ImageIcon from "@mui/icons-material/Image";
import LocationIcon from "@mui/icons-material/LocationOn";
import SearchIcon from "@mui/icons-material/Search";
+import SettingsIcon from "@mui/icons-material/Settings";
import {
Box,
Divider,
@@ -38,6 +39,7 @@ import {
type StylesConfig,
} from "react-select";
import AsyncSelect from "react-select/async";
+import { sidebarSearchOptionsForString } from "../services/search/sidebar-search-registry";
import { SearchPeopleList } from "./PeopleList";
import { UnstyledButton } from "./UnstyledButton";
import {
@@ -186,7 +188,11 @@ const SearchInput: React.FC<Omit<SearchBarProps, "onShowSearchInput">> = ({
const type = value?.suggestion.type;
// Collection and people suggestions are handled differently - our
// caller will switch to the corresponding view, dismissing search.
- if (type == "collection" || type == "person") {
+ if (
+ type == "collection" ||
+ type == "person" ||
+ type == "sidebarAction"
+ ) {
setValue(null);
setInputValue("");
} else {
@@ -304,7 +310,16 @@ const SearchInputWrapper = styled("div")`
margin: auto;
`;
-const loadOptions = pDebounce(searchOptionsForString, 250);
+const loadOptions = pDebounce(async (input: string) => {
+ const [sidebarActions, photoOptions] = await Promise.all([
+ sidebarSearchOptionsForString(input),
+ searchOptionsForString(input),
+ ]);
+
+ return [...photoOptions, ...sidebarActions];
+}, 250);
+
+// const loadOptions = pDebounce(searchOptionsForString, 250);
const createSelectStyles = (
theme: Theme,
@@ -419,6 +434,8 @@ const iconForOption = (option: SearchOption | undefined) => {
return <ImageIcon />;
case "date":
return <CalendarIcon />;
+ case "sidebarAction":
+ return <SettingsIcon />;
case "location":
case "city":
return <LocationIcon />;
@@ -549,20 +566,16 @@ const Option: React.FC<OptionProps<SearchOption, false>> = (props) => (
</SelectComponents.Option>
);
-const OptionContents = ({ data: option }: { data: SearchOption }) => (
- <Stack className="option-contents" sx={{ gap: "4px", px: 2, py: 1 }}>
- <Typography variant="mini" sx={{ color: "text.muted" }}>
- {labelForOption(option)}
- </Typography>
- <Stack
- direction="row"
- sx={{
- gap: 1,
- alignItems: "center",
- justifyContent: "space-between",
- }}
- >
- <Box>
+const OptionContents = ({ data: option }: { data: SearchOption }) => {
+ if (option.suggestion.type === "sidebarAction") {
+ return (
+ <Stack
+ className="option-contents"
+ sx={{ gap: "4px", px: 2, py: 1 }}
+ >
+ <Typography variant="mini" sx={{ color: "text.muted" }}>
+ {labelForOption(option)}
+ </Typography>
<Typography
sx={{
color: "text.base",
@@ -573,22 +586,52 @@ const OptionContents = ({ data: option }: { data: SearchOption }) => (
{option.suggestion.label}
</Typography>
<Typography sx={{ color: "text.muted" }}>
- {t("photos_count", { count: option.fileCount })}
+ {option.suggestion.path.join(" > ")}
</Typography>
- </Box>
-
- <Stack direction="row" sx={{ gap: 1 }}>
- {option.previewFiles.map((file) => (
- <ItemCard
- key={file.id}
- coverFile={file}
- TileComponent={PreviewItemTile}
- />
- ))}
+ </Stack>
+ );
+ }
+ return (
+ <Stack className="option-contents" sx={{ gap: "4px", px: 2, py: 1 }}>
+ <Typography variant="mini" sx={{ color: "text.muted" }}>
+ {labelForOption(option)}
+ </Typography>
+ <Stack
+ direction="row"
+ sx={{
+ gap: 1,
+ alignItems: "center",
+ justifyContent: "space-between",
+ }}
+ >
+ <Box>
+ <Typography
+ sx={{
+ color: "text.base",
+ fontWeight: "medium",
+ wordBreak: "break-word",
+ }}
+ >
+ {option.suggestion.label}
+ </Typography>
+ <Typography sx={{ color: "text.muted" }}>
+ {t("photos_count", { count: option.fileCount })}
+ </Typography>
+ </Box>
+
+ <Stack direction="row" sx={{ gap: 1 }}>
+ {option.previewFiles.map((file) => (
+ <ItemCard
+ key={file.id}
+ coverFile={file}
+ TileComponent={PreviewItemTile}
+ />
+ ))}
+ </Stack>
</Stack>
</Stack>
- </Stack>
-);
+ );
+};
const labelForOption = (option: SearchOption) => {
switch (option.suggestion.type) {
@@ -618,5 +661,8 @@ const labelForOption = (option: SearchOption) => {
case "person":
return t("people");
+
+ case "sidebarAction":
+ return t("settings");
}
};
diff --git a/web/packages/new/photos/services/search/sidebar-search-registry.ts b/web/packages/new/photos/services/search/sidebar-search-registry.ts
new file mode 100644
index 0000000000..c82a879ab9
--- /dev/null
+++ b/web/packages/new/photos/services/search/sidebar-search-registry.ts
@@ -0,0 +1,238 @@
+import { isDesktop } from "ente-base/app";
+import { isHLSGenerationSupported } from "ente-gallery/services/video";
+import { t } from "i18next";
+import { isDevBuildAndUser } from "../settings";
+import type { SearchOption, SidebarActionID } from "./types";
+
+export interface SidebarAction {
+ id: SidebarActionID;
+ label: string;
+ path: string[];
+ keywords?: string[];
+ available?: () => boolean;
+}
+
+const shortcutsCategory = t("shortcuts", { defaultValue: "Shortcuts" });
+const preferencesCategory = t("preferences");
+const accountCategory = t("account");
+const helpCategory = t("help");
+
+export const sidebarActions: SidebarAction[] = [
+ {
+ id: "shortcuts.uncategorized",
+ label: t("section_uncategorized"),
+ path: [shortcutsCategory, t("section_uncategorized")],
+ keywords: ["uncategorized", "ungrouped"],
+ },
+ {
+ id: "shortcuts.archive",
+ label: t("section_archive"),
+ path: [shortcutsCategory, t("section_archive")],
+ keywords: ["archive", "archived"],
+ },
+ {
+ id: "shortcuts.hidden",
+ label: t("section_hidden"),
+ path: [shortcutsCategory, t("section_hidden")],
+ keywords: ["hidden", "private"],
+ },
+ {
+ id: "shortcuts.trash",
+ label: t("section_trash"),
+ path: [shortcutsCategory, t("section_trash")],
+ keywords: ["trash", "bin", "deleted"],
+ },
+ {
+ id: "utility.account",
+ label: t("account"),
+ path: [preferencesCategory, t("account")],
+ keywords: ["profile", "user"],
+ },
+ {
+ id: "utility.watchFolders",
+ label: t("watch_folders"),
+ path: [preferencesCategory, t("watch_folders")],
+ keywords: ["watch", "folder", "desktop"],
+ available: () => isDesktop,
+ },
+ {
+ id: "utility.deduplicate",
+ label: t("deduplicate_files"),
+ path: [preferencesCategory, t("deduplicate_files")],
+ keywords: ["duplicate", "dedupe"],
+ },
+ {
+ id: "utility.preferences",
+ label: t("preferences"),
+ path: [preferencesCategory],
+ keywords: ["settings"],
+ },
+ {
+ id: "utility.help",
+ label: t("help"),
+ path: [helpCategory],
+ keywords: ["support", "docs"],
+ },
+ {
+ id: "utility.export",
+ label: t("export_data"),
+ path: [preferencesCategory, t("export_data")],
+ keywords: ["export", "download"],
+ },
+ {
+ id: "utility.logout",
+ label: t("logout"),
+ path: [preferencesCategory, t("logout")],
+ keywords: ["sign out", "signout"],
+ },
+ {
+ id: "account.recoveryKey",
+ label: t("recovery_key"),
+ path: [accountCategory, t("recovery_key")],
+ keywords: ["recovery", "key", "backup"],
+ },
+ {
+ id: "account.twoFactor",
+ label: t("two_factor"),
+ path: [accountCategory, t("two_factor")],
+ keywords: ["2fa", "otp", "mfa"],
+ },
+ {
+ id: "account.passkeys",
+ label: t("passkeys"),
+ path: [accountCategory, t("passkeys")],
+ keywords: ["webauthn", "security key"],
+ },
+ {
+ id: "account.changePassword",
+ label: t("change_password"),
+ path: [accountCategory, t("change_password")],
+ keywords: ["password"],
+ },
+ {
+ id: "account.changeEmail",
+ label: t("change_email"),
+ path: [accountCategory, t("change_email")],
+ keywords: ["email"],
+ },
+ {
+ id: "account.deleteAccount",
+ label: t("delete_account"),
+ path: [accountCategory, t("delete_account")],
+ keywords: ["delete", "remove"],
+ },
+ {
+ id: "preferences.language",
+ label: t("language"),
+ path: [preferencesCategory, t("language")],
+ keywords: ["locale"],
+ },
+ {
+ id: "preferences.theme",
+ label: t("theme"),
+ path: [preferencesCategory, t("theme")],
+ keywords: ["appearance", "dark mode", "light mode"],
+ },
+ {
+ id: "preferences.customDomains",
+ label: t("custom_domains"),
+ path: [preferencesCategory, t("custom_domains")],
+ keywords: ["domain", "link"],
+ },
+ {
+ id: "preferences.map",
+ label: t("map"),
+ path: [preferencesCategory, t("map")],
+ keywords: ["maps", "location"],
+ },
+ {
+ id: "preferences.advanced",
+ label: t("advanced"),
+ path: [preferencesCategory, t("advanced")],
+ keywords: ["advanced", "proxy", "upload"],
+ },
+ {
+ id: "preferences.mlSearch",
+ label: t("ml_search"),
+ path: [preferencesCategory, t("ml_search")],
+ keywords: ["ml", "search", "magic"],
+ },
+ {
+ id: "preferences.streamableVideos",
+ label: t("streamable_videos"),
+ path: [preferencesCategory, t("streamable_videos")],
+ keywords: ["hls", "video", "stream"],
+ available: () => isHLSGenerationSupported,
+ },
+ {
+ id: "help.helpCenter",
+ label: t("ente_help"),
+ path: [helpCategory, t("ente_help")],
+ keywords: ["help", "docs"],
+ },
+ {
+ id: "help.blog",
+ label: t("blog"),
+ path: [helpCategory, t("blog")],
+ keywords: ["news"],
+ },
+ {
+ id: "help.requestFeature",
+ label: t("request_feature"),
+ path: [helpCategory, t("request_feature")],
+ keywords: ["feature", "feedback"],
+ },
+ {
+ id: "help.support",
+ label: t("support"),
+ path: [helpCategory, t("support")],
+ keywords: ["contact", "support"],
+ },
+ {
+ id: "help.viewLogs",
+ label: t("view_logs"),
+ path: [helpCategory, t("view_logs")],
+ keywords: ["logs", "debug"],
+ },
+ {
+ id: "help.testUpload",
+ label: t("test_upload"),
+ path: [helpCategory, t("test_upload")],
+ keywords: ["test", "upload"],
+ available: () => isDevBuildAndUser(),
+ },
+];
+
+export const sidebarSearchOptionsForString = (
+ searchString: string,
+): SearchOption[] => {
+ const normalized = searchString.trim().toLowerCase();
+ if (!normalized) return [];
+
+ return sidebarActions
+ .filter(({ available }) => !available || available())
+ .filter(({ label, path, keywords }) =>
+ matchesSearch(normalized, label, path, keywords),
+ )
+ .map(({ id, label, path }) => ({
+ suggestion: { type: "sidebarAction", actionID: id, path, label },
+ fileCount: 0,
+ previewFiles: [],
+ }));
+};
+
+const matchesSearch = (
+ normalized: string,
+ label: string,
+ path: string[],
+ keywords: string[] = [],
+) => {
+ const haystack = [label, ...path, ...keywords]
+ .filter(Boolean)
+ .map((s) => s.toLowerCase());
+
+ const re = new RegExp("(^|[\\s.,!?\"'-_])" + escapeRegex(normalized));
+ return haystack.some((h) => re.test(h));
+};
+
+const escapeRegex = (s: string) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
diff --git a/web/packages/new/photos/services/search/types.ts b/web/packages/new/photos/services/search/types.ts
index 1f9a4ef03b..4a73bb216f 100644
--- a/web/packages/new/photos/services/search/types.ts
+++ b/web/packages/new/photos/services/search/types.ts
@@ -10,6 +10,51 @@ import { FileType } from "ente-media/file-type";
import type { Person } from "ente-new/photos/services/ml/people";
import type { LocationTag } from "../user-entity";
+/**
+ * Represents the unique identifiers for various sidebar actions in the application.
+ *
+ * These IDs are organized into categories:
+ * - `shortcuts.*`: Quick access actions like uncategorized items, archive, hidden items, and trash
+ * - `utility.*`: General utility actions such as account management, folder watching, deduplication, preferences, help, export, and logout
+ * - `account.*`: Account-specific settings including recovery key, two-factor authentication, passkeys, password/email management, and account deletion
+ * - `preferences.*`: User preference options like language, theme, custom domains, map settings, advanced options, ML search, and streamable videos
+ * - `help.*`: Help-related actions including help center, blog, feature requests, support, log viewing, and test upload
+ *
+ * @remarks
+ * This type is used to ensure type safety when referencing sidebar actions throughout the application.
+ */
+export type SidebarActionID =
+ | "shortcuts.uncategorized"
+ | "shortcuts.archive"
+ | "shortcuts.hidden"
+ | "shortcuts.trash"
+ | "utility.account"
+ | "utility.watchFolders"
+ | "utility.deduplicate"
+ | "utility.preferences"
+ | "utility.help"
+ | "utility.export"
+ | "utility.logout"
+ | "account.recoveryKey"
+ | "account.twoFactor"
+ | "account.passkeys"
+ | "account.changePassword"
+ | "account.changeEmail"
+ | "account.deleteAccount"
+ | "preferences.language"
+ | "preferences.theme"
+ | "preferences.customDomains"
+ | "preferences.map"
+ | "preferences.advanced"
+ | "preferences.mlSearch"
+ | "preferences.streamableVideos"
+ | "help.helpCenter"
+ | "help.blog"
+ | "help.requestFeature"
+ | "help.support"
+ | "help.viewLogs"
+ | "help.testUpload";
+
/**
* A search suggestion.
*
@@ -26,6 +71,7 @@ export type SearchSuggestion = { label: string } & (
| { type: "city"; city: City }
| { type: "clip"; clipScoreForFileID: Map<number, number> }
| { type: "person"; person: Person }
+ | { type: "sidebarAction"; actionID: SidebarActionID; path: string[] }
);
/**