From dbca46f1c5203929a701a53e1af78d118bdec153 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4ki?= Date: Wed, 20 Mar 2024 16:32:48 +0200 Subject: [PATCH 1/2] Move apiConnectionError from main Vuex store to TsModsModule The error is shown on the UI when manually triggered udpating of the mod list from Thunderstore API fails, so the module which handles all that is more suitable location for managing the error message. --- src/components/settings-components/SettingsView.vue | 9 ++++----- src/store/index.ts | 8 -------- src/store/modules/TsModsModule.ts | 11 +++++++++++ 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/components/settings-components/SettingsView.vue b/src/components/settings-components/SettingsView.vue index d793d501e..afa8829fd 100644 --- a/src/components/settings-components/SettingsView.vue +++ b/src/components/settings-components/SettingsView.vue @@ -295,8 +295,8 @@ import UtilityMixin from '../mixins/UtilityMixin.vue'; if (this.downloadingThunderstoreModList) { return "Checking for new releases"; } - if (this.$store.state.apiConnectionError.length > 0) { - return "Error getting new mods: " + this.$store.state.apiConnectionError; + if (this.$store.state.tsMods.connectionError.length > 0) { + return "Error getting new mods: " + this.$store.state.tsMods.connectionError; } if (this.$store.state.tsMods.modsLastUpdated !== undefined) { return "Cache date: " + moment(this.$store.state.tsMods.modsLastUpdated).format("MMMM Do YYYY, h:mm:ss a"); @@ -307,13 +307,12 @@ import UtilityMixin from '../mixins/UtilityMixin.vue'; async () => { if (!this.downloadingThunderstoreModList) { this.downloadingThunderstoreModList = true; - await this.$store.dispatch("updateApiConnectionError", ""); + this.$store.commit("tsMods/setConnectionError", ""); try { await this.refreshThunderstoreModList(); } catch (e) { - const err = e instanceof Error ? e.message : "Unknown error"; - await this.$store.dispatch("updateApiConnectionError", err); + this.$store.commit("tsMods/setConnectionError", e); } finally { this.downloadingThunderstoreModList = false; } diff --git a/src/store/index.ts b/src/store/index.ts index f46eefff5..62b9fb7fd 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -16,7 +16,6 @@ Vue.use(Vuex); export interface State { activeGame: Game; - apiConnectionError: string; dismissedUpdateAll: boolean; isMigrationChecked: boolean; _settings: ManagerSettings | null; @@ -34,7 +33,6 @@ export const store = { activeGame: GameManager.defaultGame, dismissedUpdateAll: false, isMigrationChecked: false, - apiConnectionError: "", // Access through getters to ensure the settings are loaded. _settings: null, @@ -43,9 +41,6 @@ export const store = { dismissUpdateAll({commit}: Context) { commit('dismissUpdateAll'); }, - updateApiConnectionError({commit}: Context, err: string) { - commit('setApiConnectionError', err); - }, async checkMigrations({commit, state}: Context) { if (state.isMigrationChecked) { return; @@ -84,9 +79,6 @@ export const store = { setMigrationChecked(state: State) { state.isMigrationChecked = true; }, - setApiConnectionError(state: State, err: string) { - state.apiConnectionError = err; - }, setSettings(state: State, settings: ManagerSettings) { state._settings = settings; } diff --git a/src/store/modules/TsModsModule.ts b/src/store/modules/TsModsModule.ts index 307a4b71d..7efb728fa 100644 --- a/src/store/modules/TsModsModule.ts +++ b/src/store/modules/TsModsModule.ts @@ -15,6 +15,7 @@ interface CachedMod { interface State { cache: Map; + connectionError: string; deprecated: Map; exclusions?: string[]; mods: ThunderstoreMod[]; @@ -32,6 +33,8 @@ export const TsModsModule = { state: (): State => ({ cache: new Map(), + /*** Error shown on UI after manual mod list refresh fails */ + connectionError: '', deprecated: new Map(), /*** Packages available through API that should be ignored by the manager */ exclusions: [], @@ -113,6 +116,14 @@ export const TsModsModule = { clearModCache(state) { state.cache.clear(); }, + setConnectionError(state, error: string|unknown) { + if (typeof error === 'string') { + state.connectionError = error; + } else { + const msg = error instanceof Error ? error.message : "Unknown error"; + state.connectionError = msg; + } + }, setMods(state, payload: ThunderstoreMod[]) { state.mods = payload; }, From 0d229f38e53737c618f5525707758918c8d749f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4ki?= Date: Wed, 20 Mar 2024 16:51:00 +0200 Subject: [PATCH 2/2] Move dismissedUpdateAll from main Vuex store to ProfileModule The banner for updating all mods with updates is shown on the view listing the mods in currently selected profile, so the module which handles the rest of the profile related data is a more suitabl location. --- src/components/views/InstalledModView.vue | 4 ++-- src/store/index.ts | 8 -------- src/store/modules/ProfileModule.ts | 6 ++++++ 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/components/views/InstalledModView.vue b/src/components/views/InstalledModView.vue index 29131de5d..cc7b78c60 100644 --- a/src/components/views/InstalledModView.vue +++ b/src/components/views/InstalledModView.vue @@ -24,7 +24,7 @@ You have {{ numberOfModsWithUpdates }} available mod update{{ numberOfModsWithUpdates > 1 ? "s" : ""}}. Would you like to update all? - + @@ -50,7 +50,7 @@ import LocalModListProvider from "../../providers/components/loaders/LocalModLis export default class InstalledModView extends Vue { get dismissedUpdateAll() { - return this.$store.state.dismissedUpdateAll; + return this.$store.state.profile.dismissedUpdateAll; } get localModList(): ManifestV2[] { diff --git a/src/store/index.ts b/src/store/index.ts index 62b9fb7fd..e9b3b66ee 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -16,7 +16,6 @@ Vue.use(Vuex); export interface State { activeGame: Game; - dismissedUpdateAll: boolean; isMigrationChecked: boolean; _settings: ManagerSettings | null; } @@ -31,16 +30,12 @@ type Context = ActionContext; export const store = { state: { activeGame: GameManager.defaultGame, - dismissedUpdateAll: false, isMigrationChecked: false, // Access through getters to ensure the settings are loaded. _settings: null, }, actions: { - dismissUpdateAll({commit}: Context) { - commit('dismissUpdateAll'); - }, async checkMigrations({commit, state}: Context) { if (state.isMigrationChecked) { return; @@ -73,9 +68,6 @@ export const store = { setActiveGame(state: State, game: Game) { state.activeGame = game; }, - dismissUpdateAll(state: State) { - state.dismissedUpdateAll = true; - }, setMigrationChecked(state: State) { state.isMigrationChecked = true; }, diff --git a/src/store/modules/ProfileModule.ts b/src/store/modules/ProfileModule.ts index ec1d1333b..60ce884f3 100644 --- a/src/store/modules/ProfileModule.ts +++ b/src/store/modules/ProfileModule.ts @@ -24,6 +24,7 @@ interface State { direction?: SortDirection; disabledPosition?: SortLocalDisabledMods; searchQuery: string; + dismissedUpdateAll: boolean; } /** @@ -41,6 +42,7 @@ export default { direction: undefined, disabledPosition: undefined, searchQuery: '', + dismissedUpdateAll: false, }), getters: >{ @@ -112,6 +114,10 @@ export default { }, mutations: { + dismissUpdateAll(state: State) { + state.dismissedUpdateAll = true; + }, + // Use updateActiveProfile action to ensure the persistent // settings are updated. setActiveProfile(state: State, profileName: string) {