Skip to content

Commit

Permalink
feat: main page featured levels display
Browse files Browse the repository at this point in the history
  • Loading branch information
paring-chan committed Jan 18, 2025
1 parent 7e9454c commit 264ccc4
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 127 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
],
"devDependencies": {
"@adofai-gg/query-types": "1.0.0-alpha.3",
"@adofai-gg/ui": "1.2.0-beta.59",
"@adofai-gg/ui": "1.2.0-beta.81",
"@commitlint/cli": "^19.6.1",
"@commitlint/config-conventional": "^19.6.0",
"@fluent/bundle": "^0.18.0",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
<script lang="ts">
import { Container, SearchBar, Logo, type SearchOptionsData } from '@adofai-gg/ui'
import { Container, SearchBar, Logo } from '@adofai-gg/ui'
import MainSection from '$lib/components/main/MainSection.svelte'
import { goto } from '$app/navigation'
import type { PageData } from './$types'
import LevelListItem from '~/lib/components/levelList/LevelListItem.svelte'
interface Props {
data: PageData
}
const { data }: Props = $props()
let searchQuery = $state('')
Expand All @@ -26,7 +34,11 @@
</div>
</div>

<MainSection title="main:recent-featured-levels">wow</MainSection>
<MainSection title="main:recent-featured-levels">
{#each data.featured.results as level}
<LevelListItem {level} />
{/each}
</MainSection>
</Container>
</main>

Expand Down
35 changes: 35 additions & 0 deletions src/routes/+page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { api, type APILevel } from '~/lib'
import type { PageLoad } from './$types'
import type { SearchQuery } from '@adofai-gg/query-types'
import type { ListResponse } from '~/types'
import { error } from '@sveltejs/kit'

export const load: PageLoad = async ({ fetch }) => {
const featuredRes = await fetch(api.forum('levels/search'), {
body: JSON.stringify({
skip: 0,
take: 5,
query: {
sort: [
// {
// direction: 'desc',
// objective: 'recent'
// }
],
filter: {
op: 'eq',
key: 'quality',
value: 'FEATURED'
}
} satisfies SearchQuery
}),
method: 'POST',
headers: { 'Content-Type': 'application/json' }
})

if (!featuredRes.ok) return error(500, 'failed to fetch featured levels')

const featured = (await featuredRes.json()) as ListResponse<APILevel>

return { featured }
}
2 changes: 0 additions & 2 deletions src/routes/levels/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
const fetchLevels = async (skip: number, take: number, query: SearchQuery) => {
const url = new URL(api.forum('levels/search'))
// url.searchParams.set('offset', `${offset}`)
// url.searchParams.set('limit', `${limit}`)
const res = await fetch(url, {
method: 'POST',
Expand Down
117 changes: 0 additions & 117 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,125 +1,8 @@
export interface PlayLog {
accept: boolean
description: string
id: number
level: { id: number; name: string }
playPoint: number
player: { id: number; name: string }
speed: number
timestamp: string
url: string
xAccuracy: number
}

export type PlayLogWithLevel = PlayLog & {
level: Level
}

export interface Ranking {
id: number
name: string
totalPp: number
bestPlay: PlayLog | null
}

export interface PartialMember {
id: number
name: string
}

export interface Member extends PartialMember {
totalPp: number
}

export interface PartialMusic {
id: number
name: string

minBpm: number
maxBpm: number

artists: PartialMember[]
}

export interface Music extends PartialMusic {
createdLevelAmount: number
}

export interface Level {
id: number
title: string
difficulty: number
creators: PartialMember[]
music: PartialMusic
tiles: number
video: string
censored: boolean

download: string
workshop: string | null

tags: Tag[]

epilepsyWarning: boolean

// and more(not added)
}

export interface Tag {
id: number
name: string
}

export interface ListResponse<T> {
results: T[]
count: number
}

export interface DifficultyReference {
difficulty: number
ppRating: number
levels: (DifficultyReferenceLevel | null)[]
}

export type DifficultyReferenceLevel =
| DifficultyReferenceLevelForum
| DifficultyReferenceLevelOfficial

export interface DifficultyReferenceLevelForum {
levelId: number
name: string
url: null
}

export interface DifficultyReferenceLevelOfficial {
levelId: null
name: string
url: string
}

export interface RawDifficultyReference {
difficulty: number
easiestLevel: boolean
position: number
level: DifficultyReferenceLevel
}

export interface RawPPRatings {
difficulty: number
rating: number
}

export enum SyncStatus {
Ok = 'ok',
Err = 'error'
}

export interface SyncStatusResponse {
status: SyncStatus
lastSucceedAt: string
exception: string | null
}

declare global {
interface Window {
gtag?: (...args: unknown[]) => void
Expand Down

0 comments on commit 264ccc4

Please sign in to comment.