fix: multi-events
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user