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
4 changes: 2 additions & 2 deletions src/works/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
getChapterName,
getChapterSummary,
getWorkAdditionalTags,
getWorkAdult,
getWorkAuthors,
getWorkBookmarkCount,
getWorkCategory,
Expand Down Expand Up @@ -66,8 +67,7 @@ export const getWork = async ({
language: getWorkLanguage(workPage),
rating: getWorkRating(workPage),
category: getWorkCategory(workPage),
// TODO: figure out how to get this
adult: false,
adult: getWorkAdult(workPage),
fandoms: getWorkFandoms(workPage),
tags: {
warnings: getWorkWarnings(workPage),
Expand Down
5 changes: 5 additions & 0 deletions src/works/work-getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ export const getWorkLocked = ($workPage: WorkPage) => {
return !!$workPage("#signin > .heading").text();
};

export const getWorkAdult = ($workPage: WorkPage): boolean => {
const adultCategories: WorkRatings[] = [WorkRatings.EXPLICIT, WorkRatings.MATURE, WorkRatings.NOT_RATED];

Choose a reason for hiding this comment

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

since this is a constant, we should define it outside this function like this:

const ADULT_CATEGORIES: WorkRatings[] = [WorkRatings.EXPLICIT, WorkRatings.MATURE, WorkRatings.NOT_RATED];
export const getWorkAdult = ($workPage: WorkPage): boolean => {
// rest of the code

see https://google.github.io/styleguide/tsguide.html#identifiers-constants (but it's a common convention)

Choose a reason for hiding this comment

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

Also, I just found out about this: https://mkosir.github.io/typescript-style-guide/#type-safe-constants-with-satisfies

Apparently the best way of declaring this constant would be:

const ADULT_CATEGORIES = [
  WorkRatings.EXPLICIT, 
  WorkRatings.MATURE, 
  WorkRatings.NOT_RATED
] as const satisfies ReadonlyArray<WorkRatings>;

this would give the most correct typing (feel free to ask if you want to understand more).

I'd be ok with keeping it const ADULT_CATEGORIES: WorkRatings[], but since you're changing it let's try the new one?

return adultCategories.includes(getWorkRating($workPage));
}

// Chapter-specific (must be multi-chapter fic)
export const getChapterIndex = (
$workPage: WorkPage
Expand Down
2 changes: 1 addition & 1 deletion tests/work-chapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe("Fetches chapter of work", () => {
language: "English",
rating: "Not Rated",
category: null,
adult: false,
adult: true,
fandoms: ["Batman - All Media Types"],
tags: {
warnings: ["Creator Chose Not To Use Archive Warnings"],
Expand Down