Skip to content

Commit 4424be2

Browse files
committed
Add ModListUpdateBanner
The banner will show on top of an empty online mod list, explaining that the list is empty because splash screen failed to load it. A one-click option for trying to update the mod list is offered. This change is adjustment to the fact that the splash screen no longer stops on errors and user is more likely to reach the manager view with no mod list loaded into Vuex.
1 parent 0ce7372 commit 4424be2

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<script lang="ts">
2+
import { mixins } from 'vue-class-component';
3+
import { Component, Watch } from 'vue-property-decorator';
4+
5+
import UtilityMixin from './mixins/UtilityMixin.vue';
6+
import ManagerInformation from '../_managerinf/ManagerInformation';
7+
8+
@Component({})
9+
export default class ModListUpdateBanner extends mixins(UtilityMixin) {
10+
updateError = '';
11+
12+
get appName(): string {
13+
return ManagerInformation.APP_NAME;
14+
}
15+
16+
get isModListLoaded(): boolean {
17+
return this.$store.state.tsMods.modsLastUpdated !== undefined;
18+
}
19+
20+
get isUpdateInProgress(): boolean {
21+
return this.$store.state.tsMods.isBackgroundUpdateInProgress;
22+
}
23+
24+
@Watch('isUpdateInProgress')
25+
onLoadingProgressChange(newVal: boolean, oldVal: boolean) {
26+
// React to background update as well as the manual update from the banner.
27+
if (!oldVal && newVal) {
28+
this.updateError = '';
29+
}
30+
}
31+
32+
async updateModList() {
33+
if (this.isUpdateInProgress) {
34+
return;
35+
}
36+
37+
this.$store.commit('tsMods/startBackgroundUpdate');
38+
this.updateError = '';
39+
40+
try {
41+
// Invalidate hash to force a refresh. Otherwise a scenario where
42+
// the latest index hash is already present in IndexedDB but loading
43+
// the package list into Vuex store has failed would cause the banner
44+
// to just disappear when refreshThunderstoreModList skips the actual
45+
// update but updates the timestamp of the hash.
46+
await this.$store.dispatch('tsMods/updateIndexHash', 'invalidated');
47+
await this.refreshThunderstoreModList();
48+
} catch (e) {
49+
this.updateError = `${e}`;
50+
} finally {
51+
this.$store.commit('tsMods/finishBackgroundUpdate');
52+
}
53+
}
54+
}
55+
</script>
56+
57+
<template>
58+
<div v-if="!isModListLoaded" id="mod-list-update-banner" class="margin-bottom">
59+
<div class="notification is-warning margin-right">
60+
<span v-if="isUpdateInProgress">
61+
Updating mod list from Thunderstore...
62+
</span>
63+
<span v-else-if="updateError">
64+
Error updating the mod list: {{ updateError }}<br />
65+
{{ appName }} will keep trying to update the mod list in the background.
66+
</span>
67+
<span v-else>
68+
It seems like the latest mod list hasn't been loaded from Thunderstore yet.
69+
Would you like to
70+
<a @click="updateModList">update now</a>?
71+
</span>
72+
</div>
73+
</div>
74+
</template>
75+
76+
<style scoped lang="scss">
77+
78+
</style>

src/components/views/OnlineModView.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
</div>
4444
</div>
4545
</div>
46+
<ModListUpdateBanner />
4647
<OnlineModList
4748
:local-mod-list="localModList"
4849
:paged-mod-list="pagedThunderstoreModList"
@@ -78,10 +79,12 @@ import OnlineModListProvider from '../../providers/components/loaders/OnlineModL
7879
import SearchUtils from '../../utils/SearchUtils';
7980
import PaginationButtons from "../navigation/PaginationButtons.vue";
8081
import { DeferredInput } from "../all";
82+
import ModListUpdateBanner from "../ModListUpdateBanner.vue";
8183
8284
@Component({
8385
components: {
8486
DeferredInput,
87+
ModListUpdateBanner,
8588
OnlineModList: OnlineModListProvider.provider,
8689
PaginationButtons,
8790
}

0 commit comments

Comments
 (0)