From 3e8af16270e0e2270c0b466a7d317f2f77c0a295 Mon Sep 17 00:00:00 2001 From: Daniel Dietzler <36593685+danieldietzler@users.noreply.github.com> Date: Mon, 26 Feb 2024 22:45:08 +0100 Subject: [PATCH] refactor(web): search box (#7397) * refactor search suggestion handling * chore: open api * revert server changes * chore: open api * update location filters * location filter cleanup * refactor people filter * refactor camera filter * refactor display filter * cleanup --------- Co-authored-by: Michel Heusschen <59014050+michelheusschen@users.noreply.github.com> --- server/src/domain/search/search.service.ts | 36 +- .../shared-components/combobox.svelte | 4 + .../search-bar/search-camera-section.svelte | 63 ++ .../search-bar/search-date-section.svelte | 37 ++ .../search-bar/search-display-section.svelte | 32 + .../search-bar/search-filter-box.svelte | 549 +++--------------- .../search-bar/search-location-section.svelte | 96 +++ .../search-bar/search-media-section.svelte | 47 ++ .../search-bar/search-people-section.svelte | 95 +++ 9 files changed, 468 insertions(+), 491 deletions(-) create mode 100644 web/src/lib/components/shared-components/search-bar/search-camera-section.svelte create mode 100644 web/src/lib/components/shared-components/search-bar/search-date-section.svelte create mode 100644 web/src/lib/components/shared-components/search-bar/search-display-section.svelte create mode 100644 web/src/lib/components/shared-components/search-bar/search-location-section.svelte create mode 100644 web/src/lib/components/shared-components/search-bar/search-media-section.svelte create mode 100644 web/src/lib/components/shared-components/search-bar/search-people-section.svelte diff --git a/server/src/domain/search/search.service.ts b/server/src/domain/search/search.service.ts index 95ad848e28..5b56399981 100644 --- a/server/src/domain/search/search.service.ts +++ b/server/src/domain/search/search.service.ts @@ -195,26 +195,22 @@ export class SearchService { } async getSearchSuggestions(auth: AuthDto, dto: SearchSuggestionRequestDto): Promise { - if (dto.type === SearchSuggestionType.COUNTRY) { - return this.metadataRepository.getCountries(auth.user.id); + switch (dto.type) { + case SearchSuggestionType.COUNTRY: { + return this.metadataRepository.getCountries(auth.user.id); + } + case SearchSuggestionType.STATE: { + return this.metadataRepository.getStates(auth.user.id, dto.country); + } + case SearchSuggestionType.CITY: { + return this.metadataRepository.getCities(auth.user.id, dto.country, dto.state); + } + case SearchSuggestionType.CAMERA_MAKE: { + return this.metadataRepository.getCameraMakes(auth.user.id, dto.model); + } + case SearchSuggestionType.CAMERA_MODEL: { + return this.metadataRepository.getCameraModels(auth.user.id, dto.make); + } } - - if (dto.type === SearchSuggestionType.STATE) { - return this.metadataRepository.getStates(auth.user.id, dto.country); - } - - if (dto.type === SearchSuggestionType.CITY) { - return this.metadataRepository.getCities(auth.user.id, dto.country, dto.state); - } - - if (dto.type === SearchSuggestionType.CAMERA_MAKE) { - return this.metadataRepository.getCameraMakes(auth.user.id, dto.model); - } - - if (dto.type === SearchSuggestionType.CAMERA_MODEL) { - return this.metadataRepository.getCameraModels(auth.user.id, dto.make); - } - - return []; } } diff --git a/web/src/lib/components/shared-components/combobox.svelte b/web/src/lib/components/shared-components/combobox.svelte index 7c1e1f68dd..80ea3b7965 100644 --- a/web/src/lib/components/shared-components/combobox.svelte +++ b/web/src/lib/components/shared-components/combobox.svelte @@ -3,6 +3,10 @@ label: string; value: string; }; + + export function toComboBoxOptions(items: string[]) { + return items.map((item) => ({ label: item, value: item })); + } + + + +
+

CAMERA

+ +
+
+ + (filters.make = detail?.value)} + placeholder="Search camera make..." + /> +
+ +
+ + (filters.model = detail?.value)} + placeholder="Search camera model..." + /> +
+
+
diff --git a/web/src/lib/components/shared-components/search-bar/search-date-section.svelte b/web/src/lib/components/shared-components/search-bar/search-date-section.svelte new file mode 100644 index 0000000000..02fa903309 --- /dev/null +++ b/web/src/lib/components/shared-components/search-bar/search-date-section.svelte @@ -0,0 +1,37 @@ + + + + +
+ + + +
diff --git a/web/src/lib/components/shared-components/search-bar/search-display-section.svelte b/web/src/lib/components/shared-components/search-bar/search-display-section.svelte new file mode 100644 index 0000000000..49a2dd56d8 --- /dev/null +++ b/web/src/lib/components/shared-components/search-bar/search-display-section.svelte @@ -0,0 +1,32 @@ + + + + +
+

