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 16, 2024
1 parent 762be48 commit f7ca8c1
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/pages/GameSelectionScreen.vue
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,8 @@ export default class GameSelectionScreen extends Vue {
await this.$store.dispatch('checkMigrations');
this.runningMigration = false;
await this.$store.dispatch('resetProfileModule');
await this.$store.dispatch('resetLocalState');
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 @@ -115,6 +115,10 @@ export default class Profiles extends ProfilesMixin {
const settings = await this.$store.getters.settings;
await settings.load();
await this.$store.commit('modFilters/reset');
await this.$store.commit('tsMods/reset');
await this.$store.commit('profile/reset');
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: 6 additions & 4 deletions src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,12 @@ export const store = {
return settings;
},

// TODO: Add reset actions for other modules
async resetProfileModule({dispatch}: Context) {
return await dispatch('profile/reset');
}
async resetLocalState({commit}: Context) {
commit('profile/reset');
commit('profiles/reset');
commit('tsMods/reset');
commit('modFilters/reset');
},
},
mutations: {
setActiveGame(state: State, game: Game) {
Expand Down
2 changes: 1 addition & 1 deletion src/store/modules/ModFilterModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 2 additions & 6 deletions 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 Expand Up @@ -120,7 +119,8 @@ export default {
},

mutations: {
resetLocalState(state: State) {
reset(state: State) {
state.activeProfile = null;
state.modList = [];
state.order = undefined;
state.direction = undefined;
Expand Down Expand Up @@ -302,10 +302,6 @@ export default {
commit('setDisabledPosition', settings.getInstalledDisablePosition());
},

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

async resolveConflicts(
{},
params: {
Expand Down
3 changes: 3 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 addProfile({rootGetters, state, dispatch}, name: string) {
Expand Down
8 changes: 8 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

0 comments on commit f7ca8c1

Please sign in to comment.