Skip to content

refactor(web): search people - #9082

Merged
jrasm91 merged 11 commits into
mainfrom
fix/refactor-search-people
Apr 29, 2024
Merged

jrasm91 merged 11 commits into
mainfrom
fix/refactor-search-people

Conversation

@martabal

@martabal martabal commented Apr 25, 2024 •

Copy link
Copy Markdown
Contributor

This PR aims to simplify and reduce bugs with search people. Currently there are multiple implementations for the same search, this PR creates a new modal for all person search.

fix #5571

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Apr 25, 2024 •

Copy link
Copy Markdown

Deploying immich with  Cloudflare Pages  Cloudflare Pages

Latest commit: f4ca564
Status: ✅  Deploy successful!
Preview URL: https://0b7f0693.immich.pages.dev
Branch Preview URL: https://fix-refactor-search-people.immich.pages.dev

View logs

@martabal
martabal force-pushed the fix/refactor-search-people branch 4 times, most recently from f459ddd to 18cfb55 Compare April 26, 2024 15:57
@martabal
martabal force-pushed the fix/refactor-search-people branch from 18cfb55 to 5f80630 Compare April 26, 2024 16:01
@martabal
martabal marked this pull request as ready for review April 26, 2024 16:07

@danieldietzler danieldietzler left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rough first review

searchedPeopleLocal = searchNameLocal(searchName, searchedPeople, numberPeopleToSearch);
};

export let handleSearch = async (force?: boolean, name?: string) => {

@danieldietzler danieldietzler Apr 26, 2024 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this method accept a name? I don't see any place where that's passed. Actually, I don't even see the point why that method should be exported in the first place

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also personally find this method quite hard to read. I'm not 100% sure why that is; I think it's just many ifs for a method I'd expect to be simple :D

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's because of

 onMount(async () => {
   const getSearchedPeople = $page.url.searchParams.get(QueryParameter.SEARCHED_PEOPLE);
   if (getSearchedPeople) {
     searchName = getSearchedPeople;
     await handleSearchPeople(true, searchName);
   }
 });

here

The search is saved in a query parameter so onMount, if you don't have that handleSearchPeople, you don't trigger the search and searchName in the search-people component is not yet binded to the searchName from its parent.

The issue with that component is that it's doing the search for every components. It was implemented 4 times with different features and bugs, I prefer to have one which is doing everything well.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But handleSearchPeople is a different method, no? I'm confused...

@martabal martabal Apr 26, 2024 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, it's binded to handleSearch like that :

<SearchPeople
  type="searchBar"
  placeholder="Search people"
  onReset={onResetSearchBar}
  onSearch={handleSearch}
  bind:searchName
  bind:searchedPeopleLocal
  bind:isSearching={isSearchingPeople}
  bind:handleSearch={handleSearchPeople}
/>

so the parent component can interact with the child method.

import { searchNameLocal } from '$lib/utils/person';
import { searchPerson, type PersonResponseDto } from '@immich/sdk';

export let searchName: string;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this actually need to be exported?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, so the parent component know what's the user input, it allowed me to simplify that part thanks to that :

$: showPeople = searchName ? searchedPeopleLocal : people.filter((person) => !person.isHidden)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh now it's starting to make sense to me....

@martabal martabal Apr 26, 2024 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah at the end, parent components "just" get a nice searchbar and a list of suggested people, they can do whatever they want with that list (most of the time filtering) and searchName is a nice way to know when the user is searching a person or not

use:initInput
<SearchPeople
type="input"
bind:searchName

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need to bind the name since SearchPeople won't update it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as before, but I can probably simplify with something like that 15c1e89

@martabal
martabal force-pushed the fix/refactor-search-people branch from 26e4009 to 830f8ad Compare April 26, 2024 20:55
@martabal
martabal force-pushed the fix/refactor-search-people branch from 830f8ad to daa24cc Compare April 26, 2024 20:56

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename this component to something more descriptive? Is it a UI element? which type of element is it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UI + handlers to avoid useless API requests. I renamed it people-search to follow the same pattern as the other files

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this search bar component only used for people's searches?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's used for the album search too

let name = '';
let searchWord: string;
let isSearchingPeople = false;
let showPeople: PersonResponseDto[];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this showPeople mean search result?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's for the people shown to the users.

@alextran1502 alextran1502 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the improvement is good, however, it is still quite complex to follow the logic of the component around. Is there any way we can think of a fool-proof design for these components so you know exactly what they are doing?

@martabal

Copy link
Copy Markdown
Contributor Author

Yes, the logic is complex, we can probably optimize it but we will probably hit some limits. I prefer to have one complex component rather than writing the same component/handler multiple times.

@jrasm91
jrasm91 enabled auto-merge (squash) April 29, 2024 21:36
@jrasm91
jrasm91 merged commit 5722c83 into main Apr 29, 2024
@jrasm91
jrasm91 deleted the fix/refactor-search-people branch April 29, 2024 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Select face search not working consistently

4 participants