Skip to content
Open
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Paperback extensions for websites with unique, non-generic themes.
- [MangaPlus](https://mangaplus.shueisha.co.jp)
- [MangaTaro](https://mangataro.org)
- [Mgeko](https://mgeko.cc)
- [NovelArchive](https://novelarchive.cc)
- [PunkRecords](https://punkrecordz.com)
- [Roliascan](https://roliascan.com)
- [RoyalRoad](https://www.royalroad.com)
Expand Down
89 changes: 89 additions & 0 deletions src/NovelArchive/forms/search.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/* SPDX-License-Identifier: GPL-3.0-or-later */
/* Copyright © 2026 Inkdex */

import {
AdvancedSearchForm,
Section,
SelectRow,
SelectSection,
TriStateSelectRow,
type SearchQuery,
type Tag,
} from "@paperback/types";

import { GENRE_MATCH_OPTIONS, STATUS_OPTIONS, type SearchMetadata, type TriState } from "../models";

export class NovelArchiveAdvancedSearchForm extends AdvancedSearchForm {
private status: string[];
private genreMatch: string[];
private genres: TriState;

private readonly genreOptions: Tag[];

constructor(searchQuery: SearchQuery<SearchMetadata>, genres: Tag[]) {
super();
const metadata = searchQuery.metadata ?? {};
this.status = metadata.status ?? [];
this.genreMatch = metadata.genreMatch ?? ["all"];
this.genres = { ...metadata.genres };
this.genreOptions = genres;
}

override getSections() {
return [
Section("status", [
SelectRow("status", {
title: "Status",
layout: "flow",
value: this.status,
items: STATUS_OPTIONS,
minItemCount: 0,
maxItemCount: 1,
onValueChange: Application.Selector(
this as NovelArchiveAdvancedSearchForm,
"handleStatusChange",
),
}),
]),
Section({ id: "genres", footer: "Tap once to include, twice to exclude." }, [
TriStateSelectRow("genres", {
title: "Genres",
layout: "flow",
value: this.genres,
items: this.genreOptions,
allowExclusion: true,
allowEmptySelection: true,
onValueChange: Application.Selector(
this as NovelArchiveAdvancedSearchForm,
"handleGenresChange",
),
}),
]),
SelectSection(this, {
id: "genre_match",
header: "Genre match",
layout: "flow",
value: this.genreMatch,
items: GENRE_MATCH_OPTIONS,
minItemCount: 1,
maxItemCount: 1,
}),
];
}

async handleStatusChange(value: string[]): Promise<void> {
this.status = value;
}

async handleGenresChange(value: TriState): Promise<void> {
this.genres = value;
}

override getSearchQueryMetadata(): SearchMetadata {
const result: SearchMetadata = {};
if (this.status.length > 0) result.status = this.status;
if (this.genreMatch.length > 0) result.genreMatch = this.genreMatch;
if (Object.keys(this.genres).length > 0) result.genres = this.genres;
return result;
}
}
66 changes: 66 additions & 0 deletions src/NovelArchive/forms/settings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/* SPDX-License-Identifier: GPL-3.0-or-later */
/* Copyright © 2026 Inkdex */

import { Form, Section, ToggleRow, TriStateSelectRow, type Tag } from "@paperback/types";

import { STATE_KEYS, type TriState } from "../models";

export class NovelArchiveSettingsForm extends Form {
// Adult titles remain visible unless the user opts to hide them.
private hideAdultContent =
(Application.getState(STATE_KEYS.HIDE_ADULT) as boolean | undefined) ?? false;
private genres = (Application.getState(STATE_KEYS.DEFAULT_GENRES) as TriState | undefined) ?? {};

private readonly genreOptions: Tag[];

constructor(genres: Tag[]) {
super();
this.genreOptions = genres;
}

override getSections() {
return [
Section(
{
id: "browse",
header: "Browse Settings",
footer: "Default genres apply to paginated browse sections and search.",
},
[
ToggleRow("hide_adult", {
title: "Hide adult content",
value: this.hideAdultContent,
onValueChange: Application.Selector(
this as NovelArchiveSettingsForm,
"handleHideAdultChange",
),
}),
TriStateSelectRow("genres", {
title: "Default genres",
layout: "flow",
value: this.genres,
items: this.genreOptions,
allowExclusion: true,
allowEmptySelection: true,
onValueChange: Application.Selector(
this as NovelArchiveSettingsForm,
"handleGenresChange",
),
}),
],
),
];
}

async handleHideAdultChange(value: boolean): Promise<void> {
this.hideAdultContent = value;
Application.setState(value, STATE_KEYS.HIDE_ADULT);
Application.invalidateDiscoverSections();
}

async handleGenresChange(value: TriState): Promise<void> {
this.genres = value;
Application.setState(value, STATE_KEYS.DEFAULT_GENRES);
Application.invalidateDiscoverSections();
}
}
Loading