diff --git a/scripts/build.mjs b/scripts/build.mjs index 609ea64b..9d755ed6 100755 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -1,7 +1,6 @@ #!/usr/bin/env node -import { spawnSync } from 'node:child_process'; +import { execSync, spawnSync } from 'node:child_process'; import { readFileSync } from 'node:fs'; -import { execSync } from 'node:child_process'; function getVersion() { try { @@ -17,19 +16,18 @@ function getHash() { if (process.env.GITHUB_SHA) return process.env.GITHUB_SHA; if (process.env.COMMIT_HASH) return process.env.COMMIT_HASH; try { - return execSync('git rev-parse HEAD', { encoding: 'utf8', stdio: ['pipe', 'pipe', 'ignore'] }).trim(); + return execSync('git rev-parse HEAD', { + encoding: 'utf8', + stdio: ['pipe', 'pipe', 'ignore'], + }).trim(); } catch { return 'unknown'; } } -function getBuildDate() { - return new Date().toISOString(); -} - const version = getVersion(); const hash = getHash(); -const buildDate = getBuildDate(); +const buildDate = new Date().toISOString(); const extraArgs = process.argv.slice(2); diff --git a/src/app/app.ts b/src/app/app.ts index 1f5e4962..efbc95a9 100644 --- a/src/app/app.ts +++ b/src/app/app.ts @@ -23,7 +23,6 @@ export class App { private readonly importExportService = inject(ImportExportService); private readonly document = inject(DOCUMENT); private readonly updates = inject(SwUpdate, { optional: true }); - protected readonly title = signal('watch-list'); protected readonly saveError = this.storageService.getSaveErrorSignal(); protected readonly inMemorySession = this.storageService.getInMemorySessionSignal(); protected readonly settingsUnavailable = inject(BrowserSettingsStorage).unavailable; diff --git a/src/app/components/add-item/add-item.component.ts b/src/app/components/add-item/add-item.component.ts index 5d030928..961f1878 100644 --- a/src/app/components/add-item/add-item.component.ts +++ b/src/app/components/add-item/add-item.component.ts @@ -5,7 +5,7 @@ import { of, Subject, switchMap } from 'rxjs'; import { WatchListService } from '../../services/watch-list.service'; import { GroupService } from '../../services/group.service'; import { SuggestionSearchService } from '../../services/suggestion-search.service'; -import { ItemFormComponent } from '../item-form/item-form.component'; +import { ItemFormAutofillPatch, ItemFormComponent } from '../item-form/item-form.component'; import { buildItemMutationInput, createDefaultItemFormValue, @@ -81,7 +81,7 @@ export class AddItemComponent { readonly suggestions = this.search.results; readonly suggestionsLoading = this.search.loading; readonly suggestionsError = this.search.error; - readonly autofillPatch = signal<{ id: number; value: Partial } | null>(null); + readonly autofillPatch = signal(null); private autofillPatchId = 0; readonly duplicateTitleHint = computed(() => { const normalizedTitle = this.normalizeTitle(this.title()); @@ -99,13 +99,7 @@ export class AddItemComponent { constructor() { this.selectedEpisodicRef .pipe( - switchMap((ref) => { - if (ref === null) { - return of(null); - } - - return this.suggestionSearchService.getDetails(ref); - }), + switchMap((ref) => (ref ? this.suggestionSearchService.getDetails(ref) : of(null))), takeUntilDestroyed(this.destroyRef), ) .subscribe((details) => { @@ -113,12 +107,7 @@ export class AddItemComponent { return; } - this.autofillPatch.set({ - id: ++this.autofillPatchId, - value: { - seasons: details.seasons, - }, - }); + this.autofillPatch.set({ id: ++this.autofillPatchId, value: { seasons: details.seasons } }); }); } @@ -136,21 +125,13 @@ export class AddItemComponent { onSuggestionSelected(suggestion: Suggestion): void { this.title.set(suggestion.title); this.search.dismiss(suggestion.title); - - if (!isEpisodicType(suggestion.type)) { - this.autofillPatch.set({ - id: ++this.autofillPatchId, - value: { season: 1, episode: 1, seasons: [] }, - }); - this.selectedEpisodicRef.next(null); - return; - } - this.autofillPatch.set({ id: ++this.autofillPatchId, value: { season: 1, episode: 1, seasons: [] }, }); - this.selectedEpisodicRef.next({ source: suggestion.source, id: suggestion.id }); + this.selectedEpisodicRef.next( + isEpisodicType(suggestion.type) ? { source: suggestion.source, id: suggestion.id } : null, + ); } async onSubmit(formValue: ItemFormValue): Promise { diff --git a/src/app/components/home/home.component.spec.ts b/src/app/components/home/home.component.spec.ts index 60667e78..82d4cfb5 100644 --- a/src/app/components/home/home.component.spec.ts +++ b/src/app/components/home/home.component.spec.ts @@ -208,12 +208,7 @@ describe('HomeComponent', () => { it('markItem delegates to correct service methods', async () => { setup(); const fixture = TestBed.createComponent(HomeComponent); - const svc = TestBed.inject(WatchListService) as unknown as { - markWatched: ReturnType; - markCompleted: ReturnType; - markDropped: ReturnType; - markPaused: ReturnType; - }; + const svc = TestBed.inject(WatchListService); const item = createItem({ id: 'x', title: 'X', status: 'in-progress', isAdult: false }); await fixture.componentInstance.markItem(() => item, 'watched'); @@ -332,26 +327,17 @@ describe('HomeComponent', () => { expect(fixture.nativeElement.textContent).toContain('No movies currently being watched'); }); - it('computes hasSeries and hasMovies correctly', () => { + it('distinguishes an empty watch list from one with nothing in progress', () => { setup({ watchItems: [createItem({ id: '1', title: 'S', type: 'series' })] }); let fixture = TestBed.createComponent(HomeComponent); fixture.detectChanges(); - expect((fixture.componentInstance as unknown as { hasSeries: () => boolean }).hasSeries()).toBe( - true, - ); + expect(fixture.nativeElement.textContent).toContain('No series currently being watched'); + expect(fixture.nativeElement.textContent).toContain('No movies in your watch list'); setup({ watchItems: [createItem({ id: '2', title: 'M', type: 'movie' })] }); fixture = TestBed.createComponent(HomeComponent); fixture.detectChanges(); - expect((fixture.componentInstance as unknown as { hasMovies: () => boolean }).hasMovies()).toBe( - true, - ); - - setup({ watchItems: [] }); - fixture = TestBed.createComponent(HomeComponent); - fixture.detectChanges(); - expect((fixture.componentInstance as unknown as { hasSeries: () => boolean }).hasSeries()).toBe( - false, - ); + expect(fixture.nativeElement.textContent).toContain('No movies currently being watched'); + expect(fixture.nativeElement.textContent).toContain('No series in your watch list'); }); }); diff --git a/src/app/components/home/home.component.ts b/src/app/components/home/home.component.ts index f879b244..7896aa49 100644 --- a/src/app/components/home/home.component.ts +++ b/src/app/components/home/home.component.ts @@ -4,7 +4,7 @@ import { RouterLink } from '@angular/router'; import { RoundRobinService } from '../../services/round-robin.service'; import { WatchListService } from '../../services/watch-list.service'; import { ItemCardComponent } from '../item-card/item-card.component'; -import { ReadonlyItem as Item, ItemType } from '../../models/item.model'; +import { ReadonlyItem as Item, ItemStatus } from '../../models/item.model'; import { isEpisodicType } from '../../domain/item.constants'; import { ProviderSettingsService } from '../../services/provider-settings.service'; import { watchActionFailure } from '../watch-action-feedback'; @@ -53,9 +53,9 @@ import { DiscussionLinkComponent } from '../discussion-link/discussion-link.comp > Next Series - @if (nextSeries()) { + @if (nextSeries(); as series) {
- +