mirror of
https://github.com/MewoLab/AquaDX.git
synced 2026-02-13 04:17:27 +08:00
[F] Fix no data when a user hasn't played maimai
This commit is contained in:
@@ -22,6 +22,7 @@ export const EN_REF_USER = {
|
|||||||
'UserHome.Game.Ongeki': "Ongeki",
|
'UserHome.Game.Ongeki': "Ongeki",
|
||||||
'UserHome.UnknownSong': "(unknown song)",
|
'UserHome.UnknownSong': "(unknown song)",
|
||||||
'UserHome.Settings': 'Settings',
|
'UserHome.Settings': 'Settings',
|
||||||
|
'UserHome.NoValidGame': "The user hasn't played any game yet.",
|
||||||
}
|
}
|
||||||
|
|
||||||
export const EN_REF_Welcome = {
|
export const EN_REF_Welcome = {
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ const zhUser: typeof EN_REF_USER = {
|
|||||||
'UserHome.Game.Ongeki': "音击",
|
'UserHome.Game.Ongeki': "音击",
|
||||||
'UserHome.UnknownSong': "(未知曲目)",
|
'UserHome.UnknownSong': "(未知曲目)",
|
||||||
'UserHome.Settings': '设置',
|
'UserHome.Settings': '设置',
|
||||||
|
'UserHome.NoValidGame': "用户还没有玩过游戏",
|
||||||
}
|
}
|
||||||
|
|
||||||
const zhWelcome: typeof EN_REF_Welcome = {
|
const zhWelcome: typeof EN_REF_Welcome = {
|
||||||
|
|||||||
@@ -135,6 +135,8 @@ export const CARD = {
|
|||||||
post('/api/v2/card/link', props),
|
post('/api/v2/card/link', props),
|
||||||
unlink: (cardId: string) =>
|
unlink: (cardId: string) =>
|
||||||
post('/api/v2/card/unlink', { cardId }),
|
post('/api/v2/card/unlink', { cardId }),
|
||||||
|
userGames: (username: string): Promise<CardSummary> =>
|
||||||
|
post('/api/v2/card/user-games', { username }),
|
||||||
}
|
}
|
||||||
|
|
||||||
export const GAME = {
|
export const GAME = {
|
||||||
|
|||||||
@@ -1,12 +1,19 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { CHARTJS_OPT, coverNotFound, pfpNotFound, registerChart, renderCal, title, tooltip, pfp } from "../libs/ui";
|
import { CHARTJS_OPT, coverNotFound, pfpNotFound, registerChart, renderCal, title, tooltip, pfp } from "../libs/ui";
|
||||||
import type { GenericGamePlaylog, GenericGameSummary, MusicMeta, TrendEntry, AquaNetUser } from "../libs/generalTypes";
|
import type {
|
||||||
|
GenericGamePlaylog,
|
||||||
|
GenericGameSummary,
|
||||||
|
MusicMeta,
|
||||||
|
TrendEntry,
|
||||||
|
AquaNetUser,
|
||||||
|
CardSummary
|
||||||
|
} from "../libs/generalTypes";
|
||||||
import { DATA_HOST } from "../libs/config";
|
import { DATA_HOST } from "../libs/config";
|
||||||
import 'cal-heatmap/cal-heatmap.css';
|
import 'cal-heatmap/cal-heatmap.css';
|
||||||
import { Line } from 'svelte-chartjs';
|
import { Line } from 'svelte-chartjs';
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
import 'chartjs-adapter-moment';
|
import 'chartjs-adapter-moment';
|
||||||
import { DATA, GAME, USER } from "../libs/sdk";
|
import { CARD, DATA, GAME, USER } from "../libs/sdk";
|
||||||
import { type GameName, getMult } from "../libs/scoring";
|
import { type GameName, getMult } from "../libs/scoring";
|
||||||
import StatusOverlays from "../components/StatusOverlays.svelte";
|
import StatusOverlays from "../components/StatusOverlays.svelte";
|
||||||
import Icon from "@iconify/svelte";
|
import Icon from "@iconify/svelte";
|
||||||
@@ -23,37 +30,51 @@
|
|||||||
let me: AquaNetUser
|
let me: AquaNetUser
|
||||||
title(`User ${username}`)
|
title(`User ${username}`)
|
||||||
|
|
||||||
|
const GAME_TITLE: { [key in GameName]: string } =
|
||||||
|
{chu3: t("UserHome.Game.Chu3"), mai2: t("UserHome.Game.Mai2"), ongeki: t("UserHome.Game.Ongeki")}
|
||||||
|
const titleText = GAME_TITLE[game]
|
||||||
|
|
||||||
interface MusicAndPlay extends MusicMeta, GenericGamePlaylog {}
|
interface MusicAndPlay extends MusicMeta, GenericGamePlaylog {}
|
||||||
|
|
||||||
let d: {
|
let d: {
|
||||||
user: GenericGameSummary,
|
user: GenericGameSummary,
|
||||||
trend: TrendEntry[]
|
trend: TrendEntry[]
|
||||||
recent: MusicAndPlay[]
|
recent: MusicAndPlay[],
|
||||||
|
validGames: [ string, string ][]
|
||||||
} | null
|
} | null
|
||||||
|
|
||||||
USER.isLoggedIn() && USER.me().then(u => me = u)
|
USER.isLoggedIn() && USER.me().then(u => me = u)
|
||||||
|
|
||||||
Promise.all([
|
|
||||||
GAME.userSummary(username, game),
|
|
||||||
GAME.trend(username, game),
|
|
||||||
DATA.allMusic(game)
|
|
||||||
]).then(([user, trend, music]) => {
|
|
||||||
console.log(user)
|
|
||||||
console.log(trend)
|
|
||||||
|
|
||||||
const minDate = moment().subtract(TREND_DAYS, 'days').format("YYYY-MM-DD")
|
CARD.userGames(username).then(games => {
|
||||||
d = {user,
|
if (!games[game]) {
|
||||||
trend: trend.filter(it => it.date >= minDate && it.plays != 0),
|
// Find a valid game
|
||||||
recent: user.recent.map(it => {return {...music[it.musicId], ...it}})
|
const valid = Object.entries(games).filter(([g, valid]) => valid)
|
||||||
|
if (!valid) return error = t("UserHome.NoValidGame")
|
||||||
|
window.location.href = `/u/${username}/${valid[0][0]}`
|
||||||
}
|
}
|
||||||
renderCal(calElement, trend.map(it => {return {date: it.date, value: it.plays}})).then(() => {
|
|
||||||
// Scroll to the rightmost
|
|
||||||
calElement.scrollLeft = calElement.scrollWidth - calElement.clientWidth
|
|
||||||
})
|
|
||||||
}).catch((e) => error = e.message);
|
|
||||||
|
|
||||||
const games = {chu3: t("UserHome.Game.Chu3"), mai2: t("UserHome.Game.Mai2"), ongeki: t("UserHome.Game.Ongeki")}
|
Promise.all([
|
||||||
const titleText = games[game]
|
GAME.userSummary(username, game),
|
||||||
|
GAME.trend(username, game),
|
||||||
|
DATA.allMusic(game),
|
||||||
|
]).then(([user, trend, music]) => {
|
||||||
|
console.log(user)
|
||||||
|
console.log(trend)
|
||||||
|
console.log(games)
|
||||||
|
|
||||||
|
const minDate = moment().subtract(TREND_DAYS, 'days').format("YYYY-MM-DD")
|
||||||
|
d = {user,
|
||||||
|
trend: trend.filter(it => it.date >= minDate && it.plays != 0),
|
||||||
|
recent: user.recent.map(it => {return {...music[it.musicId], ...it}}),
|
||||||
|
validGames: Object.entries(GAME_TITLE).filter(g => games[g[0] as GameName])
|
||||||
|
}
|
||||||
|
renderCal(calElement, trend.map(it => {return {date: it.date, value: it.plays}})).then(() => {
|
||||||
|
// Scroll to the rightmost
|
||||||
|
calElement.scrollLeft = calElement.scrollWidth - calElement.clientWidth
|
||||||
|
})
|
||||||
|
}).catch((e) => error = e.message);
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<main id="user-home" class="content">
|
<main id="user-home" class="content">
|
||||||
@@ -69,7 +90,7 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
<nav>
|
<nav>
|
||||||
{#each Object.entries(games) as [g, name]}
|
{#each d.validGames as [g, name]}
|
||||||
<a href={`/u/${username}/${g}`} class:active={game === g}>{name}</a>
|
<a href={`/u/${username}/${g}`} class:active={game === g}>{name}</a>
|
||||||
{/each}
|
{/each}
|
||||||
</nav>
|
</nav>
|
||||||
|
|||||||
Reference in New Issue
Block a user