From 37946c5aba02b397e33199a335e8b7238428517c Mon Sep 17 00:00:00 2001 From: Azalea <22280294+hykilpikonna@users.noreply.github.com> Date: Wed, 25 Dec 2024 16:31:01 -0500 Subject: [PATCH] [+] Helpful message for unsupported games --- AquaNet/src/libs/i18n/en_ref.ts | 1 + AquaNet/src/libs/i18n/zh.ts | 1 + AquaNet/src/pages/UserHome.svelte | 79 ++++++++++++++++--------------- 3 files changed, 44 insertions(+), 37 deletions(-) diff --git a/AquaNet/src/libs/i18n/en_ref.ts b/AquaNet/src/libs/i18n/en_ref.ts index bdda8016..b9d02f9d 100644 --- a/AquaNet/src/libs/i18n/en_ref.ts +++ b/AquaNet/src/libs/i18n/en_ref.ts @@ -26,6 +26,7 @@ export const EN_REF_USER = { 'UserHome.B50': 'B50', 'UserHome.AddRival': "Add to Rival", 'UserHome.RemoveRival': "Remove from Rival", + 'UserHome.InvalidGame': "Game ${game} is not supported on the web UI yet. We only support maimai, chunithm, wacca, and ongeki for now.", } export const EN_REF_Welcome = { diff --git a/AquaNet/src/libs/i18n/zh.ts b/AquaNet/src/libs/i18n/zh.ts index fbb52218..f40fb0cf 100644 --- a/AquaNet/src/libs/i18n/zh.ts +++ b/AquaNet/src/libs/i18n/zh.ts @@ -35,6 +35,7 @@ const zhUser: typeof EN_REF_USER = { 'UserHome.B50': "B50", 'UserHome.AddRival': "添加劲敌", 'UserHome.RemoveRival': "移除劲敌", + 'UserHome.InvalidGame': "游戏 ${game} 还不支持网页端查看。我们目前只支持舞萌、中二、Wacca 和音击。", } const zhWelcome: typeof EN_REF_Welcome = { diff --git a/AquaNet/src/pages/UserHome.svelte b/AquaNet/src/pages/UserHome.svelte index 0c75d5d7..613d6cdf 100644 --- a/AquaNet/src/pages/UserHome.svelte +++ b/AquaNet/src/pages/UserHome.svelte @@ -50,49 +50,54 @@ let allMusics: AllMusic let showDetailRank = false let isLoading = false - USER.isLoggedIn() && USER.me().then(u => me = u) + function init() { + USER.isLoggedIn() && USER.me().then(u => me = u) - CARD.userGames(username).then(games => { - if (!games[game]) { - // Find a valid game - const valid = Object.entries(games).filter(([g, valid]) => valid) - if (!valid || !valid[0]) return error = t("UserHome.NoValidGame") - window.location.href = `/u/${username}/${valid[0][0]}` - } + CARD.userGames(username).then(games => { + if (!games[game]) { + // Find a valid game + const valid = Object.entries(games).filter(([g, valid]) => valid) + if (!valid || !valid[0]) return error = t("UserHome.NoValidGame") + window.location.href = `/u/${username}/${valid[0][0]}` + } - Promise.all([ - GAME.userSummary(username, game), - GAME.trend(username, game), - DATA.allMusic(game), - ]).then(([user, trend, music]) => { - console.log(user) - console.log(trend) - console.log(games) + Promise.all([ + GAME.userSummary(username, game), + GAME.trend(username, game), + DATA.allMusic(game), + ]).then(([user, trend, music]) => { + console.log(user) + console.log(trend) + console.log(games) - // If game is wacca, divide all ratings by 10 - if (game === 'wacca') { - user.rating /= 10 - trend.forEach(it => it.rating /= 10) - user.recent.forEach(it => { - it.beforeRating /= 10 - it.afterRating /= 10 + // If game is wacca, divide all ratings by 10 + if (game === 'wacca') { + user.rating /= 10 + trend.forEach(it => it.rating /= 10) + user.recent.forEach(it => { + it.beforeRating /= 10 + it.afterRating /= 10 + }) + } + + 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]) + } + allMusics = music + 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); + }).catch((e) => { error = e.message; console.error(e) } ); + } - 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]) - } - allMusics = music - 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); - }).catch((e) => { error = e.message; console.error(e) } ); + if (Object.keys(GAME_TITLE).includes(game)) init() + else error = t("UserHome.InvalidGame", {game}) const setRival = (isAdd: boolean) => { isLoading = true