Skip to content

Commit

Permalink
Add data resetting to vuex storage modules and use the functionality …
Browse files Browse the repository at this point in the history
…in page components
  • Loading branch information
VilppeRiskidev committed Sep 11, 2024
1 parent 03e2f40 commit bc2c05f
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/pages/GameSelectionScreen.vue
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,11 @@ export default class GameSelectionScreen extends Vue {
await this.$store.dispatch('checkMigrations');
this.runningMigration = false;
await this.$store.dispatch('resetModFilterModule');
await this.$store.dispatch('resetTsModsModule');
await this.$store.dispatch('resetProfileModule');
await this.$store.dispatch('resetProfilesModule');
this.settings = await ManagerSettings.getSingleton(GameManager.defaultGame);
const globalSettings = this.settings.getContext().global;
this.favourites = globalSettings.favouriteGames || [];
Expand Down
4 changes: 4 additions & 0 deletions src/pages/Profiles.vue
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,10 @@ export default class Profiles extends Vue {
const settings = await this.$store.getters.settings;
await settings.load();
await this.$store.dispatch('resetModFilterModule');
await this.$store.dispatch('resetTsModsModule');
await this.$store.dispatch('resetProfileModule');
const lastProfileName = await this.$store.dispatch('profile/loadLastSelectedProfile');
// If the view was entered via game selection, the mod list was updated
Expand Down
10 changes: 9 additions & 1 deletion src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,17 @@ export const store = {
return settings;
},

// TODO: Add reset actions for other modules
async resetProfileModule({dispatch}: Context) {
return await dispatch('profile/reset');
},
async resetProfilesModule({dispatch}: Context) {
return await dispatch('profiles/reset');
},
async resetTsModsModule({dispatch}: Context) {
return await dispatch('tsMods/reset');
},
async resetModFilterModule({dispatch}: Context) {
return await dispatch('modFilters/reset');
}
},
mutations: {
Expand Down
10 changes: 8 additions & 2 deletions src/store/modules/ModFilterModule.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GetterTree } from 'vuex';
import { ActionTree, GetterTree } from 'vuex';

import { State as RootState } from '../index';

Expand All @@ -11,7 +11,7 @@ interface State {
}

/**
* State for OnlineModList, i.e. list for all the mods available on Thunderstore.
* State for ModFilter, i.e. filters for mod listings.
*/
export default {
namespaced: true,
Expand Down Expand Up @@ -70,4 +70,10 @@ export default {
state.showDeprecatedPackages = value;
},
},

actions: <ActionTree<State, RootState>>{
async reset({commit}) {
commit('reset');
}
}
}
1 change: 0 additions & 1 deletion src/store/modules/ProfileModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import ManagerSettings from '../../r2mm/manager/ManagerSettings';
import ModListSort from '../../r2mm/mods/ModListSort';
import ProfileModList from '../../r2mm/mods/ProfileModList';
import SearchUtils from '../../utils/SearchUtils';
import GameManager from "../../model/game/GameManager";

interface State {
activeProfile: Profile | null;
Expand Down
7 changes: 7 additions & 0 deletions src/store/modules/ProfilesModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export const ProfilesModule = {
setProfileList(state: State, profileList: string[]) {
state.profileList = profileList;
},
reset(state: State) {
state.profileList = ['Default'];
},
},
actions: <ActionTree<State, RootState>>{
async removeSelectedProfile({rootGetters, state, dispatch}) {
Expand All @@ -41,6 +44,10 @@ export const ProfilesModule = {
await dispatch('setSelectedProfile', { profileName: 'Default', prewarmCache: true });
},

async reset({commit}) {
commit('reset');
},

async setSelectedProfile({rootGetters, state, dispatch}, params: { profileName: string, prewarmCache: boolean }) {
await dispatch('profile/updateActiveProfile', params.profileName, { root: true });

Expand Down
12 changes: 12 additions & 0 deletions src/store/modules/TsModsModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ export const TsModsModule = {
},

mutations: <MutationTree<State>>{
reset(state: State) {
state.cache = new Map<string, CachedMod>();
state.connectionError = '';
state.deprecated = new Map<string, boolean>();
state.exclusions = [];
state.mods = [];
state.modsLastUpdated = undefined;
},
clearModCache(state) {
state.cache.clear();
},
Expand Down Expand Up @@ -153,6 +161,10 @@ export const TsModsModule = {
profileMods.forEach(getters['cachedMod']);
},

async reset({commit}) {
commit('reset');
},

async updateExclusions(
{commit},
progressCallback?: (progress: number) => void
Expand Down

0 comments on commit bc2c05f

Please sign in to comment.