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
29 changes: 19 additions & 10 deletions app/frontend/src/pages/DiscoverPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const sections: Array<{ id: Exclude<CatalogSection, 'search'>; label: string }>

const filterKeys = ['genre', 'year', 'status', 'sort', 'source'] as const;

function statusOptions(category: DiscoverCategory, section: CatalogSection) {
function statusOptions(category: DiscoverCategory, section: CatalogSection, source: string) {
if ((category === 'tv' || category === 'anime') && section !== 'search') {
return [
['returning', 'Returning'],
Expand All @@ -39,7 +39,7 @@ function statusOptions(category: DiscoverCategory, section: CatalogSection) {
['pilot', 'Pilot'],
];
}
if (category === 'manga' || category === 'manhwa') {
if ((category === 'manga' || category === 'manhwa') && source === 'mangadex') {
return [
['ongoing', 'Ongoing'],
['completed', 'Completed'],
Expand All @@ -50,12 +50,18 @@ function statusOptions(category: DiscoverCategory, section: CatalogSection) {
return [];
}

function sortOptions(category: DiscoverCategory, section: CatalogSection) {
function sortOptions(category: DiscoverCategory, section: CatalogSection, source: string) {
if (category === 'manga' || category === 'manhwa') {
return [
['followedCount', 'Most followed'],
['latestUploadedChapter', 'Latest update'],
];
return source === 'mangadex'
? [
['followedCount', 'Most followed'],
['latestUploadedChapter', 'Latest update'],
]
: [
['list_reading', 'Most read'],
['month1_pos', 'Trending'],
['rating', 'Rating'],
];
}
const newest = category === 'movie' ? 'primary_release_date.desc' : 'first_air_date.desc';
return [
Expand Down Expand Up @@ -124,7 +130,7 @@ export function DiscoverPage({
attributionUrl: results.data.attributionUrl,
},
);
const statuses = statusOptions(category, section);
const statuses = statusOptions(category, section, source);
const activeFilters = filterKeys.filter((key) => searchParams.get(key)).length;
const hasFilters = activeFilters > 0;

Expand All @@ -133,9 +139,12 @@ export function DiscoverPage({
const form = new FormData(event.currentTarget);
const next = new URLSearchParams();
if (section === 'search') next.set('q', query);
const sourceChanged = form.has('source') && form.get('source') !== source;
for (const key of filterKeys) {
const value = String(form.get(key) ?? '').trim();
if (value) next.set(key, value);
if (value && !(sourceChanged && ['genre', 'status', 'sort'].includes(key))) {
next.set(key, value);
}
}
navigate(`/discover/${category}/${section}?${next.toString()}`);
}
Expand Down Expand Up @@ -279,7 +288,7 @@ export function DiscoverPage({
Sort
<select defaultValue={searchParams.get('sort') ?? ''} name="sort">
<option value="">{section === 'search' ? 'Relevance' : 'Default'}</option>
{sortOptions(category, section).map(([value, label]) => (
{sortOptions(category, section, source).map(([value, label]) => (
<option key={value} value={value}>{label}</option>
))}
</select>
Expand Down
2 changes: 1 addition & 1 deletion app/frontend/src/pages/HomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function HomePage() {
aria-label="Title"
name="query"
onInput={form.field('query').onInput}
placeholder="Search every medium, or paste a TMDB, MangaDex, IGDB or RAWG link"
placeholder="Search every medium, or paste a TMDB, MangaUpdates, MangaDex, IGDB or RAWG link"
type="search"
/>
<button className="primary-button" disabled={search.opening} type="submit">
Expand Down
17 changes: 13 additions & 4 deletions app/frontend/src/pages/LegalPages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ export function PrivacyPage() {
<section>
<h2>Other services</h2>
<p>
The server looks titles up at TMDB, MangaDex, IGDB and RAWG without sending anything about
you. Posters and artwork load straight from those services, so they see your browser's
request like any other image on the web. There are no ads, analytics or tracking cookies.
The server looks titles up at TMDB, MangaUpdates, MangaDex, IGDB and RAWG without sending
anything about you. Posters and artwork load straight from those services, so they see
your browser's request like any other image on the web. There are no ads, analytics or
tracking cookies.
</p>
</section>
<section>
Expand Down Expand Up @@ -147,10 +148,18 @@ export function CreditsPage() {
not endorsed or certified by TMDB.
</p>
</section>
<section>
<h2>MangaUpdates</h2>
<p>
Manga and manhwa data, covers and chapter updates are provided by{' '}
<External href="https://www.mangaupdates.com/">MangaUpdates</External>. Graphite Tracker
is not affiliated with MangaUpdates.
</p>
</section>
<section>
<h2>MangaDex</h2>
<p>
Manga and manhwa data and covers are provided by{' '}
When you choose MangaDex as a source, manga and manhwa data and covers are provided by{' '}
<External href="https://mangadex.org/">MangaDex</External>. Graphite Tracker is not
affiliated with MangaDex. It links to MangaDex titles and never hosts chapters or offers a
reader.
Expand Down
2 changes: 1 addition & 1 deletion app/frontend/src/pages/SearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export function SearchPage() {
defaultValue={query}
name="query"
onInput={form.field('query').onInput}
placeholder="Search every medium, or paste a TMDB, MangaDex, IGDB or RAWG link"
placeholder="Search every medium, or paste a TMDB, MangaUpdates, MangaDex, IGDB or RAWG link"
type="search"
/>
<button className="primary-button" disabled={search.opening} type="submit">
Expand Down
90 changes: 90 additions & 0 deletions app/frontend/test/discover.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { act } from 'react';
import { createRoot, type Root } from 'react-dom/client';
import { MemoryRouter } from 'react-router';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { App } from '../src/App';
import { AuthProvider } from '../src/auth';

(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;

const json = (body: unknown) =>
new Response(JSON.stringify(body), { status: 200, headers: { 'Content-Type': 'application/json' } });

const mangaSource = (key: string, displayName: string) => ({
key,
displayName,
categories: ['manga', 'manhwa'],
attribution: displayName,
enabled: true,
});

describe('Discover filters', () => {
let container: HTMLDivElement;
let root: Root;

beforeEach(() => {
container = document.createElement('div');
document.body.append(container);
root = createRoot(container);
});

afterEach(() => {
act(() => root.unmount());
container.remove();
vi.unstubAllGlobals();
});

it('offers the sorts and statuses of the manga source in use and drops them when the source changes', async () => {
const fetchMock = vi.fn((input: string) => {
const url = String(input);
if (url.includes('/catalog/sources')) {
return Promise.resolve(
json([mangaSource('mangaupdates', 'MangaUpdates'), mangaSource('mangadex', 'MangaDex')]),
);
}
if (url.includes('/genres')) return Promise.resolve(json(['Romance']));
if (url.includes('/catalog/')) {
return Promise.resolve(
json({ page: 1, totalPages: 1, totalResults: 0, results: [], attribution: 'Test' }),
);
}
return Promise.resolve(new Response(null, { status: 401 }));
});
vi.stubGlobal('fetch', fetchMock);
const browses = () =>
fetchMock.mock.calls
.map(([url]) => String(url))
.filter((url) => url.includes('/catalog/manga/popular'));
const sorts = () =>
[...container.querySelectorAll<HTMLOptionElement>('select[name="sort"] option')].map(
({ value }) => value,
);

await act(async () =>
root.render(
<MemoryRouter initialEntries={['/discover/manga/popular?genre=Romance&year=2020&sort=list_reading']}>
<AuthProvider>
<App />
</AuthProvider>
</MemoryRouter>,
),
);

expect(browses()).toEqual([
'/api/v1/catalog/manga/popular?page=1&genre=Romance&year=2020&sort=list_reading',
]);
expect(sorts()).toEqual(['', 'list_reading', 'month1_pos', 'rating']);
expect(container.querySelector('select[name="status"]')).toBeNull();

const form = container.querySelector<HTMLFormElement>('#discover-filters');
form!.querySelector<HTMLSelectElement>('select[name="source"]')!.value = 'mangadex';
await act(async () => {
form!.dispatchEvent(new Event('submit', { bubbles: true, cancelable: true }));
await new Promise((resolve) => setTimeout(resolve, 30));
});

expect(browses().at(-1)).toBe('/api/v1/catalog/manga/popular?page=1&year=2020&source=mangadex');
expect(sorts()).toEqual(['', 'followedCount', 'latestUploadedChapter']);
expect(container.querySelector('select[name="status"]')).not.toBeNull();
});
});
4 changes: 3 additions & 1 deletion app/server/src/sources/connector-registry.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { withoutAdult } from './adult-content';
import { ConnectorCacheService } from './connector-cache.service';
import { IgdbService } from './igdb/igdb.service';
import { MangaDexService } from './mangadex/mangadex.service';
import { MangaUpdatesService } from './mangaupdates/mangaupdates.service';
import { RawgService } from './rawg/rawg.service';
import {
CatalogCategory,
Expand All @@ -21,6 +22,7 @@ export class ConnectorRegistryService {
constructor(
config: ConfigService,
tmdb: TmdbService,
mangaUpdates: MangaUpdatesService,
mangadex: MangaDexService,
igdb: IgdbService,
rawg: RawgService,
Expand All @@ -36,7 +38,7 @@ export class ConnectorRegistryService {
gameSource === 'igdb' && igdb.descriptor.enabled;
rawg.descriptor.enabled =
gameSource === 'rawg' && rawg.descriptor.enabled;
this.connectors = [tmdb, mangadex, igdb, rawg];
this.connectors = [tmdb, mangaUpdates, mangadex, igdb, rawg];
const disabled = new Set(
(config.get<string>('DISABLED_SOURCES') ?? '')
.split(',')
Expand Down
Loading
Loading