DISPLAY OPTIONS

+ +
+ + + + + +
+
diff --git a/web/src/lib/components/shared-components/search-bar/search-filter-box.svelte b/web/src/lib/components/shared-components/search-bar/search-filter-box.svelte index 1be3c95602..eb7cc0d871 100644 --- a/web/src/lib/components/shared-components/search-bar/search-filter-box.svelte +++ b/web/src/lib/components/shared-components/search-bar/search-filter-box.svelte @@ -1,242 +1,97 @@ - + +
- {#if suggestions.people.length > 0} -
-
-

PEOPLE

-
- -
- {#each peopleList as person (person.id)} - - {/each} -
- - {#if showAllPeople || suggestions.people.length > peopleList.length} -
- -
- {/if} -
- {/if} +
@@ -389,173 +149,20 @@
-
-

PLACE

- -
-
- - updateSuggestion(SearchSuggestionType.Country, {})} - /> -
- -
- - updateSuggestion(SearchSuggestionType.State, { country: filter.location.country?.value })} - /> -
- -
- - - updateSuggestion(SearchSuggestionType.City, { - country: filter.location.country?.value, - state: filter.location.state?.value, - })} - /> -
-
-
+ -
-

CAMERA

- -
-
- - - updateSuggestion(SearchSuggestionType.CameraMake, { cameraModel: filter.camera.model?.value })} - /> -
- -
- - - updateSuggestion(SearchSuggestionType.CameraModel, { cameraMake: filter.camera.make?.value })} - /> -
-
-
+ -
- - - -
+
-
-

MEDIA TYPE

- -
- - - - - -
-
+ -
-

DISPLAY OPTIONS

- -
- - - - - -
-
+
diff --git a/web/src/lib/components/shared-components/search-bar/search-location-section.svelte b/web/src/lib/components/shared-components/search-bar/search-location-section.svelte new file mode 100644 index 0000000000..2a713e9a04 --- /dev/null +++ b/web/src/lib/components/shared-components/search-bar/search-location-section.svelte @@ -0,0 +1,96 @@ + + + + +
+

PLACE

+ +
+
+ + (filters.country = detail?.value)} + placeholder="Search country..." + /> +
+ +
+ + (filters.state = detail?.value)} + placeholder="Search state..." + /> +
+ +
+ + (filters.city = detail?.value)} + placeholder="Search city..." + /> +
+
+
diff --git a/web/src/lib/components/shared-components/search-bar/search-media-section.svelte b/web/src/lib/components/shared-components/search-bar/search-media-section.svelte new file mode 100644 index 0000000000..a050d6adca --- /dev/null +++ b/web/src/lib/components/shared-components/search-bar/search-media-section.svelte @@ -0,0 +1,47 @@ + + +
+

MEDIA TYPE

+ +
+ + + + + +
+
diff --git a/web/src/lib/components/shared-components/search-bar/search-people-section.svelte b/web/src/lib/components/shared-components/search-bar/search-people-section.svelte new file mode 100644 index 0000000000..6db71e2ae8 --- /dev/null +++ b/web/src/lib/components/shared-components/search-bar/search-people-section.svelte @@ -0,0 +1,95 @@ + + +{#await peoplePromise then people} + {#if people && people.length > 0} + {@const peopleList = showAllPeople ? people : people.slice(0, numberOfPeople)} + +
+
+

PEOPLE

+
+ +
+ {#each peopleList as person (person.id)} + + {/each} +
+ + {#if showAllPeople || people.length > peopleList.length} +
+ +
+ {/if} +
+ {/if} +{/await}