Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort sponsors by name asc #94

Merged
merged 1 commit into from
Jan 10, 2024
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
9 changes: 7 additions & 2 deletions lib/db/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item[]> {
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<Item[]> {
return (await getItems()).filter((item) => item.sponsor)
}

export async function getItem(_id: string): Promise<Item | null> {
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] })
}
Expand Down
12 changes: 10 additions & 2 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import ViewAllButton from '../components/buttons/ViewAllButton'
import { Item } from '../types/Item'
import LibraryBoard from '../components/boards/LibraryBoard'
import { getSponsors } from '../lib/db/items'

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused import getSponsors.

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.'
Expand Down Expand Up @@ -44,7 +45,6 @@
canEdit={true}
/>


<div className={'row'}>
<div className={'col'}>
<h2 className={'mb-0'}>
Expand Down Expand Up @@ -111,7 +111,14 @@

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) => {
Expand All @@ -138,6 +145,7 @@
sponsorsSortedByPopular.reverse().forEach((sponsor) => {
popular.unshift(sponsor)
})
*/

return {
props: {
Expand Down
Loading