fix: multi-events
This commit is contained in:
@@ -14,6 +14,12 @@ import {
|
||||
type SortingState,
|
||||
} from "@tanstack/vue-table";
|
||||
|
||||
interface Props {
|
||||
eventPath: string;
|
||||
}
|
||||
|
||||
const props = defineProps<Props>();
|
||||
|
||||
const noitaStore = useNoitaStore();
|
||||
const { userInfo, objectives, leaderboard, isLoadingLeaderboard, isUploading } = storeToRefs(noitaStore);
|
||||
|
||||
@@ -135,7 +141,7 @@ const submitRun = async () => {
|
||||
if (uploadedFiles.value.length === 0) return;
|
||||
|
||||
try {
|
||||
await noitaStore.submitRun(uploadedFiles.value);
|
||||
await noitaStore.submitRun(props.eventPath, uploadedFiles.value);
|
||||
uploadedFiles.value = [];
|
||||
alert("Run submitted successfully!");
|
||||
} catch (error) {
|
||||
@@ -145,12 +151,12 @@ const submitRun = async () => {
|
||||
};
|
||||
|
||||
const goHome = () => {
|
||||
window.location.href = "/";
|
||||
window.location.href = `/${props.eventPath}/`;
|
||||
};
|
||||
|
||||
const clearCache = async () => {
|
||||
try {
|
||||
await noitaStore.clearCache();
|
||||
await noitaStore.clearCache(props.eventPath);
|
||||
alert("Cache cleared successfully!");
|
||||
} catch (error) {
|
||||
console.error("Error clearing cache:", error);
|
||||
@@ -159,7 +165,7 @@ const clearCache = async () => {
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
noitaStore.loadUserData();
|
||||
noitaStore.loadUserData(props.eventPath);
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from "vue";
|
||||
import RankBadge from "./RankBadge.vue";
|
||||
import { animationsApiResults, polylanSubmitterApiClearCache, polylanSubmitterApiGetUserInfo } from "@/api";
|
||||
import { useEventPath } from "@/composables/useEventPath";
|
||||
|
||||
const eventPath = useEventPath();
|
||||
|
||||
interface User {
|
||||
id: number;
|
||||
@@ -65,10 +69,10 @@ const userInfo = ref({
|
||||
const fetchResults = async () => {
|
||||
isLoading.value = true;
|
||||
try {
|
||||
const response = await fetch("/api/results/results");
|
||||
if (!response.ok) throw new Error("Failed to fetch results");
|
||||
const response = await animationsApiResults({ path: { event_path: eventPath } });
|
||||
if (response.error || !response.data) throw new Error("Failed to fetch results");
|
||||
|
||||
resultsData.value = await response.json();
|
||||
resultsData.value = response.data as unknown as ResultsData;
|
||||
} catch (error) {
|
||||
console.error("Error fetching results:", error);
|
||||
} finally {
|
||||
@@ -117,16 +121,16 @@ const togglePuzzleExpanded = (puzzleId: number) => {
|
||||
|
||||
const clearCache = async () => {
|
||||
try {
|
||||
const response = await fetch("/api/cache/clear", {
|
||||
method: "POST",
|
||||
const response = await polylanSubmitterApiClearCache({
|
||||
query: { event_path: eventPath },
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
if (!response.error) {
|
||||
alert("Cache cleared successfully!");
|
||||
await fetchResults();
|
||||
} else {
|
||||
const error = await response.json();
|
||||
alert(`Error clearing cache: ${error.detail || "Unknown error"}`);
|
||||
const detail = (response.error as { detail?: string })?.detail;
|
||||
alert(`Error clearing cache: ${detail || "Unknown error"}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error clearing cache:", error);
|
||||
@@ -136,24 +140,22 @@ const clearCache = async () => {
|
||||
|
||||
const loadUserData = async () => {
|
||||
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();
|
||||
const user = response.data;
|
||||
if (user?.is_authenticated) {
|
||||
userInfo.value.username = user.username ?? "";
|
||||
userInfo.value.isStaff = user.is_staff || false;
|
||||
|
||||
await fetchResults();
|
||||
await fetchResults();
|
||||
|
||||
// Calculate user's rank and stats
|
||||
const ranking = getOverallRanking();
|
||||
const userRankIndex = ranking.findIndex((u) => u.user.id === user.id);
|
||||
// Calculate user's rank and stats
|
||||
const ranking = getOverallRanking();
|
||||
const userRankIndex = ranking.findIndex((u) => u.user.id === user.id);
|
||||
|
||||
if (userRankIndex !== -1) {
|
||||
userInfo.value.rank = userRankIndex + 1;
|
||||
userInfo.value.totalPoints = ranking[userRankIndex].totalPoints;
|
||||
userInfo.value.puzzlesSolved = ranking[userRankIndex].puzzlesSolved;
|
||||
}
|
||||
if (userRankIndex !== -1) {
|
||||
userInfo.value.rank = userRankIndex + 1;
|
||||
userInfo.value.totalPoints = ranking[userRankIndex].totalPoints;
|
||||
userInfo.value.puzzlesSolved = ranking[userRankIndex].puzzlesSolved;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user