feature: nieskończona lista historii dr/rj scenerii

This commit is contained in:
2023-06-24 13:46:37 +02:00
parent 6ceae3f161
commit 96d64e77fc
3 changed files with 72 additions and 13 deletions
@@ -2,7 +2,7 @@
<section class="scenery-timetables-history scenery-section">
<Loading v-if="dataStatus != 2" />
<table class="scenery-history-table" v-else-if="sceneryHistoryList.length">
<table class="scenery-history-table" v-else-if="historyList.length">
<thead>
<th>{{ $t('scenery.timetables-history-id') }}</th>
<th>{{ $t('scenery.timetables-history-number') }}</th>
@@ -13,7 +13,7 @@
</thead>
<tbody>
<tr v-for="historyItem in sceneryHistoryList">
<tr v-for="historyItem in historyList">
<td>
<router-link :to="`/journal/timetables?timetableId=${historyItem.id}`">#{{ historyItem.id }}</router-link>
</td>
@@ -40,6 +40,7 @@
</table>
<div class="no-history" v-else>{{ $t('scenery.history-list-empty') }}</div>
<div ref="bottomDiv"></div>
</section>
</template>
@@ -52,37 +53,54 @@ import { TimetableHistory, SceneryTimetableHistory } from '../../scripts/interfa
import Station from '../../scripts/interfaces/Station';
import { URLs } from '../../scripts/utils/apiURLs';
import Loading from '../Global/Loading.vue';
import listObserverMixin from '../../mixins/listObserverMixin';
export default defineComponent({
name: 'SceneryTimetablesHistory',
mixins: [dateMixin],
mixins: [dateMixin, listObserverMixin],
props: {
station: {
type: Object as PropType<Station>,
required: true,
},
},
data() {
return {
sceneryHistoryList: [] as TimetableHistory[],
historyList: [] as TimetableHistory[],
dataStatus: DataStatus.Loading,
};
},
activated() {
this.fetchAPIData();
mounted() {
this.mountObserver(this.fireObserverAction, this.$refs['bottomDiv'] as Element);
},
unmounted() {
this.unmountObserver();
},
activated() {
if (this.historyList.length == 0) this.fetchAPIData();
},
methods: {
async fetchAPIData(countFrom = 0, countLimit = 15) {
try {
const requestString = `${URLs.stacjownikAPI}/api/getIssuedTimetables?name=${this.station.name}&countFrom=${countFrom}&countLimit=${countLimit}`;
const historyAPIData: SceneryTimetableHistory = await (await axios.get(requestString)).data;
this.sceneryHistoryList = historyAPIData.timetables;
this.historyList.push(...historyAPIData.timetables);
this.dataStatus = DataStatus.Loaded;
} catch (error) {
console.error(error);
}
},
fireObserverAction() {
if (this.historyList.length > 0 && this.dataStatus == DataStatus.Loaded)
this.fetchAPIData(this.historyList.length);
},
},
components: { Loading },
});