|
| 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> |
0 commit comments