Skip to content

Commit

Permalink
feat: app filter fansub and publisher
Browse files Browse the repository at this point in the history
  • Loading branch information
yjl9903 committed Apr 9, 2023
1 parent 433d19e commit 2c377d8
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 12 deletions.
11 changes: 2 additions & 9 deletions packages/app/src/components/ResourceTable.astro
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,7 @@ const DisplayTypeColor: Record<ResourceType, string> = {
<td class="py2 pl2">
<div class="flex items-center justify-start">
{r.fansub && (
<a
href={`https://share.dmhy.org/topics/list/team_id/${r.fansub.id}`}
target="_blank"
class="block"
>
<a href={`/fansub/${r.fansub.id}/1`} class="block">
<Tag text={r.fansub.name} className={`text-xs mr2 hover:bg-gray-300`} />
</a>
)}
Expand All @@ -93,10 +89,7 @@ const DisplayTypeColor: Record<ResourceType, string> = {
</div>
</td>
<td class="py2 pl2 text-center">
<a
href={`https://share.dmhy.org/topics/list/user_id/${r.publisher.id}`}
target="_blank"
>
<a href={`/publisher/${r.publisher.id}/1`}>
<Tag text={r.publisher.name} className={`text-xs mr2 hover:bg-gray-300`} />
</a>
</td>
Expand Down
14 changes: 12 additions & 2 deletions packages/app/src/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@ import type { Resource } from 'animegarden';

import { WORKER_BASE } from './constant';

export async function fetchResources(page: number) {
const resources = await fetch(new URL(`/resources?page=${page}`, 'https://' + WORKER_BASE))
export async function fetchResources(
page: number,
options: { fansub?: number; publisher?: number } = {}
) {
const url = new URL(`/resources?page=${page}`, 'https://' + WORKER_BASE);
if (options.fansub) {
url.searchParams.set('fansub', '' + options.fansub);
}
if (options.publisher) {
url.searchParams.set('publisher', '' + options.publisher);
}
const resources = await fetch(url, {})
.then((r) => r.json())
.then((r: any) => r.resources as Resource[]);
return resources;
Expand Down
22 changes: 22 additions & 0 deletions packages/app/src/pages/fansub/[fansub]/[page].astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
import Layout from '../../../layouts/Layout.astro';
import ResourceTable from '../../../components/ResourceTable.astro';
import Pagination from '../../../components/Pagination.astro';
import { fetchResources } from '../../../fetch';
const { page: _page, fansub } = Astro.params;
const page = _page ? +_page : 1;
if (!fansub) {
return Astro.redirect('/');
}
const resources = await fetchResources(page, { fansub: +fansub });
---

<Layout title="Anime Garden">
<div class="mt-8vh">
<ResourceTable resources={resources} />
<Pagination page={page} prefix={`/fansub/${fansub}/`} />
</div>
</Layout>
22 changes: 22 additions & 0 deletions packages/app/src/pages/publisher/[publisher]/[page].astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
import Layout from '../../../layouts/Layout.astro';
import ResourceTable from '../../../components/ResourceTable.astro';
import Pagination from '../../../components/Pagination.astro';
import { fetchResources } from '../../../fetch';
const { page: _page, publisher } = Astro.params;
const page = _page ? +_page : 1;
if (!publisher) {
return Astro.redirect('/');
}
const resources = await fetchResources(page, { publisher: +publisher });
---

<Layout title="Anime Garden">
<div class="mt-8vh">
<ResourceTable resources={resources} />
<Pagination page={page} prefix={`/publisher/${publisher}/`} />
</div>
</Layout>
1 change: 0 additions & 1 deletion packages/app/src/pages/resources/[page].astro
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import ResourceTable from '../../components/ResourceTable.astro';
import { fetchResources } from '../../fetch';
const { page: _page } = Astro.params;
const page = _page ? +_page : 1;
const resources = await fetchResources(page);
---
Expand Down

0 comments on commit 2c377d8

Please sign in to comment.