From b3ee8bd1190ace73a088dac7330711ad1cf7f5e0 Mon Sep 17 00:00:00 2001 From: Spythere Date: Tue, 29 Apr 2025 01:55:09 +0200 Subject: [PATCH] chore: fetching data --- dev-dist/sw.js | 2 +- src/components/App/MainContainer.vue | 4 +- .../TimetableSearch/ActiveSearchInput.vue | 41 ++++++ .../TimetableSearch/JournalSearchInput.vue | 130 ++++++++++++++++++ .../TimetableSearch/LocalSearchInput.vue | 33 +++++ .../TimetableSearch/SearchContainer.vue | 26 ++++ .../SearchModeActions.vue} | 76 +--------- .../TimetableViews/JournalStorageView.vue | 22 ++- src/locales/pl.json | 4 +- src/stores/api.store.ts | 81 +---------- src/stores/global.store.ts | 7 +- src/types/common.types.ts | 6 - 12 files changed, 270 insertions(+), 162 deletions(-) create mode 100644 src/components/TimetableSearch/ActiveSearchInput.vue create mode 100644 src/components/TimetableSearch/JournalSearchInput.vue create mode 100644 src/components/TimetableSearch/LocalSearchInput.vue create mode 100644 src/components/TimetableSearch/SearchContainer.vue rename src/components/{Timetable/TimetableSelect.vue => TimetableSearch/SearchModeActions.vue} (64%) diff --git a/dev-dist/sw.js b/dev-dist/sw.js index 7069aab..16cfcc7 100644 --- a/dev-dist/sw.js +++ b/dev-dist/sw.js @@ -82,7 +82,7 @@ define(['./workbox-99d8380f'], (function (workbox) { 'use strict'; */ workbox.precacheAndRoute([{ "url": "index.html", - "revision": "0.ah6c8rh4s38" + "revision": "0.2ul174kd9vo" }], {}); workbox.cleanupOutdatedCaches(); workbox.registerRoute(new workbox.NavigationRoute(workbox.createHandlerBoundToURL("index.html"), { diff --git a/src/components/App/MainContainer.vue b/src/components/App/MainContainer.vue index 8220539..58d26a9 100644 --- a/src/components/App/MainContainer.vue +++ b/src/components/App/MainContainer.vue @@ -1,13 +1,13 @@ diff --git a/src/components/TimetableSearch/ActiveSearchInput.vue b/src/components/TimetableSearch/ActiveSearchInput.vue new file mode 100644 index 0000000..a0d30d1 --- /dev/null +++ b/src/components/TimetableSearch/ActiveSearchInput.vue @@ -0,0 +1,41 @@ + + + diff --git a/src/components/TimetableSearch/JournalSearchInput.vue b/src/components/TimetableSearch/JournalSearchInput.vue new file mode 100644 index 0000000..444b4d8 --- /dev/null +++ b/src/components/TimetableSearch/JournalSearchInput.vue @@ -0,0 +1,130 @@ + + + diff --git a/src/components/TimetableSearch/LocalSearchInput.vue b/src/components/TimetableSearch/LocalSearchInput.vue new file mode 100644 index 0000000..83311e0 --- /dev/null +++ b/src/components/TimetableSearch/LocalSearchInput.vue @@ -0,0 +1,33 @@ + + + diff --git a/src/components/TimetableSearch/SearchContainer.vue b/src/components/TimetableSearch/SearchContainer.vue new file mode 100644 index 0000000..eae413e --- /dev/null +++ b/src/components/TimetableSearch/SearchContainer.vue @@ -0,0 +1,26 @@ + + + diff --git a/src/components/Timetable/TimetableSelect.vue b/src/components/TimetableSearch/SearchModeActions.vue similarity index 64% rename from src/components/Timetable/TimetableSelect.vue rename to src/components/TimetableSearch/SearchModeActions.vue index c5ee60a..c707826 100644 --- a/src/components/Timetable/TimetableSelect.vue +++ b/src/components/TimetableSearch/SearchModeActions.vue @@ -1,5 +1,5 @@ diff --git a/src/components/TimetableViews/JournalStorageView.vue b/src/components/TimetableViews/JournalStorageView.vue index 4a98da9..3d638ee 100644 --- a/src/components/TimetableViews/JournalStorageView.vue +++ b/src/components/TimetableViews/JournalStorageView.vue @@ -66,11 +66,29 @@ diff --git a/src/locales/pl.json b/src/locales/pl.json index 7d9a6ae..e7e38b3 100644 --- a/src/locales/pl.json +++ b/src/locales/pl.json @@ -36,7 +36,9 @@ "journal-preview-title": "DZIENNIK ROZKŁADÓW JAZDY", "journal-empty-info": "Wpisz dane rozkładu korzystając z pola tekstowego powyżej - mogą nimi być:
id (#numer); nickname (nick:Spythere); data (date:11.01.2025); punkt startowy (from:Krnów)
W przypadku wielu rozkładów jazdy wyświetli się maks. 15 najnowszych.", - "journal-search-placeholder": "nick:Spythere date:02.04.2025 from:Krnów to:Biała_Sudecka", + "journal-driver-search-placeholder": "Maszynista / #ID", + "journal-date-search-placeholder": "Data", + "journal-route-search-placeholder": "Relacja", "journal-preview-info": "Rozkład historyczny {id} maszynisty {driverName} z dnia {date}", "journal-no-data": "Brak wyników dla obecnego wyszukiwania! Sprawdź czy wpisałeś poprawnie dane.", diff --git a/src/stores/api.store.ts b/src/stores/api.store.ts index a9e79f4..e749e29 100644 --- a/src/stores/api.store.ts +++ b/src/stores/api.store.ts @@ -4,16 +4,9 @@ import { defineStore } from 'pinia'; import { DataStatus, type ActiveDataResponse, - type SceneriesDataResponse, - type JournalTimetablesShortResponse + type SceneriesDataResponse } from '../types/api.types'; -import type { - ActiveData, - JournalTimetableDetailed, - JournalTimetableShort, - SceneryData -} from '../types/common.types'; -import { useGlobalStore } from './global.store'; +import type { ActiveData, JournalTimetableShort, SceneryData } from '../types/common.types'; let activeDataInterval = -1; @@ -58,7 +51,7 @@ export const useApiStore = defineStore('api', { } clearInterval(activeDataInterval); - + activeDataInterval = setInterval(() => { this.fetchActiveData(); }, 25000); @@ -93,74 +86,6 @@ export const useApiStore = defineStore('api', { } catch (error) { console.error(error); } - }, - - async fetchJournalTimetables(searchValue: string) { - // if (searchValue.trim().length == 0) { - // this.journalDataStatus = DataStatus.SUCCESS; - // this.journalTimetablesData = null; - - // return; - // } - - let searchObj: Record = {}; - const searchParams = searchValue.split(' '); - - searchParams.forEach((param) => { - const [key, value] = param.split(':'); - - if (key == 'nick') searchObj['driverName'] = value; - else if (key == 'date') { - let dateFromStr = new Date(value).toISOString(); - - let dateTo = new Date(dateFromStr); - dateTo.setDate(dateTo.getDate() + 1); - - searchObj['dateFrom'] = dateFromStr; - searchObj['dateTo'] = dateTo.toISOString(); - } else if (key == 'from') searchObj['issuedFrom'] = value.replace(/_/g, ' '); - else if (key == 'to') searchObj['terminatingAt'] = value.replace(/_/g, ' '); - }); - - searchObj['hasStopsDetails'] = 1; - searchObj['returnType'] = 'short'; - - try { - this.journalDataStatus = DataStatus.LOADING; - - const response = ( - await this.client!.get('/api/getTimetables', { - params: searchObj - }) - ).data; - - this.journalDataStatus = DataStatus.SUCCESS; - this.journalTimetablesData = response; - } catch (error) { - this.journalDataStatus = DataStatus.ERROR; - this.journalTimetablesData = null; - console.error(error); - } - }, - - async fetchJournalTimetableDetails(id: number) { - const globalStore = useGlobalStore(); - - try { - const response = ( - await this.client!.get('/api/getTimetables', { - params: { - timetableId: id, - hasStopsDetails: 1 - } - }) - ).data; - - if (response.length > 0) globalStore.selectedJournalTimetable = response[0]; - } catch (error) { - globalStore.selectedJournalTimetable = null; - console.error(error); - } } } }); diff --git a/src/stores/global.store.ts b/src/stores/global.store.ts index 1a5e6a2..0faa329 100644 --- a/src/stores/global.store.ts +++ b/src/stores/global.store.ts @@ -26,7 +26,12 @@ export const useGlobalStore = defineStore('global', { generatedMs: 0, localTimetableSearch: '', - journalTimetableSearch: '', + + journalTimetableSearch: { + driverName: '', + date: '', + route: '' + }, showSettings: false }), diff --git a/src/types/common.types.ts b/src/types/common.types.ts index 975a636..fd2cb5c 100644 --- a/src/types/common.types.ts +++ b/src/types/common.types.ts @@ -1,10 +1,5 @@ export type ViewMode = 'active' | 'storage' | 'journal'; -export enum StorageMode { - LOCAL = 'local', - API = 'api' -} - export interface ActiveData { trains: ActiveTrain[]; activeSceneries: ActiveScenery[]; @@ -228,7 +223,6 @@ export interface JournalTimetableDetailed extends JournalTimetableShort { createdAt: string; updatedAt: string; stockHistory: string[]; - hidden: boolean; routeSceneries: string; checkpointArrivals: any[]; checkpointDepartures: any[];