Skip to content

Commit 1e67be5

Browse files
committed
improved readability replacing foreach with map
1 parent 4332a16 commit 1e67be5

File tree

2 files changed

+215
-289
lines changed

2 files changed

+215
-289
lines changed

src/generic/main.ts

Lines changed: 2 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -357,92 +357,10 @@ export abstract class MangaWorldGeneric
357357
);
358358
}
359359
case "genre_section": {
360-
await filter.populateFilter(this);
361-
const allGenres: DiscoverSectionItem[] = [];
362-
filter
363-
.getGenreFilter()
364-
.filter((option) => !tags.blacklistedTags([option.id]))
365-
.forEach((filterItem) => {
366-
const getExcludedValueObject = {
367-
...Object.fromEntries(
368-
filter
369-
.getGenreFilter()
370-
.filter((option) =>
371-
tags.blacklistedTags([option.id]),
372-
)
373-
.map((item) => [
374-
item.id,
375-
"excluded" as const,
376-
]),
377-
),
378-
[filterItem.id]: "included" as const,
379-
} as Record<string, "included" | "excluded">;
380-
allGenres.push({
381-
type: "genresCarouselItem",
382-
searchQuery: {
383-
title: "",
384-
filters: [
385-
{
386-
id: "genres",
387-
value: getExcludedValueObject,
388-
},
389-
],
390-
},
391-
name: filterItem.value,
392-
metadata: metadata,
393-
contentRating:
394-
this.defaultContentRating ===
395-
ContentRating.ADULT
396-
? ContentRating.ADULT
397-
: tags.getRating([filterItem.value]),
398-
});
399-
});
400-
return {
401-
items: allGenres,
402-
metadata: metadata,
403-
};
360+
return this.parser.parseGenreSection(this, metadata);
404361
}
405362
case "type_section": {
406-
await filter.populateFilter(this);
407-
const mangaType: DiscoverSectionItem[] = [];
408-
filter
409-
.getMangaTypeFilter()
410-
.filter((option) => !types.blacklistedType(option.value))
411-
.forEach((filterItem) => {
412-
const getExcludedTypeObject = {
413-
...Object.fromEntries(
414-
filter
415-
.getMangaTypeFilter()
416-
.filter((option) =>
417-
types.blacklistedType(option.value),
418-
)
419-
.map((item) => [
420-
item.id,
421-
"excluded" as const,
422-
]),
423-
),
424-
[filterItem.id]: "included" as const,
425-
} as Record<string, "included" | "excluded">;
426-
mangaType.push({
427-
type: "genresCarouselItem",
428-
searchQuery: {
429-
title: "",
430-
filters: [
431-
{
432-
id: "types",
433-
value: getExcludedTypeObject,
434-
},
435-
],
436-
},
437-
name: filterItem.value,
438-
metadata: metadata,
439-
contentRating: ContentRating.EVERYONE,
440-
});
441-
});
442-
return {
443-
items: mangaType,
444-
metadata: metadata,
445-
};
363+
return this.parser.parseTypeSection(this, metadata);
446364
}
447365
default:
448366
return { items: [], metadata: metadata };

0 commit comments

Comments
 (0)