[+] mai2: support adding rival

This commit is contained in:
Clansty
2024-08-05 20:37:18 +08:00
parent 94ba1f0b09
commit 473f4a4295
14 changed files with 88 additions and 20 deletions

View File

@@ -99,6 +99,7 @@ export interface GenericGameSummary {
lastVersion: string
ratingComposition: { [key: string]: any }
recent: GenericGamePlaylog[]
rival?: boolean
}
export interface MusicMeta {

View File

@@ -24,6 +24,8 @@ export const EN_REF_USER = {
'UserHome.RankDetail.Title': 'Achievement Details',
'UserHome.RankDetail.Level': 'Level',
'UserHome.B50': 'B50',
'UserHome.AddRival': "Add to Rival",
'UserHome.RemoveRival': "Remove from Rival",
}
export const EN_REF_Welcome = {

View File

@@ -33,6 +33,8 @@ const zhUser: typeof EN_REF_USER = {
'UserHome.RankDetail.Title': '评分详细',
'UserHome.RankDetail.Level': "等级",
'UserHome.B50': "B50",
'UserHome.AddRival': "添加劲敌",
'UserHome.RemoveRival': "移除劲敌",
}
const zhWelcome: typeof EN_REF_Welcome = {

View File

@@ -305,6 +305,8 @@ export const GAME = {
post(`/api/v2/game/${game}/export`),
import: (game: GameName, data: any): Promise<Record<string, any>> =>
post(`/api/v2/game/${game}/import`, {}, { body: JSON.stringify(data) }),
setRival: (game: GameName, rivalUserName: string, isAdd: boolean) =>
post(`/api/v2/game/${game}/set-rival`, { rivalUserName, isAdd }),
}
export const DATA = {

View File

@@ -47,6 +47,7 @@
let allMusics: AllMusic
let showDetailRank = false
let isLoading = false
USER.isLoggedIn() && USER.me().then(u => me = u)
@@ -90,6 +91,13 @@
})
}).catch((e) => error = e.message);
}).catch((e) => { error = e.message; console.error(e) } );
const setRival = (isAdd: boolean) => {
isLoading = true
GAME.setRival(game, username, isAdd).then(() => {
d!.user.rival = isAdd
}).catch(e => error = e.message).finally(() => isLoading = false)
}
</script>
<main id="user-home" class="content">
@@ -98,6 +106,11 @@
<img use:pfp={d.user.aquaUser} alt="" class="pfp" on:error={pfpNotFound}>
<div class="name-box">
<h2>{d.user.name}</h2>
{#if typeof d.user.rival === 'boolean' && game === 'mai2'}
<a class="clickable" on:click={()=>setRival(!d.user.rival)}>
{d.user.rival ? t("UserHome.RemoveRival") : t("UserHome.AddRival")}
</a>
{/if}
{#if me && me.username === username}
<a class="setting-icon clickable" use:tooltip={t("UserHome.Settings")} href="/settings">
<Icon icon="eos-icons:rotating-gear"/>
@@ -267,7 +280,7 @@
</div>
{/if}
<StatusOverlays {error} loading={!d} />
<StatusOverlays {error} loading={!d || isLoading} />
</main>
<style lang="sass">