mirror of
https://github.com/MewoLab/AquaDX.git
synced 2026-02-09 12:37:27 +08:00
[O] Use better error and loading
This commit is contained in:
@@ -3,12 +3,11 @@
|
||||
import {getMaimaiAllMusic, getMaimai} from "../libs/maimai";
|
||||
import type {ParsedRating, Rating} from "../libs/maimaiTypes";
|
||||
import { getMult } from "../libs/scoring";
|
||||
import ErrorMessage from "../ErrorMessage.svelte";
|
||||
import LoadingMessage from "../LoadingMessage.svelte";
|
||||
import StatusOverlays from "../components/StatusOverlays.svelte";
|
||||
|
||||
export let userId: any
|
||||
userId = +userId
|
||||
let ifError: string | null;
|
||||
let error: string | null;
|
||||
|
||||
if (!userId) console.error("No user ID provided")
|
||||
|
||||
@@ -28,9 +27,7 @@
|
||||
old: parseRating(data.userRating.ratingList),
|
||||
new: parseRating(data.userRating.newRatingList)
|
||||
}
|
||||
}).catch((error) => {
|
||||
ifError = error
|
||||
})
|
||||
}).catch((e) => error = e.message)
|
||||
|
||||
function parseRating(arr: Rating[]) {
|
||||
return arr.map(x => {
|
||||
@@ -96,12 +93,9 @@
|
||||
{/each}
|
||||
</div>
|
||||
{/each}
|
||||
{:else if ifError}
|
||||
<ErrorMessage {ifError}/>
|
||||
{:else}
|
||||
<LoadingMessage/>
|
||||
{/if}
|
||||
|
||||
{/if}
|
||||
|
||||
<StatusOverlays error={error} loading={!parsedRatings} />
|
||||
</main>
|
||||
|
||||
<style lang="sass">
|
||||
|
||||
@@ -2,21 +2,18 @@
|
||||
import { clz, title } from "../libs/ui";
|
||||
import { GAME } from "../libs/sdk";
|
||||
import type { GenericRanking } from "../libs/generalTypes";
|
||||
import ErrorMessage from "../ErrorMessage.svelte";
|
||||
import LoadingMessage from "../LoadingMessage.svelte";
|
||||
import StatusOverlays from "../components/StatusOverlays.svelte";
|
||||
|
||||
title(`Ranking`);
|
||||
|
||||
let d: { users: GenericRanking[] };
|
||||
let ifError: string | null;
|
||||
let error: string | null;
|
||||
Promise.all([GAME.ranking("mai2")])
|
||||
.then(([users]) => {
|
||||
console.log(users)
|
||||
d = { users };
|
||||
})
|
||||
.catch((error) => {
|
||||
ifError = error;
|
||||
});
|
||||
.catch((e) => error = e.message);
|
||||
</script>
|
||||
|
||||
<main class="content leaderboard">
|
||||
@@ -47,11 +44,9 @@
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{:else if ifError}
|
||||
<ErrorMessage {ifError}/>
|
||||
{:else}
|
||||
<LoadingMessage/>
|
||||
{/if}
|
||||
|
||||
<StatusOverlays error={error} loading={!d} />
|
||||
</main>
|
||||
|
||||
<style lang="sass">
|
||||
|
||||
@@ -8,8 +8,7 @@
|
||||
import 'chartjs-adapter-moment';
|
||||
import { DATA, GAME } from "../libs/sdk";
|
||||
import { type GameName, getMult } from "../libs/scoring";
|
||||
import ErrorMessage from "../ErrorMessage.svelte";
|
||||
import LoadingMessage from "../LoadingMessage.svelte";
|
||||
import StatusOverlays from "../components/StatusOverlays.svelte";
|
||||
|
||||
registerChart()
|
||||
|
||||
@@ -17,7 +16,7 @@
|
||||
export let game: GameName
|
||||
game = game || "mai2"
|
||||
let calElement: HTMLElement
|
||||
let ifError: string | null;
|
||||
let error: string | null;
|
||||
title(`User ${username}`)
|
||||
|
||||
interface MusicAndPlay extends MusicMeta, GenericGamePlaylog {}
|
||||
@@ -40,9 +39,7 @@
|
||||
d = {user, trend, recent: user.recent.map(it => {return {...music[it.musicId], ...it}})}
|
||||
localStorage.setItem("tmp-user-details", JSON.stringify(d))
|
||||
renderCal(calElement, trend.map(it => {return {date: it.date, value: it.plays}}))
|
||||
}).catch((error) => {
|
||||
ifError = error;
|
||||
});
|
||||
}).catch((e) => error = e.message);
|
||||
|
||||
const pfpNotFound = (e: Event) => {
|
||||
(e.target as HTMLImageElement).src = "/assets/imgs/no_profile.png"
|
||||
@@ -54,7 +51,7 @@
|
||||
</script>
|
||||
|
||||
<main id="user-home" class="content">
|
||||
{#if d !== null}
|
||||
{#if d}
|
||||
<div class="user-pfp">
|
||||
<img src={`${DATA_HOST}/d/${game}/assetbundle/icon/${d.user.iconId.toString().padStart(6, "0")}.png`} alt="" class="pfp" on:error={pfpNotFound}>
|
||||
<h2>{d.user.name}</h2>
|
||||
@@ -195,11 +192,9 @@
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{:else if ifError}
|
||||
<ErrorMessage {ifError}/>
|
||||
{:else}
|
||||
<LoadingMessage/>
|
||||
{/if}
|
||||
|
||||
<StatusOverlays {error} loading={!d} />
|
||||
</main>
|
||||
|
||||
<style lang="sass">
|
||||
|
||||
Reference in New Issue
Block a user