mirror of
https://github.com/Spythere/srjp-td2.git
synced 2026-05-03 05:28:12 +00:00
feat: loading timetable from url params
This commit is contained in:
+16
-3
@@ -19,13 +19,26 @@ const apiStore = useApiStore();
|
|||||||
const globalStore = useGlobalStore();
|
const globalStore = useGlobalStore();
|
||||||
const i18n = useI18n();
|
const i18n = useI18n();
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(async () => {
|
||||||
apiStore.setupAPIData();
|
|
||||||
|
|
||||||
setupLocale();
|
setupLocale();
|
||||||
setupDarkMode();
|
setupDarkMode();
|
||||||
loadStorageTimetables();
|
loadStorageTimetables();
|
||||||
setupAfterPrintClose();
|
setupAfterPrintClose();
|
||||||
|
|
||||||
|
await apiStore.setupAPIData();
|
||||||
|
|
||||||
|
const query = new URLSearchParams(window.location.search);
|
||||||
|
|
||||||
|
if (query.has('id')) {
|
||||||
|
const id = query.get('id')!;
|
||||||
|
|
||||||
|
const queryTrain = apiStore.activeData?.trains.find((train) => train.id == id);
|
||||||
|
|
||||||
|
if (queryTrain) {
|
||||||
|
globalStore.selectedTrainId = id;
|
||||||
|
globalStore.selectedActiveTrain = queryTrain;
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function loadStorageTimetables() {
|
function loadStorageTimetables() {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
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"
|
:disabled="apiStore.activeDataStatus != DataStatus.SUCCESS"
|
||||||
v-model="selectedTrainId"
|
v-model="globalStore.selectedTrainId"
|
||||||
v-if="globalStore.viewMode == 'active'"
|
v-if="globalStore.viewMode == 'active'"
|
||||||
@change="selectTrain"
|
@change="selectTrain"
|
||||||
>
|
>
|
||||||
@@ -76,9 +76,6 @@ import type { TimetableData } from '../../types/common.types';
|
|||||||
const apiStore = useApiStore();
|
const apiStore = useApiStore();
|
||||||
const globalStore = useGlobalStore();
|
const globalStore = useGlobalStore();
|
||||||
|
|
||||||
// Variables & refs
|
|
||||||
let selectedTrainId = ref(null) as Ref<string | null>;
|
|
||||||
|
|
||||||
// Computed
|
// Computed
|
||||||
const isTimetableSaved = computed(() => {
|
const isTimetableSaved = computed(() => {
|
||||||
if (!globalStore.currentTimetableData) return false;
|
if (!globalStore.currentTimetableData) return false;
|
||||||
@@ -90,7 +87,7 @@ const isTimetableSaved = computed(() => {
|
|||||||
function selectTrain() {
|
function selectTrain() {
|
||||||
if (!apiStore.activeData) return;
|
if (!apiStore.activeData) return;
|
||||||
|
|
||||||
globalStore.selectedActiveTrain = globalStore.activeTimetableTrains.find((train) => train.id == selectedTrainId.value) ?? null;
|
globalStore.selectedActiveTrain = globalStore.activeTimetableTrains.find((train) => train.id == globalStore.selectedTrainId) ?? null;
|
||||||
|
|
||||||
if (globalStore.selectedActiveTrain != null) {
|
if (globalStore.selectedActiveTrain != null) {
|
||||||
globalStore.generatedDate = new Date();
|
globalStore.generatedDate = new Date();
|
||||||
|
|||||||
@@ -41,7 +41,8 @@ export const useApiStore = defineStore('api', {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.fetchSceneriesData();
|
this.fetchSceneriesData();
|
||||||
this.fetchActiveData();
|
await this.fetchActiveData();
|
||||||
|
|
||||||
|
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
this.fetchActiveData();
|
this.fetchActiveData();
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ export const useGlobalStore = defineStore('global', {
|
|||||||
darkMode: false,
|
darkMode: false,
|
||||||
viewMode: 'active' as ViewMode,
|
viewMode: 'active' as ViewMode,
|
||||||
|
|
||||||
|
selectedTrainId: null as string | null,
|
||||||
selectedActiveTrain: null as ActiveTrain | null,
|
selectedActiveTrain: null as ActiveTrain | null,
|
||||||
selectedStorageTimetable: null as TimetableData | null,
|
selectedStorageTimetable: null as TimetableData | null,
|
||||||
storageTimetables: {} as Record<number, TimetableData>,
|
storageTimetables: {} as Record<number, TimetableData>,
|
||||||
|
|||||||
Reference in New Issue
Block a user