From d06f2d5d2ec5a794ddf072b28252e09e17c7bced Mon Sep 17 00:00:00 2001 From: Spythere Date: Wed, 21 Dec 2022 18:10:54 +0100 Subject: [PATCH] Optymalizacja pobierania danych --- src/views/JournalDispatchers.vue | 60 +++++++++++++++++--------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/src/views/JournalDispatchers.vue b/src/views/JournalDispatchers.vue index 9d5c5b5..a3970dd 100644 --- a/src/views/JournalDispatchers.vue +++ b/src/views/JournalDispatchers.vue @@ -4,7 +4,7 @@
elementHeight * 0.85) this.addHistoryData(); }, - resetOptions() { - this.searchersValues['search-station'] = ''; - this.searchersValues['search-dispatcher'] = ''; - this.searchersValues['search-date'] = ''; - this.sorterActive.id = 'timestampFrom'; - - this.searchHistory(); + handleQueries(query: LocationQuery) { + if ('sceneryName' in query) this.searchersValues['search-station'] = `${query.sceneryName}`; + if ('dispatcherName' in query) this.searchersValues['search-dispatcher'] = `${query.dispatcherName}`; }, - searchHistory() { - this.fetchHistoryData({ - searchers: this.searchersValues, - }); + setSearchers(date: string, station: string, dispatcher: string) { + this.searchersValues['search-date'] = date; + this.searchersValues['search-station'] = station; + this.searchersValues['search-dispatcher'] = dispatcher; + }, - this.scrollNoMoreData = false; - this.scrollDataLoaded = true; + resetOptions() { + this.setSearchers('', '', ''); + this.sorterActive.id = 'timestampFrom'; + + this.fetchHistoryData(); }, async addHistoryData() { @@ -223,19 +226,15 @@ export default defineComponent({ this.scrollDataLoaded = true; }, - async fetchHistoryData( - props: { - searchers?: JournalDispatcherSearcher; - filter?: JournalTimetableFilter; - } = {} - ) { + async fetchHistoryData() { this.dataStatus = DataStatus.Loading; const queries: string[] = []; - const dispatcher = props.searchers?.['search-dispatcher'].trim(); - const station = props.searchers?.['search-station'].trim(); - const dateString = props.searchers?.['search-date'].trim(); + const dispatcher = this.searchersValues['search-dispatcher'].trim(); + const station = this.searchersValues['search-station'].trim(); + const dateString = this.searchersValues['search-date'].trim(); + const timestampFrom = dateString ? Date.parse(new Date(dateString).toISOString()) - 120 * 60 * 1000 : undefined; const timestampTo = timestampFrom ? timestampFrom + 86400000 : undefined; @@ -278,6 +277,9 @@ export default defineComponent({ } catch (error) { this.dataStatus = DataStatus.Error; } + + this.scrollNoMoreData = false; + this.scrollDataLoaded = true; }, }, });