Skip to content

Commit ffabd3e

Browse files
committed
feat(web): highlight used-in-server names in name history panel
1 parent 36071ca commit ffabd3e

File tree

2 files changed

+79
-42
lines changed

2 files changed

+79
-42
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<template>
2+
<ul class="bg-white overflow-hidden">
3+
<li
4+
v-for="({name, changedToAt}, idx) of names"
5+
:key="changedToAt || 'init'"
6+
:class="['p-3 border-t first:border-t-0 border-gray-300 flex items-center', {'bg-gray-50 text-gray-500': idx < lastInServer || firstInServer < idx}]"
7+
>
8+
<strong class="font-normal mr-3">{{ name }}</strong>
9+
<span class="ml-auto text-gray-500 font-tnum">{{ formatDate(changedToAt) || t('nyaa.player_name_history.first_name') }}</span>
10+
</li>
11+
<li v-if="isLoadingNameHistory" class="p-3 border-t first:border-t-0 border-gray-300 bg-gray-100 text-gray-500 flex items-center">{{ t('nyaa.general.loading_hint') }}</li>
12+
</ul>
13+
</template>
14+
15+
<script>
16+
import axios from 'axios'
17+
18+
import {normalizeDate} from '@/common/utils'
19+
20+
export default {
21+
name: 'PlayerNameHistory',
22+
23+
props: {
24+
player: {
25+
type: Object,
26+
required: true,
27+
},
28+
},
29+
30+
data () {
31+
return {
32+
names: this.player.data.names,
33+
isLoadingNameHistory: true,
34+
}
35+
},
36+
37+
computed: {
38+
// Index of the last name used in server
39+
lastInServer () {
40+
return this.names.findIndex(({changedToAt}) => (changedToAt ?? -Infinity) < this.player.data.time_last)
41+
},
42+
43+
// Index of the first name used in server
44+
firstInServer () {
45+
return this.names.findIndex(({changedToAt}) => (changedToAt ?? -Infinity) < this.player.data.time_start)
46+
},
47+
},
48+
49+
created () {
50+
this.loadNameHistory()
51+
},
52+
53+
methods: {
54+
async loadNameHistory () {
55+
if (this.names.slice(-1)[0].changedToAt) {
56+
const {data} = await axios(
57+
process.env.NODE_ENV === 'development'
58+
? `/mojang-api/user/profiles/${this.player.data.uuid_short}/names`
59+
: `https://mojang-api.silent.land/${location.host}/user/profiles/${this.uuid}/names`
60+
)
61+
this.names = data.reverse()
62+
}
63+
64+
this.isLoadingNameHistory = false
65+
},
66+
67+
formatDate (val) {
68+
return val && normalizeDate(val, 'short')
69+
},
70+
},
71+
}
72+
</script>

web/src/views/Player.vue

Lines changed: 7 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,7 @@
3434
<!-- Name history -->
3535
<div class="mt-5">
3636
<h2 class="font-medium text-cool-gray-600 uppercase tracking-wide px-3 pb-2">{{ t('nyaa.player_name_history.section_title') }}</h2>
37-
<ul class="bg-white rounded-md shadow">
38-
<li
39-
v-for="({name, changedToAt}, idx) of player.data.names"
40-
:key="idx"
41-
class="p-3 border-t first:border-t-0 border-gray-300 flex items-center"
42-
>
43-
<strong class="font-normal mr-3">{{ name }}</strong>
44-
<span class="ml-auto text-gray-500 font-tnum">{{ formatDate(changedToAt) || t('nyaa.player_name_history.first_name') }}</span>
45-
</li>
46-
<li v-if="isLoadingNameHistory" class="p-3 border-t first:border-t-0 border-gray-300 text-gray-500 flex items-center">{{ t('nyaa.general.loading_hint') }}</li>
47-
</ul>
37+
<PlayerNameHistory :player="player" class="rounded-md shadow" />
4838
</div>
4939
<!-- Ore mining graph -->
5040
<div class="mt-5">
@@ -65,11 +55,11 @@
6555
</template>
6656

6757
<script>
68-
import axios from 'axios'
6958
import {add, formatDistanceStrict} from 'date-fns'
7059
import {zhCN} from 'date-fns/locale'
7160
7261
import advancementData from '@/assets/advancement-data.json'
62+
import PlayerNameHistory from '@/components/PlayerNameHistory.vue'
7363
import PlayerOreGraph from '@/components/PlayerOreGraph.vue'
7464
import PlayerAdvancementPanel from '@/components/PlayerAdvancementPanel.vue'
7565
import PlayerStatisticPanel from '@/components/PlayerStatisticPanel.vue'
@@ -82,6 +72,7 @@
8272
name: 'PlayerView',
8373
8474
components: {
75+
PlayerNameHistory,
8576
PlayerOreGraph,
8677
PlayerAdvancementPanel,
8778
PlayerStatisticPanel,
@@ -91,8 +82,6 @@
9182
return {
9283
player: null,
9384
94-
isLoadingNameHistory: true,
95-
9685
goRandom,
9786
}
9887
},
@@ -110,14 +99,14 @@
11099
111100
membership () {
112101
const output = [
113-
{
114-
label: this.t('nyaa.player_info.first_login'),
115-
value: this.formatDate(this.player?.data.time_start),
116-
},
117102
{
118103
label: this.t('nyaa.player_info.last_active'),
119104
value: this.formatDate(this.player?.data.time_last),
120105
},
106+
{
107+
label: this.t('nyaa.player_info.first_login'),
108+
value: this.formatDate(this.player?.data.time_start),
109+
},
121110
{
122111
label: this.t('nyaa.player_info.total_online'),
123112
value: null,
@@ -138,12 +127,6 @@
138127
uuid () {
139128
this.fetchData()
140129
},
141-
142-
player (val) {
143-
if (val) {
144-
this.loadNameHistory()
145-
}
146-
},
147130
},
148131
149132
created () {
@@ -158,24 +141,6 @@
158141
this.$store.commit('setFooterUpdateTime', this.player.data.lastUpdate)
159142
},
160143
161-
async loadNameHistory () {
162-
if (!this.player) {
163-
console.error('Attempt to load name history while player data is not ready.')
164-
return
165-
}
166-
167-
if (this.player.data.names.slice(-1)[0].changedToAt) {
168-
const {data} = await axios(
169-
process.env.NODE_ENV === 'development'
170-
? `/mojang-api/user/profiles/${this.uuid}/names`
171-
: `https://mojang-api.silent.land/${location.host}/user/profiles/${this.uuid}/names`
172-
)
173-
this.$set(this.player.data, 'names', data.reverse())
174-
}
175-
176-
this.isLoadingNameHistory = false
177-
},
178-
179144
formatDate (val) {
180145
return val && normalizeDate(val, 'short')
181146
},

0 commit comments

Comments
 (0)