refactor(sceneries): changed to new api call for top list; added duty duration mode option

This commit is contained in:
2026-04-17 03:02:03 +02:00
parent 5a684ddc66
commit 7af08f3cb8
3 changed files with 38 additions and 51 deletions
+26 -43
View File
@@ -28,22 +28,8 @@
<Loading v-if="listState == Status.Data.Loading" /> <Loading v-if="listState == Status.Data.Loading" />
<div v-else-if="listState == Status.Data.Error">Ups, coś poszło nie tak...</div> <div v-else-if="listState == Status.Data.Error">Ups, coś poszło nie tak...</div>
<ul v-else-if="currentListMode == 'likes'">
<li v-for="(value, i) in topLikesList">
<div>
{{ t('scenery.top-list.place', i + 1) }} -
<router-link :to="`/profile?playerId=${value.dispatcherId}`">{{
value.dispatcherName
}}</router-link>
</div>
<div>
<b class="text--primary">{{ t('scenery.top-list.like-count', value.sumRate) }}</b>
</div>
</li>
</ul>
<ul v-else> <ul v-else>
<li v-for="(value, i) in topDispatchersList"> <li v-for="(value, i) in bestScoreList">
<div> <div>
{{ t('scenery.top-list.place', i + 1) }} - {{ t('scenery.top-list.place', i + 1) }} -
<router-link :to="`/profile?playerId=${value.dispatcherId}`">{{ <router-link :to="`/profile?playerId=${value.dispatcherId}`">{{
@@ -51,7 +37,18 @@
}}</router-link> }}</router-link>
</div> </div>
<div> <div>
<b class="text--primary">{{ t('scenery.top-list.dispatch-count', value.count) }}</b> <b class="text--primary" v-if="currentListMode == 'dutyCount'">{{
t('scenery.top-list.duty-count', value.value)
}}</b>
<b class="text--primary" v-else-if="currentListMode == 'dispatcherRating'">{{
t('scenery.top-list.dispatcher-rating', value.value)
}}</b>
<b class="text--primary" v-else>
{{ t('scenery.top-list.duration') }}
{{ humanizeDuration(value.value) }}
</b>
</div> </div>
</li> </li>
</ul> </ul>
@@ -65,24 +62,17 @@ import { useI18n } from 'vue-i18n';
import { useApiStore } from '../../store/apiStore'; import { useApiStore } from '../../store/apiStore';
import { Station, ActiveScenery, Status } from '../../typings/common'; import { Station, ActiveScenery, Status } from '../../typings/common';
import Loading from '../Global/Loading.vue'; import Loading from '../Global/Loading.vue';
import { useMainStore } from '../../store/mainStore'; import { humanizeDuration } from '../../composables/time';
interface DispatcherTopCount { interface SceneryBestScoreItem {
dispatcherName: string; dispatcherName: string;
dispatcherId: number; dispatcherId: number;
count: number; value: number;
}
interface LikesTopCount {
dispatcherName: string;
dispatcherId: number;
sumRate: number;
} }
const { t } = useI18n(); const { t } = useI18n();
const apiStore = useApiStore(); const apiStore = useApiStore();
const mainStore = useMainStore();
defineOptions({ defineOptions({
name: 'SceneryTopList' name: 'SceneryTopList'
@@ -98,19 +88,18 @@ const props = defineProps({
} }
}); });
const availableModes = ['likes', 'dispatchers'] as const; const availableModes = ['dutyCount', 'dispatcherRating', 'dutyDuration'] as const;
const availableScopes = ['name', 'hash'] as const; const availableScopes = ['name', 'hash'] as const;
type ListMode = (typeof availableModes)[number]; type ListMode = (typeof availableModes)[number];
type ListScope = (typeof availableScopes)[number]; type ListScope = (typeof availableScopes)[number];
const currentListMode = ref<ListMode>('likes'); const currentListMode = ref<ListMode>('dutyCount');
const currentListScope = ref<ListScope>('name'); const currentListScope = ref<ListScope>('name');
const listState = ref<Status.Data>(Status.Data.Loading); const listState = ref<Status.Data>(Status.Data.Loading);
const topLikesList = ref<LikesTopCount[]>([]); const bestScoreList = ref<SceneryBestScoreItem[]>([]);
const topDispatchersList = ref<DispatcherTopCount[]>([]);
onActivated(() => { onActivated(() => {
fetchTopDispatchersList(); fetchTopDispatchersList();
@@ -132,10 +121,7 @@ async function fetchTopDispatchersList() {
? props.station?.name ? props.station?.name
: apiStore.sceneryData.find((sc) => sc.name == props.station!.name)?.hash; : apiStore.sceneryData.find((sc) => sc.name == props.station!.name)?.hash;
console.log(searchedStationValue); bestScoreList.value = [];
topDispatchersList.value = [];
topLikesList.value = [];
if (!searchedStationValue) { if (!searchedStationValue) {
listState.value = Status.Data.Loaded; listState.value = Status.Data.Loaded;
@@ -145,16 +131,13 @@ async function fetchTopDispatchersList() {
try { try {
listState.value = Status.Data.Loading; listState.value = Status.Data.Loading;
const response = await apiStore.client.get( const response: SceneryBestScoreItem[] = await apiStore.client.get(`api/getSceneryBestScores`, {
`api/getSceneryTop${currentListMode.value}By${currentListScope.value}?${currentListScope.value}=${searchedStationValue}&countLimit=40` [currentListScope.value]: searchedStationValue,
); type: currentListMode.value,
currentLimit: 40
if (currentListMode.value == 'dispatchers') { });
topDispatchersList.value = response as DispatcherTopCount[];
} else {
topLikesList.value = response as LikesTopCount[];
}
bestScoreList.value = response;
listState.value = Status.Data.Loaded; listState.value = Status.Data.Loaded;
} catch (error) { } catch (error) {
listState.value = Status.Data.Error; listState.value = Status.Data.Error;
+6 -4
View File
@@ -597,14 +597,16 @@
"btn-hide-internal-routes": "Hide internal routes", "btn-hide-internal-routes": "Hide internal routes",
"top-list": { "top-list": {
"header": "RECORDS ON THE SCENERY (PL1)", "header": "RECORDS ON THE SCENERY (PL1)",
"mode-likes": "DISP. RATING", "mode-dispatcherRating": "DISP. RATING",
"mode-dispatchers": "DUTY COUNT", "mode-dutyCount": "DUTY COUNT",
"mode-dutyDuration": "DUTY DURATION",
"scope-name": "GENERAL", "scope-name": "GENERAL",
"scope-hash": "CURRENT HASH", "scope-hash": "CURRENT HASH",
"place": "{n}. place", "place": "{n}. place",
"like-count": "Rating: {n}", "dispatcher-rating": "Rating: {n}",
"dispatch-count": "No duties | 1 duty | Duties: {n}" "duty-count": "No duties | 1 duty | Duties: {n}",
"duration": "Duration:"
} }
}, },
"availability": { "availability": {
+6 -4
View File
@@ -583,14 +583,16 @@
"btn-hide-internal-routes": "Ukrywaj szlaki wewnętrzne", "btn-hide-internal-routes": "Ukrywaj szlaki wewnętrzne",
"top-list": { "top-list": {
"header": "REKORDY NA SCENERII (PL1)", "header": "REKORDY NA SCENERII (PL1)",
"mode-likes": "OCENA DR", "mode-dispatcherRating": "OCENA DR",
"mode-dispatchers": "LICZBA DYŻURÓW", "mode-dutyCount": "DYŻURY",
"mode-dutyDuration": "CZAS DYŻURU",
"scope-name": "OGÓLNIE", "scope-name": "OGÓLNIE",
"scope-hash": "OBECNY HASH", "scope-hash": "OBECNY HASH",
"place": "{n}. miejsce", "place": "{n}. miejsce",
"like-count": "Ocena: {n}", "dispatcher-rating": "Ocena: {n}",
"dispatch-count": "Brak dyżurów | 1 dyżur | Dyżury: {n}" "duty-count": "Brak dyżurów | 1 dyżur | Dyżury: {n}",
"duration": "Czas:"
} }
}, },
"availability": { "availability": {