mirror of
https://github.com/Spythere/srjp-td2.git
synced 2026-05-03 13:38:12 +00:00
chore: add api data status info
This commit is contained in:
@@ -16,9 +16,11 @@
|
|||||||
name="trains"
|
name="trains"
|
||||||
id="trains-select"
|
id="trains-select"
|
||||||
class="bg-zinc-800 p-1 rounded-md print:hidden w-full"
|
class="bg-zinc-800 p-1 rounded-md print:hidden w-full"
|
||||||
|
:disabled="apiStore.activeDataStatus != DataStatus.SUCCESS"
|
||||||
v-model="selectedTrainId"
|
v-model="selectedTrainId"
|
||||||
@change="selectTrain"
|
@change="selectTrain"
|
||||||
>
|
>
|
||||||
|
<option value="" disabled>{{ apiStore.activeDataStatus == DataStatus.LOADING ? 'Ładowanie danych...' : 'Wybierz pociąg z listy' }}</option>
|
||||||
<option :value="train.id" v-for="train in activeTimetableTrains">
|
<option :value="train.id" v-for="train in activeTimetableTrains">
|
||||||
{{ train.driverName }} | {{ train.timetable?.category }} {{ train.trainNo }}
|
{{ train.driverName }} | {{ train.timetable?.category }} {{ train.trainNo }}
|
||||||
</option>
|
</option>
|
||||||
@@ -245,6 +247,7 @@ import type { ActiveTrain } from './types/common.types';
|
|||||||
import { version } from '../package.json';
|
import { version } from '../package.json';
|
||||||
import { PrinterIcon, ArrowPathIcon, ExclamationTriangleIcon } from '@heroicons/vue/16/solid';
|
import { PrinterIcon, ArrowPathIcon, ExclamationTriangleIcon } from '@heroicons/vue/16/solid';
|
||||||
import { useApiStore } from './stores/api.store';
|
import { useApiStore } from './stores/api.store';
|
||||||
|
import { DataStatus } from './types/api.types';
|
||||||
|
|
||||||
interface StopRow {
|
interface StopRow {
|
||||||
pointName: string;
|
pointName: string;
|
||||||
@@ -290,6 +293,7 @@ export default defineComponent({
|
|||||||
version,
|
version,
|
||||||
|
|
||||||
apiMode: import.meta.env.VITE_API_MODE,
|
apiMode: import.meta.env.VITE_API_MODE,
|
||||||
|
DataStatus,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { AxiosInstance } from 'axios';
|
import type { AxiosInstance } from 'axios';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
import type { ActiveDataResponse, SceneriesDataResponse } from '../types/api.types';
|
import { DataStatus, type ActiveDataResponse, type SceneriesDataResponse } from '../types/api.types';
|
||||||
import type { ActiveData, SceneryData } from '../types/common.types';
|
import type { ActiveData, SceneryData } from '../types/common.types';
|
||||||
|
|
||||||
export const useApiStore = defineStore('api', {
|
export const useApiStore = defineStore('api', {
|
||||||
@@ -11,6 +11,8 @@ export const useApiStore = defineStore('api', {
|
|||||||
|
|
||||||
activeData: null as ActiveData | null,
|
activeData: null as ActiveData | null,
|
||||||
sceneryData: null as SceneryData[] | null,
|
sceneryData: null as SceneryData[] | null,
|
||||||
|
|
||||||
|
activeDataStatus: DataStatus.LOADING
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -34,7 +36,7 @@ export const useApiStore = defineStore('api', {
|
|||||||
this.client = axios.create({
|
this.client = axios.create({
|
||||||
baseURL,
|
baseURL,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.fetchSceneriesData();
|
this.fetchSceneriesData();
|
||||||
this.fetchActiveData();
|
this.fetchActiveData();
|
||||||
|
|
||||||
@@ -48,6 +50,7 @@ export const useApiStore = defineStore('api', {
|
|||||||
const response = (await this.client!.get<ActiveDataResponse>('/api/getActiveData')).data;
|
const response = (await this.client!.get<ActiveDataResponse>('/api/getActiveData')).data;
|
||||||
|
|
||||||
this.activeData = response;
|
this.activeData = response;
|
||||||
|
this.activeDataStatus = DataStatus.SUCCESS;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,3 +3,9 @@ import type { ActiveData, SceneryData } from './common.types';
|
|||||||
export type ActiveDataResponse = ActiveData;
|
export type ActiveDataResponse = ActiveData;
|
||||||
|
|
||||||
export type SceneriesDataResponse = SceneryData[];
|
export type SceneriesDataResponse = SceneryData[];
|
||||||
|
|
||||||
|
export enum DataStatus {
|
||||||
|
'LOADING' = 0,
|
||||||
|
'SUCCESS' = 1,
|
||||||
|
'ERROR' = 2,
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user