Skip to content

Commit

Permalink
Browse games view
Browse files Browse the repository at this point in the history
Fixes #61
  • Loading branch information
andrew-codes committed Jan 1, 2024
1 parent 988a7d2 commit 0ecd91c
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions apps/playnite-web/src/routes/browse.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import type { LoaderFunctionArgs } from '@remix-run/node'
import { json } from '@remix-run/node'
import { useLoaderData } from '@remix-run/react'
import useDimensions from 'react-use-dimensions'
import { styled } from 'styled-components'
import PlayniteApi from '../api'
import { Game } from '../api/types'
import GameList from '../components/GameList.js'

async function loader({ request }: LoaderFunctionArgs) {
const api = new PlayniteApi()
const games = await api.getGames()
games.sort((a, b) => {
const aName = a.sortName
const bName = b.sortName
if (aName > bName) {
return 1
}
if (aName < bName) {
return -1
}

return 0
})

return json({
games,
})
}

const Main = styled.main``

function Index() {
const { games } = useLoaderData<typeof loader>() as unknown as {
games: Game[]
}

const [ref, { width }] = useDimensions()

return (
<Main ref={ref}>
<GameList width={width} columns={12} games={games} />
</Main>
)
}

export default Index
export { loader }

0 comments on commit 0ecd91c

Please sign in to comment.