Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move vuex items to more suitable modules #1278

Merged
merged 2 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/components/settings-components/SettingsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/views/InstalledModView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
You have {{ numberOfModsWithUpdates }} available mod update{{ numberOfModsWithUpdates > 1 ? "s" : ""}}.
Would you like to <a @click="$store.commit('openUpdateAllModsModal')">update all</a>?
</span>
<a class="float-right cursor-pointer" @click="$store.dispatch('dismissUpdateAll')">
<a class="float-right cursor-pointer" @click="$store.commit('profile/dismissUpdateAll')">
<i class="fas fa-times" />
</a>
</div>
Expand 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[] {
Expand Down
16 changes: 0 additions & 16 deletions src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ Vue.use(Vuex);

export interface State {
activeGame: Game;
apiConnectionError: string;
dismissedUpdateAll: boolean;
isMigrationChecked: boolean;
_settings: ManagerSettings | null;
}
Expand All @@ -32,20 +30,12 @@ type Context = ActionContext<State, State>;
export const store = {
state: {
activeGame: GameManager.defaultGame,
dismissedUpdateAll: false,
isMigrationChecked: false,
apiConnectionError: "",

// Access through getters to ensure the settings are loaded.
_settings: null,
},
actions: {
dismissUpdateAll({commit}: Context) {
commit('dismissUpdateAll');
},
updateApiConnectionError({commit}: Context, err: string) {
commit('setApiConnectionError', err);
},
async checkMigrations({commit, state}: Context) {
if (state.isMigrationChecked) {
return;
Expand Down Expand Up @@ -78,15 +68,9 @@ export const store = {
setActiveGame(state: State, game: Game) {
state.activeGame = game;
},
dismissUpdateAll(state: State) {
state.dismissedUpdateAll = true;
},
setMigrationChecked(state: State) {
state.isMigrationChecked = true;
},
setApiConnectionError(state: State, err: string) {
state.apiConnectionError = err;
},
setSettings(state: State, settings: ManagerSettings) {
state._settings = settings;
}
Expand Down
6 changes: 6 additions & 0 deletions src/store/modules/ProfileModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ interface State {
direction?: SortDirection;
disabledPosition?: SortLocalDisabledMods;
searchQuery: string;
dismissedUpdateAll: boolean;
}

/**
Expand All @@ -41,6 +42,7 @@ export default {
direction: undefined,
disabledPosition: undefined,
searchQuery: '',
dismissedUpdateAll: false,
}),

getters: <GetterTree<State, RootState>>{
Expand Down Expand Up @@ -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) {
Expand Down
11 changes: 11 additions & 0 deletions src/store/modules/TsModsModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface CachedMod {

interface State {
cache: Map<string, CachedMod>;
connectionError: string;
deprecated: Map<string, boolean>;
exclusions?: string[];
mods: ThunderstoreMod[];
Expand All @@ -32,6 +33,8 @@ export const TsModsModule = {

state: (): State => ({
cache: new Map<string, CachedMod>(),
/*** Error shown on UI after manual mod list refresh fails */
connectionError: '',
deprecated: new Map<string, boolean>(),
/*** Packages available through API that should be ignored by the manager */
exclusions: [],
Expand Down Expand Up @@ -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;
},
Expand Down
Loading