Skip to content

Commit

Permalink
Merge pull request #1228 from ebkr/move-local-mod-list-store
Browse files Browse the repository at this point in the history
Move localModList from main Vuex store to ProfileModule
  • Loading branch information
anttimaki authored Feb 23, 2024
2 parents 0ab6a03 + 25d0c82 commit 559c89a
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 47 deletions.
2 changes: 1 addition & 1 deletion src/components/importing/LocalFileImportModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ export default class LocalFileImportModal extends Vue {
this.showError(updatedModListResult);
return;
}
await this.$store.dispatch("updateModList", updatedModListResult);
await this.$store.dispatch("profile/updateModList", updatedModListResult);
this.emitClose();
});
Expand Down
2 changes: 1 addition & 1 deletion src/components/mixins/UtilityMixin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default class UtilityMixin extends Vue {
const modList = await ProfileModList.getModList(profile);
if (!(modList instanceof R2Error)) {
this.$store.dispatch("updateModList", modList);
await this.$store.dispatch("profile/updateModList", modList);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/navigation/NavigationMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default class NavigationMenu extends Vue {
}
get localModCount(): number {
return (this.$store.state.localModList || []).length;
return this.$store.state.profile.modList.length;
}
getTagLinkClasses(routeNames: string[]) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/settings-components/SettingsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ import UtilityMixin from '../mixins/UtilityMixin.vue';
private activeGame!: Game;
get localModList(): ManifestV2[] {
return this.$store.state.localModList || [];
return this.$store.state.profile.modList;
}
get appName(): string {
Expand Down Expand Up @@ -247,7 +247,7 @@ import UtilityMixin from '../mixins/UtilityMixin.vue';
'Update all mods',
'Quickly update every installed mod to their latest versions.',
async () => {
const outdatedMods = this.$store.getters.localModsWithUpdates;
const outdatedMods = this.$store.getters['profile/modsWithUpdates'];
if (outdatedMods.length === 1) {
return "1 mod has an update available";
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/views/DownloadModModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
<p>The following mods will be downloaded and installed:</p>
<br/>
<ul class="list">
<li class="list-item" v-for='(key, index) in $store.getters.localModsWithUpdates'
<li class="list-item" v-for='(key, index) in $store.getters["profile/modsWithUpdates"]'
:key='`to-update-${index}-${key.getVersion().getFullName()}`'>
{{key.getVersion().getName()}} will be updated to: {{key.getVersion().getVersionNumber().toString()}}
</li>
Expand Down Expand Up @@ -299,7 +299,7 @@ let assignId = 0;
this.downloadingMod = false;
const modList = await ProfileModList.getModList(this.contextProfile!);
if (!(modList instanceof R2Error)) {
await this.$store.dispatch('updateModList', modList);
await this.$store.dispatch('profile/updateModList', modList);
const err = await ConflictManagementProvider.instance.resolveConflicts(modList, this.contextProfile!);
if (err instanceof R2Error) {
this.$emit('error', err);
Expand Down Expand Up @@ -360,7 +360,7 @@ let assignId = 0;
this.downloadingMod = false;
const modList = await ProfileModList.getModList(this.contextProfile!);
if (!(modList instanceof R2Error)) {
await this.$store.dispatch('updateModList', modList);
await this.$store.dispatch('profile/updateModList', modList);
const err = await ConflictManagementProvider.instance.resolveConflicts(modList, this.contextProfile!);
if (err instanceof R2Error) {
this.$emit('error', err);
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 @@ -56,11 +56,11 @@ export default class InstalledModView extends Vue {
}
get localModList(): ManifestV2[] {
return this.$store.state.localModList;
return this.$store.state.profile.modList;
}
get numberOfModsWithUpdates(): number {
return this.$store.getters.localModsWithUpdates.length;
return this.$store.getters['profile/modsWithUpdates'].length;
}
};
</script>
6 changes: 3 additions & 3 deletions src/components/views/LocalModList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ import SearchAndSort from './LocalModList/SearchAndSort.vue';
}
async updateModListAfterChange(updatedList: ManifestV2[]) {
await this.$store.dispatch("updateModList", updatedList);
await this.$store.dispatch('profile/updateModList', updatedList);
const err = await ConflictManagementProvider.instance.resolveConflicts(updatedList, this.contextProfile!);
if (err instanceof R2Error) {
Expand All @@ -130,11 +130,11 @@ import SearchAndSort from './LocalModList/SearchAndSort.vue';
}
getDependantList(mod: ManifestV2): Set<ManifestV2> {
return Dependants.getDependantList(mod, this.$store.state.localModList);
return Dependants.getDependantList(mod, this.$store.state.profile.modList);
}
getDependencyList(mod: ManifestV2): Set<ManifestV2> {
return Dependants.getDependencyList(mod, this.$store.state.localModList);
return Dependants.getDependencyList(mod, this.$store.state.profile.modList);
}
async performUninstallMod(mod: ManifestV2, updateModList=true): Promise<ManifestV2[] | R2Error> {
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/LocalModList/DisableModModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default class DisableModModal extends Vue {
modBeingDisabled: string | null = null;
get dependants() {
return Dependants.getDependantList(this.mod, this.$store.state.localModList);
return Dependants.getDependantList(this.mod, this.$store.state.profile.modList);
}
get isLocked(): boolean {
Expand Down
4 changes: 2 additions & 2 deletions src/components/views/LocalModList/LocalModCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default class LocalModCard extends Vue {
}
get localModList(): ManifestV2[] {
return this.$store.state.localModList;
return this.$store.state.profile.modList;
}
get tsMod() {
Expand Down Expand Up @@ -76,7 +76,7 @@ export default class LocalModCard extends Vue {
}
async disableMod() {
const dependants = Dependants.getDependantList(this.mod, this.$store.state.localModList);
const dependants = Dependants.getDependantList(this.mod, this.localModList);
for (const mod of dependants) {
if (mod.isEnabled()) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/OnlineModList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default class OnlineModList extends Vue {
private funkyMode: boolean = false;
get localModList(): ManifestV2[] {
return this.$store.state.localModList;
return this.$store.state.profile.modList;
}
get deprecationMap(): Map<string, boolean> {
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/OnlineModView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export default class OnlineModView extends Vue {
thunderstoreSearchFilter = "";
get localModList(): ManifestV2[] {
return this.$store.state.localModList;
return this.$store.state.profile.modList;
}
get thunderstoreModList(): ThunderstoreMod[] {
Expand Down
14 changes: 7 additions & 7 deletions src/pages/Manager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ import CategoryFilterModal from '../components/modals/CategoryFilterModal.vue';
}
get localModList(): ManifestV2[] {
return this.$store.state.localModList || [];
return this.$store.state.profile.modList;
}
showError(error: R2Error) {
Expand Down Expand Up @@ -524,7 +524,7 @@ import CategoryFilterModal from '../components/modals/CategoryFilterModal.vue';
this.showError(R2Error.fromThrownValue(e, "Error enabling mods"));
} finally {
if (lastSuccessfulUpdate.length) {
await this.$store.dispatch("updateModList", lastSuccessfulUpdate);
await this.$store.dispatch('profile/updateModList', lastSuccessfulUpdate);
}
}
Expand Down Expand Up @@ -618,7 +618,7 @@ import CategoryFilterModal from '../components/modals/CategoryFilterModal.vue';
case "DisableAll":
await this.$store.dispatch(
"profile/disableModsFromActiveProfile",
{mods: this.$store.state.localModList}
{mods: this.localModList}
);
await this.$router.push({name: "manager.installed"});
break;
Expand All @@ -635,9 +635,9 @@ import CategoryFilterModal from '../components/modals/CategoryFilterModal.vue';
CacheUtil.clean();
break;
case "RefreshedThunderstorePackages":
ProfileModList.getModList(this.contextProfile!).then(value => {
ProfileModList.getModList(this.contextProfile!).then(async value => {
if (!(value instanceof R2Error)) {
this.$store.dispatch("updateModList", value);
await this.$store.dispatch("profile/updateModList", value);
}
});
break;
Expand All @@ -654,7 +654,7 @@ import CategoryFilterModal from '../components/modals/CategoryFilterModal.vue';
this.launchParametersModel = this.settings.getContext().gameSpecific.launchParameters;
const newModList: ManifestV2[] | R2Error = await ProfileModList.getModList(this.contextProfile!);
if (!(newModList instanceof R2Error)) {
await this.$store.dispatch("updateModList", newModList);
await this.$store.dispatch('profile/updateModList', newModList);
} else {
LoggerProvider.instance.Log(LogSeverity.ACTION_STOPPED, `Failed to retrieve local mod list\n-> ${newModList.message}`);
this.$emit('error', newModList);
Expand All @@ -672,7 +672,7 @@ import CategoryFilterModal from '../components/modals/CategoryFilterModal.vue';
.then(async value => {
const modList = await ProfileModList.getModList(this.contextProfile!);
if (!(modList instanceof R2Error)) {
await this.$store.dispatch('updateModList', modList);
await this.$store.dispatch('profile/updateModList', modList);
} else {
this.showError(modList);
}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Profiles.vue
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ export default class Profiles extends Vue {
}
async setProfileAndContinue() {
await this.$store.dispatch('updateModList', []);
await this.$store.dispatch('profile/updateModList', []);
await settings.setProfile(Profile.getActiveProfile().getProfileName());
await this.$router.push({name: 'manager.installed'});
}
Expand Down
19 changes: 1 addition & 18 deletions src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import ModalsModule from './modules/ModalsModule';
import ModFilterModule from './modules/ModFilterModule';
import ProfileModule from './modules/ProfileModule';
import { FolderMigration } from '../migrations/FolderMigration';
import ManifestV2 from '../model/ManifestV2';
import ThunderstoreMod from '../model/ThunderstoreMod';
import ThunderstoreDownloaderProvider from "../providers/ror2/downloading/ThunderstoreDownloaderProvider";
import ThunderstorePackages from '../r2mm/data/ThunderstorePackages';

Vue.use(Vuex);
Expand All @@ -17,7 +15,6 @@ export interface State {
deprecatedMods: Map<string, boolean>;
dismissedUpdateAll: boolean;
isMigrationChecked: boolean;
localModList: ManifestV2[];
thunderstoreModList: ThunderstoreMod[];
}

Expand All @@ -30,17 +27,13 @@ type Context = ActionContext<State, State>;

export const store = {
state: {
localModList: [],
thunderstoreModList: [],
dismissedUpdateAll: false,
isMigrationChecked: false,
apiConnectionError: "",
deprecatedMods: new Map<string, boolean>(),
},
actions: {
updateModList({ commit }: Context, modList: ManifestV2[]) {
commit('setLocalModList', modList);
},
updateThunderstoreModList({ commit }: Context, modList: ThunderstoreMod[]) {
commit('setThunderstoreModList', modList);
commit('setDeprecatedMods', modList);
Expand All @@ -66,9 +59,6 @@ export const store = {
}
},
mutations: {
setLocalModList(state: State, list: ManifestV2[]) {
state.localModList = list;
},
setThunderstoreModList(state: State, list: ThunderstoreMod[]) {
state.thunderstoreModList = list;
},
Expand All @@ -85,14 +75,7 @@ export const store = {
state.deprecatedMods = ThunderstorePackages.getDeprecatedPackageMap();
}
},
getters: {
localModsWithUpdates(state: State) {
return ThunderstoreDownloaderProvider.instance.getLatestOfAllToUpdate(
state.localModList,
state.thunderstoreModList
);
}
},
getters: {},
modules: {
modals: ModalsModule,
modFilters: ModFilterModule,
Expand Down
28 changes: 25 additions & 3 deletions src/store/modules/ProfileModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ import Profile from "../../model/Profile";
import { SortDirection } from '../../model/real_enums/sort/SortDirection';
import { SortLocalDisabledMods } from '../../model/real_enums/sort/SortLocalDisabledMods';
import { SortNaming } from '../../model/real_enums/sort/SortNaming';
import ThunderstoreCombo from '../../model/ThunderstoreCombo';
import ConflictManagementProvider from '../../providers/generic/installing/ConflictManagementProvider';
import ThunderstoreDownloaderProvider from '../../providers/ror2/downloading/ThunderstoreDownloaderProvider';
import ProfileInstallerProvider from '../../providers/ror2/installing/ProfileInstallerProvider';
import ModListSort from '../../r2mm/mods/ModListSort';
import ProfileModList from '../../r2mm/mods/ProfileModList';
import SearchUtils from '../../utils/SearchUtils';

interface State {
modList: ManifestV2[];
order?: SortNaming;
direction?: SortDirection;
disabledPosition?: SortLocalDisabledMods;
Expand All @@ -27,15 +30,23 @@ export default {
namespaced: true,

state: (): State => ({
modList: [],
order: undefined,
direction: undefined,
disabledPosition: undefined,
searchQuery: '',
}),

getters: <GetterTree<State, RootState>>{
modsWithUpdates(state, _getters, rootState): ThunderstoreCombo[] {
return ThunderstoreDownloaderProvider.instance.getLatestOfAllToUpdate(
state.modList,
rootState.thunderstoreModList
);
},

visibleModList(state, _getters, rootState): ManifestV2[] {
let mods = [...rootState.localModList];
let mods = [...state.modList];

if (state.searchQuery) {
const searchKeys = SearchUtils.makeKeys(state.searchQuery);
Expand Down Expand Up @@ -76,6 +87,12 @@ export default {
state.disabledPosition = values[2];
},

// Avoid calling this directly, prefer updateModList action to
// ensure TSMM specific code gets called.
setModList(state: State, list: ManifestV2[]) {
state.modList = list;
},

setOrder(state: State, value: SortNaming) {
state.order = value;
},
Expand Down Expand Up @@ -141,16 +158,17 @@ export default {
}
}

// Update mod list status to mods.yml and Vuex.
// Update mod list status to mods.yml.
const updatedList = await ProfileModList.updateMods(mods, profile, (mod) => mod.disable());
if (updatedList instanceof R2Error) {
throw updatedList;
} else {
lastSuccessfulUpdate = updatedList;
}
} finally {
// Update mod list stored in Vuex.
if (lastSuccessfulUpdate !== undefined) {
dispatch('updateModList', lastSuccessfulUpdate, {root: true});
dispatch('updateModList', lastSuccessfulUpdate);
}
}

Expand All @@ -165,5 +183,9 @@ export default {
}
}
},

async updateModList({commit}, modList: ManifestV2[]) {
commit('setModList', modList);
},
},
}

0 comments on commit 559c89a

Please sign in to comment.