Skip to content

Commit e62b2e6

Browse files
Simplify DownloadMonitor by getting rid of timeout
and instead calling the Vuex store directly in the template
1 parent 20c4366 commit e62b2e6

File tree

2 files changed

+6
-19
lines changed

2 files changed

+6
-19
lines changed

Diff for: src/pages/DownloadMonitor.vue

+2-18
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div>
33
<Hero title="Downloads" subtitle="Monitor progress of downloads" hero-type="primary"/>
4-
<template v-if="activeDownloads.length === 0">
4+
<template v-if="$store.state.download.allDownloads.length === 0">
55
<div class='text-center top'>
66
<div class="margin-right">
77
<br/>
@@ -13,7 +13,7 @@
1313
</div>
1414
</template>
1515
<template v-else>
16-
<div v-for="(downloadObject, index) of activeDownloads" :key="`download-progress-${index}`">
16+
<div v-for="(downloadObject, index) of $store.getters['download/newestFirst']" :key="`download-progress-${index}`">
1717
<div>
1818
<div class="container margin-right">
1919
<div class="border-at-bottom pad pad--sides">
@@ -42,12 +42,10 @@
4242

4343
<script lang="ts">
4444
45-
import Timeout = NodeJS.Timeout;
4645
import { Component, Vue } from 'vue-property-decorator';
4746
4847
import { Hero } from '../components/all';
4948
import Progress from '../components/Progress.vue';
50-
import { DownloadProgress } from "../store/modules/DownloadModule";
5149
5250
@Component({
5351
components: {
@@ -56,20 +54,6 @@ import { DownloadProgress } from "../store/modules/DownloadModule";
5654
}
5755
})
5856
export default class DownloadMonitor extends Vue {
59-
private refreshInterval!: Timeout;
60-
private activeDownloads: DownloadProgress[] = [];
61-
62-
created() {
63-
this.activeDownloads = [...this.$store.state.download.allDownloads].reverse();
64-
this.refreshInterval = setInterval(() => {
65-
this.activeDownloads = [...this.$store.state.download.allDownloads].reverse();
66-
}, 100);
67-
}
68-
69-
destroyed() {
70-
clearInterval(this.refreshInterval);
71-
}
72-
7357
}
7458
7559
</script>

Diff for: src/store/modules/DownloadModule.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ActionTree, GetterTree } from "vuex";
33
import { State as RootState } from "../../store";
44
import R2Error from "../../model/errors/R2Error";
55

6-
export interface DownloadProgress {
6+
interface DownloadProgress {
77
assignId: number;
88
initialMods: string[];
99
modName: string;
@@ -59,6 +59,9 @@ export const DownloadModule = {
5959
currentDownload(state) {
6060
return state.allDownloads[state.allDownloads.length-1] || null;
6161
},
62+
newestFirst(state) {
63+
return Array.from(state.allDownloads).reverse();
64+
},
6265
},
6366

6467
mutations: {

0 commit comments

Comments
 (0)