diff --git a/lib/db/items.ts b/lib/db/items.ts index 0c089ef3..848149aa 100644 --- a/lib/db/items.ts +++ b/lib/db/items.ts @@ -22,18 +22,23 @@ import { List } from '../../types/List' import { updateList } from './lists' import { Collection } from '../../types/Collection' import { postItemUpdate } from '../webhook' +import { findOneTyped, getAllTyped } from './dbTyped' export async function getItems(): Promise { return await Promise.all( - ((await getAll('items')) as Item[]).map(async (i) => { + ((await getAllTyped(Types.item)) as Item[]).map(async (i) => { i.stars = await count('users', { favs: [i._id] }) return i }) ) } +export async function getSponsors(): Promise { + return (await getItems()).filter((item) => item.sponsor) +} + export async function getItem(_id: string): Promise { - const item = (await findOne('items', { _id: _id })) as Item + const item = (await findOneTyped(Types.item, _id)) as Item if (item !== null) { item.stars = await count('users', { favs: [_id] }) } diff --git a/pages/index.tsx b/pages/index.tsx index 5466a02b..fc48609f 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -9,6 +9,7 @@ import { Types } from '../types/Components' import ViewAllButton from '../components/buttons/ViewAllButton' import { Item } from '../types/Item' import LibraryBoard from '../components/boards/LibraryBoard' +import { getSponsors } from '../lib/db/items' const description = 'The best places to stream your favorite anime shows online or download them for free and watch in sub or dub. Supports manga, light novels, hentai, and apps.' @@ -44,7 +45,6 @@ export default function Home({ libraries, sponsors, columns }) { canEdit={true} /> -

@@ -111,7 +111,14 @@ export default function Home({ libraries, sponsors, columns }) { export async function getStaticProps() { const allItems = (await getAllCache(Types.item)) as Item[] - const sponsors = allItems.filter((item) => item.sponsor) + const sponsors = allItems + .filter((item) => item.sponsor) + .sort((a, b) => { + // asc name + return a.name < b.name ? -1 : 1 + }) + + /* let popular = (await getLastViews(Types.item, 10000)) as Item[] const sponsorsSortedByPopular = sponsors.sort((a, b) => { @@ -138,6 +145,7 @@ export async function getStaticProps() { sponsorsSortedByPopular.reverse().forEach((sponsor) => { popular.unshift(sponsor) }) + */ return { props: {