fix: multi-events

This commit is contained in:
2026-09-16 00:21:08 +02:00
parent 68de07645a
commit 85e67599af
4 changed files with 78 additions and 70 deletions
+39 -40
View File
@@ -1,5 +1,12 @@
import { defineStore } from 'pinia'
import { ref } from 'vue'
import {
noitaApiGetResults,
noitaApiGetLeaderboard,
noitaApiSubmitLogFile,
polylanSubmitterApiGetUserInfo,
polylanSubmitterApiClearCache,
} from '@/api'
import type { ObjectivResultOut, LeaderboardEntryOut } from '@/api/types.gen'
export type Objective = ObjectivResultOut
@@ -30,12 +37,12 @@ export const useNoitaStore = defineStore('noita', () => {
const error = ref<string>('')
// Actions
const fetchUserResults = async () => {
const fetchUserResults = async (eventPath: string) => {
try {
const response = await fetch('/api/noita/results')
if (!response.ok) throw new Error('Failed to fetch results')
const response = await noitaApiGetResults({ path: { event_path: eventPath } })
if (response.error || !response.data) throw new Error('Failed to fetch results')
const results = await response.json()
const results = response.data
userInfo.value.score = results.total_score
userInfo.value.deathsCount = results.deaths_count
userInfo.value.runsSubmitted = results.objectives.length
@@ -46,14 +53,13 @@ export const useNoitaStore = defineStore('noita', () => {
}
}
const fetchLeaderboard = async () => {
const fetchLeaderboard = async (eventPath: string) => {
isLoadingLeaderboard.value = true
try {
const response = await fetch('/api/noita/leaderboard')
if (!response.ok) throw new Error('Failed to fetch leaderboard')
const response = await noitaApiGetLeaderboard({ path: { event_path: eventPath } })
if (response.error || !response.data) throw new Error('Failed to fetch leaderboard')
const data = await response.json()
leaderboard.value = data.leaderboard
leaderboard.value = response.data.leaderboard
// Find current user's rank
const userRank = leaderboard.value.find(
@@ -73,48 +79,41 @@ export const useNoitaStore = defineStore('noita', () => {
}
}
const loadUserData = async () => {
const loadUserData = async (eventPath: string) => {
try {
const response = await fetch('/api/user')
if (response.ok) {
const user = await response.json()
if (user.is_authenticated) {
userInfo.value.username = user.username
userInfo.value.isStaff = user.is_staff || false
}
const response = await polylanSubmitterApiGetUserInfo()
if (response.data?.is_authenticated) {
userInfo.value.username = response.data.username ?? ''
userInfo.value.isStaff = response.data.is_staff || false
}
} catch (err) {
console.error('Error fetching user info:', err)
}
await Promise.all([fetchUserResults(), fetchLeaderboard()])
await Promise.all([fetchUserResults(eventPath), fetchLeaderboard(eventPath)])
}
const submitRun = async (files: File[]) => {
const submitRun = async (eventPath: string, files: File[]) => {
if (files.length === 0) return
isUploading.value = true
try {
for (const file of files) {
const formData = new FormData()
formData.append('file', file)
const response = await fetch('/api/noita/submit', {
method: 'POST',
body: formData,
const response = await noitaApiSubmitLogFile({
path: { event_path: eventPath },
body: { file },
})
if (!response.ok) {
const errorData = await response.json()
throw new Error(errorData.detail || 'Unknown error')
if (response.error) {
const detail = (response.error as { detail?: string })?.detail
throw new Error(detail || 'Unknown error')
}
const result = await response.json()
console.log('Submission successful:', result)
console.log('Submission successful:', response.data)
}
// Refresh objectives, score, and rank after successful submission
await Promise.all([fetchUserResults(), fetchLeaderboard()])
await Promise.all([fetchUserResults(eventPath), fetchLeaderboard(eventPath)])
} catch (err) {
const errorMessage = err instanceof Error ? err.message : 'Unknown error'
error.value = `Error submitting run: ${errorMessage}`
@@ -124,18 +123,18 @@ export const useNoitaStore = defineStore('noita', () => {
}
}
const clearCache = async () => {
const clearCache = async (eventPath: string) => {
try {
const response = await fetch('/api/cache/clear', {
method: 'POST',
const response = await polylanSubmitterApiClearCache({
query: { event_path: eventPath },
})
if (!response.ok) {
const errorData = await response.json()
throw new Error(errorData.detail || 'Unknown error')
if (response.error) {
const detail = (response.error as { detail?: string })?.detail
throw new Error(detail || 'Unknown error')
}
await Promise.all([fetchUserResults(), fetchLeaderboard()])
await Promise.all([fetchUserResults(eventPath), fetchLeaderboard(eventPath)])
} catch (err) {
const errorMessage = err instanceof Error ? err.message : 'Unknown error'
error.value = `Error clearing cache: ${errorMessage}`
@@ -143,8 +142,8 @@ export const useNoitaStore = defineStore('noita', () => {
}
}
const refreshData = async () => {
await Promise.all([fetchUserResults(), fetchLeaderboard()])
const refreshData = async (eventPath: string) => {
await Promise.all([fetchUserResults(eventPath), fetchLeaderboard(eventPath)])
}
return {
+4 -3
View File
@@ -1,5 +1,6 @@
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { polylanSubmitterApiGetUserInfo } from '@/api'
interface UserInfo {
username: string
@@ -19,9 +20,9 @@ export const useUserStore = defineStore('user', () => {
const loadUserData = async () => {
isLoading.value = true
try {
const response = await fetch('/api/user')
if (response.ok) {
const user = await response.json()
const response = await polylanSubmitterApiGetUserInfo()
if (response.data) {
const user = response.data
userInfo.value.isAuthenticated = user.is_authenticated || false
userInfo.value.username = user.username || ''
userInfo.value.isStaff = user.is_staff || false