π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
feat(SearchBar):add-no-location-search
Aswin Asokd98ab73c2b9a
diff --git a/web/apps/photos/src/components/SearchBar.tsx b/web/apps/photos/src/components/SearchBar.tsxindex 6811806174..8e12b9ed5a 100644--- a/web/apps/photos/src/components/SearchBar.tsx+++ b/web/apps/photos/src/components/SearchBar.tsx@@ -4,6 +4,7 @@ import { HugeiconsIcon } from "@hugeicons/react";import CalendarIcon from "@mui/icons-material/CalendarMonth";import CloseIcon from "@mui/icons-material/Close";import ImageIcon from "@mui/icons-material/Image";+import NoLocationIcon from "@mui/icons-material/LocationOffOutlined";import LocationIcon from "@mui/icons-material/LocationOn";import CameraIcon from "@mui/icons-material/PhotoCameraOutlined";import SettingsIcon from "@mui/icons-material/Settings";@@ -375,6 +376,8 @@ const iconForOption = (option: SearchOption | undefined) => {case "location":case "city":return <LocationIcon />;+ case "noLocation":+ return <NoLocationIcon />;default:return <HugeiconsIcon icon={Search01Icon} />;}@@ -571,6 +574,9 @@ const labelForOption = (option: SearchOption) => {case "date":return t("date");+ case "noLocation":+ return t("location");+case "location":return t("location");diff --git a/web/packages/base/locales/en-US/translation.json b/web/packages/base/locales/en-US/translation.jsonindex 6726fd1e51..5d0cfb930f 100644--- a/web/packages/base/locales/en-US/translation.json+++ b/web/packages/base/locales/en-US/translation.json@@ -463,6 +463,7 @@"no_photos_found_here": "No photos found here","zoom_out_to_see_photos": "Zoom out to see photos","no_geotagged_photos": "No photos found with location information",+ "no_location": "No location","search_hint": "Search for albums, dates, descriptions, ...","albums_search_hint": "Search for albums...","album": "Album",diff --git a/web/packages/new/photos/services/search/index.ts b/web/packages/new/photos/services/search/index.tsindex d23b0f0da1..49a79c4f3f 100644--- a/web/packages/new/photos/services/search/index.ts+++ b/web/packages/new/photos/services/search/index.ts@@ -1,3 +1,4 @@+import { ensureLocalUser } from "ente-accounts/services/user";import log from "ente-base/log";import { ensureMasterKeyFromSession } from "ente-base/session";import { ComlinkWorker } from "ente-base/worker/comlink-worker";@@ -51,6 +52,7 @@ export const updateSearchCollectionsAndFiles = ();void worker().then((w) =>w.setCollectionsAndFiles({+ currentUserID: ensureLocalUser().id,collections: normalCollections,files: uniqueFilesByID(normalCollectionFiles),collectionFiles: normalCollectionFiles,@@ -127,6 +129,7 @@ const localizedSearchData = () =>locale: i18n.language,holidays: holidays(),labelledFileTypes: labelledFileTypes(),+ noLocationLabel: t("no_location"),});const holidays = (): LabelledSearchDateComponents[] => [diff --git a/web/packages/new/photos/services/search/types.ts b/web/packages/new/photos/services/search/types.tsindex a3b0ca19bc..84cb222789 100644--- a/web/packages/new/photos/services/search/types.ts+++ b/web/packages/new/photos/services/search/types.ts@@ -53,6 +53,7 @@ export type SearchSuggestion = { label: string } & (| { type: "cameraMake"; fileIDs: number[] }| { type: "cameraModel"; fileIDs: number[] }| { type: "date"; dateComponents: SearchDateComponents }+ | { type: "noLocation" }| { type: "location"; locationTag: LocationTag }| { type: "city"; city: City }| { type: "clip"; clipScoreForFileID: Map<number, number> }@@ -67,6 +68,7 @@ export interface SearchOption {}export interface SearchCollectionsAndFiles {+ currentUserID: number;collections: Collection[];// Unique by file ID.files: EnteFile[];@@ -88,6 +90,7 @@ export interface LocalizedSearchData {locale: string;holidays: LabelledSearchDateComponents[];labelledFileTypes: LabelledFileType[];+ noLocationLabel: string;}// At least one component is always present.diff --git a/web/packages/new/photos/services/search/worker.ts b/web/packages/new/photos/services/search/worker.tsindex 46acedf30d..a6a032e7b7 100644--- a/web/packages/new/photos/services/search/worker.ts+++ b/web/packages/new/photos/services/search/worker.ts@@ -35,6 +35,7 @@ export class SearchWorker {private locationTags: LocationTag[] = [];private cities: City[] = [];private collectionsAndFiles: SearchCollectionsAndFiles = {+ currentUserID: 0,collections: [],files: [],collectionFiles: [],@@ -100,7 +101,12 @@ const suggestionsForString = (searchString: string,{ collections, files }: SearchCollectionsAndFiles,people: NamedPerson[],- { locale, holidays, labelledFileTypes }: LocalizedSearchData,+ {+ locale,+ holidays,+ labelledFileTypes,+ noLocationLabel,+ }: LocalizedSearchData,locationTags: LocationTag[],cities: City[],): [SearchSuggestion[], SearchSuggestion[]] => [@@ -108,6 +114,7 @@ const suggestionsForString = ([fileTypeSuggestions(re, labelledFileTypes),dateSuggestions(s, re, locale, holidays),+ noLocationSuggestion(s, noLocationLabel),locationSuggestions(re, locationTags, cities),collectionSuggestions(re, collections),fileNameSuggestion(s, re, searchString, files),@@ -381,21 +388,30 @@ const locationSuggestions = (].flat();};+const noLocationSuggestion = (s: string, label: string): SearchSuggestion[] =>+ s.length > 2 && label.toLowerCase().startsWith(s)+ ? [{ type: "noLocation", label }]+ : [];+const filterSearchableFiles = (- { files, collectionFiles }: SearchCollectionsAndFiles,+ { currentUserID, files, collectionFiles }: SearchCollectionsAndFiles,suggestion: SearchSuggestion,) => {if (suggestion.type == "sidebarAction") return [];return sortMatchesIfNeeded((suggestion.type == "collection" ? collectionFiles : files).filter(- (f) => isMatchingFile(f, suggestion),+ (f) => isMatchingFile(f, suggestion, currentUserID),),suggestion,);};-const isMatchingFile = (file: EnteFile, suggestion: SearchSuggestion) => {+const isMatchingFile = (+ file: EnteFile,+ suggestion: SearchSuggestion,+ currentUserID: number,+) => {switch (suggestion.type) {case "collection":return suggestion.collectionID === file.collectionID;@@ -417,6 +433,9 @@ const isMatchingFile = (file: EnteFile, suggestion: SearchSuggestion) => {fileCreationPhotoDate(file),);+ case "noLocation":+ return file.ownerID == currentUserID && !fileLocation(file);+case "location": {const location = fileLocation(file);if (!location) return false;