Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/app/components/item-form/item-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export interface ItemFormAutofillPatch {
<span class="block mb-2 font-medium text-light-font dark:text-dark-font">Poster</span>
<app-poster-picker
[posterId]="formValue().posterId"
[searchSeed]="formValue().title"
(posterIdChange)="updatePosterId($event)"
(loadingChange)="posterLoading.set($event)"
#posterPicker
Expand Down
21 changes: 21 additions & 0 deletions src/app/components/poster-picker/poster-picker.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,27 @@ describe('PosterPickerComponent', () => {
});
});

it('seeds poster search with the item title when opened', async () => {
vi.useFakeTimers();
const tmdbSuggestionService = TestBed.inject(TmdbSuggestionService);
const search = vi.mocked(tmdbSuggestionService.search);
try {
const fixture = TestBed.createComponent(PosterPickerComponent);
fixture.componentRef.setInput('searchSeed', ' Test Movie ');
fixture.detectChanges();

fixture.componentInstance.openPosterSearch();

expect(fixture.componentInstance.showPosterSearch()).toBe(true);
expect(fixture.componentInstance.posterSearchQuery()).toBe('Test Movie');

await vi.advanceTimersByTimeAsync(300);
expect(search).toHaveBeenCalledWith('Test Movie');
} finally {
vi.useRealTimers();
}
});

it('searches TMDB for posters after debounce', async () => {
vi.useFakeTimers();
const tmdbSuggestionService = TestBed.inject(TmdbSuggestionService);
Expand Down
11 changes: 10 additions & 1 deletion src/app/components/poster-picker/poster-picker.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ import { createTmdbSearchStream } from '../../utils/tmdb-search.utils';
@if (!showPosterSearch()) {
<button
type="button"
(click)="showPosterSearch.set(true)"
(click)="openPosterSearch()"
class="self-start px-3 py-1.5 border border-light-border dark:border-dark-border rounded bg-light-bg-secondary dark:bg-dark-bg-secondary text-light-font dark:text-dark-font cursor-pointer hover:bg-light-hover dark:hover:bg-dark-hover text-sm"
>
Search TMDB
Expand All @@ -120,6 +120,7 @@ export class PosterPickerComponent {
private destroyRef = inject(DestroyRef);

readonly posterId = input<string | undefined>(undefined);
readonly searchSeed = input('');
readonly posterIdChange = output<string | undefined>();
readonly loadingChange = output<boolean>();

Expand Down Expand Up @@ -170,6 +171,14 @@ export class PosterPickerComponent {
return getPosterUrl(posterPath);
}

openPosterSearch(): void {
const query = this.searchSeed().trim();
if (query) {
this.onPosterSearchChanged(query);
}
this.showPosterSearch.set(true);
}

onPosterSearchChanged(query: string): void {
this.posterSearchQuery.set(query);
this.tmdb.query.next(query);
Expand Down
Loading