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
14 changes: 6 additions & 8 deletions scripts/build.mjs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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);

Expand Down
1 change: 0 additions & 1 deletion src/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
33 changes: 7 additions & 26 deletions src/app/components/add-item/add-item.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<ItemFormValue> } | null>(null);
readonly autofillPatch = signal<ItemFormAutofillPatch | null>(null);
private autofillPatchId = 0;
readonly duplicateTitleHint = computed(() => {
const normalizedTitle = this.normalizeTitle(this.title());
Expand All @@ -99,26 +99,15 @@ 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) => {
if (!details) {
return;
}

this.autofillPatch.set({
id: ++this.autofillPatchId,
value: {
seasons: details.seasons,
},
});
this.autofillPatch.set({ id: ++this.autofillPatchId, value: { seasons: details.seasons } });
});
}

Expand All @@ -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<void> {
Expand Down
26 changes: 6 additions & 20 deletions src/app/components/home/home.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof vi.fn>;
markCompleted: ReturnType<typeof vi.fn>;
markDropped: ReturnType<typeof vi.fn>;
markPaused: ReturnType<typeof vi.fn>;
};
const svc = TestBed.inject(WatchListService);
const item = createItem({ id: 'x', title: 'X', status: 'in-progress', isAdult: false });

await fixture.componentInstance.markItem(() => item, 'watched');
Expand Down Expand Up @@ -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');
});
});
41 changes: 17 additions & 24 deletions src/app/components/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -53,9 +53,9 @@ import { DiscussionLinkComponent } from '../discussion-link/discussion-link.comp
>
Next Series
</h2>
@if (nextSeries()) {
@if (nextSeries(); as series) {
<div class="w-full">
<app-item-card [item]="nextSeries()!" />
<app-item-card [item]="series" />
<div class="flex flex-wrap justify-center gap-2 mt-3">
<button
(click)="markItem(nextSeries, 'watched')"
Expand Down Expand Up @@ -155,9 +155,9 @@ import { DiscussionLinkComponent } from '../discussion-link/discussion-link.comp
>
Next Movie
</h2>
@if (nextMovie()) {
@if (nextMovie(); as movie) {
<div class="w-full">
<app-item-card [item]="nextMovie()!" />
<app-item-card [item]="movie" />
<div class="flex flex-wrap justify-center gap-2 mt-3">
<button
(click)="markItem(nextMovie, 'watched')"
Expand Down Expand Up @@ -364,28 +364,17 @@ export class HomeComponent {
);
if (result) this.deferringItem.set(null);
}
backlogItems = computed(() => {
const adultMode = this.providerSettings.settings().adultDisplayMode;
let items = this.watchListService.items().filter((item) => item.status === 'not-started');
if (adultMode === 'hide') {
items = items.filter((item) => !item.isAdult);
}
return items.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime());
});

pausedItems = computed(() => {
const adultMode = this.providerSettings.settings().adultDisplayMode;
let items = this.watchListService.items().filter((item) => item.status === 'paused');
if (adultMode === 'hide') {
items = items.filter((item) => !item.isAdult);
}
return items.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime());
});
backlogItems = computed(() => this.visibleNewestFirst('not-started'));

pausedItems = computed(() => this.visibleNewestFirst('paused'));

protected hasSeries = computed(() =>
this.watchListService.items().some((item) => isEpisodicType(item.type)),
);
protected hasMovies = computed(() => this.hasItemType('movie'));
protected hasMovies = computed(() =>
this.watchListService.items().some((item) => item.type === 'movie'),
);
protected hasInProgressSeries = computed(
() => this.watchListService.inProgressSeries().length > 0,
);
Expand Down Expand Up @@ -426,7 +415,11 @@ export class HomeComponent {
return this.dropBacklogItem(itemId);
}

private hasItemType(type: ItemType): boolean {
return this.watchListService.items().some((item) => item.type === type);
private visibleNewestFirst(status: ItemStatus) {
const hideAdult = this.providerSettings.settings().adultDisplayMode === 'hide';
return this.watchListService
.items()
.filter((item) => item.status === status && !(hideAdult && item.isAdult))
.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime());
}
}
15 changes: 5 additions & 10 deletions src/app/components/item-card/item-card.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Component, input, computed, inject, linkedSignal } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterLink } from '@angular/router';
import { ReadonlyItem as Item } from '../../models/item.model';
import { TimeAgoComponent } from '../time-ago/time-ago.component';
Expand All @@ -11,7 +10,7 @@ import { ProviderSettingsService } from '../../services/provider-settings.servic

@Component({
selector: 'app-item-card',
imports: [CommonModule, RouterLink, TimeAgoComponent],
imports: [RouterLink, TimeAgoComponent],
template: `
<div
class="border border-light-border dark:border-dark-border rounded-lg bg-light-bg-secondary dark:bg-dark-bg-secondary shadow-light dark:shadow-dark overflow-hidden"
Expand Down Expand Up @@ -44,11 +43,11 @@ import { ProviderSettingsService } from '../../services/provider-settings.servic
Adult — click to reveal
</button>
}
@if (item().progress) {
@if (item().progress; as progress) {
<span
class="absolute top-0 right-0 px-2 py-1 text-xs font-medium bg-black/60 text-white backdrop-blur-sm"
>
S{{ item().progress!.season }}E{{ item().progress!.episode }}
S{{ progress.season }}E{{ progress.episode }}
</span>
}
</div>
Expand Down Expand Up @@ -89,11 +88,7 @@ export class ItemCardComponent {
return this.item().isAdult && concealsAdultPosters && !!this.posterUrl() && !this.revealed();
});

progressPercent = computed(() => {
return calculateProgress(this.item());
});
progressPercent = computed(() => calculateProgress(this.item()));

lastWatchedDate = computed(() => {
return getMostRecentWatchDate(this.item());
});
lastWatchedDate = computed(() => getMostRecentWatchDate(this.item()));
}
13 changes: 6 additions & 7 deletions src/app/components/item-detail/item-detail.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,11 @@ export class ItemDetailComponent {

async deleteItem(): Promise<void> {
const currentItem = this.itemSnapshot();
if (currentItem) {
const result = await this.mutation.run(
() => this.watchListService.deleteItem(currentItem.id),
'Unable to delete this item.',
);
if (result) this.router.navigate(['/items']);
}
if (!currentItem) return;
const result = await this.mutation.run(
() => this.watchListService.deleteItem(currentItem.id),
'Unable to delete this item.',
);
if (result) this.router.navigate(['/items']);
}
}
Loading