Skip to content

Commit

Permalink
Initialize selected version better
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanzilla committed Jul 2, 2024
1 parent 8b88adf commit ba2d2c4
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 45 deletions.
88 changes: 47 additions & 41 deletions src/components/LandingPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import { ipcRenderer } from "electron";
import fs from "node:fs";
import path from "node:path";
import { defineComponent, provide, ref } from "vue";
import { defineComponent, provide, ref, watch } from "vue";

import { useStashStore } from "../stores/auras";
import type { Account, AuraType, Version } from "../stores/config";
import type { Account, AddonConfig, AuraType, Version } from "../stores/config";
import { useConfigStore } from "../stores/config";

import About from "./UI/About.vue";
Expand Down Expand Up @@ -99,6 +99,11 @@ export default defineComponent({
setup() {
const config = useConfigStore();
const stash = useStashStore();
const selectedVersion = ref<Version>({
account: "",
accounts: [],
name: "",
});

const updateAuraIsShown = ref(false);
const toggleUpdatedAuraList = () => {
Expand All @@ -110,6 +115,18 @@ export default defineComponent({
reportIsShown.value = !reportIsShown.value;
};

watch(
() => config.wowpath.version,
(newVersion) => {
const version = config.wowpath.versions?.find(
(version) => version.name === newVersion,
);
if (version) {
selectedVersion.value = version;
}
},
);

provide("toggleReport", toggleReport);
provide("toggleUpdatedAuraList", toggleUpdatedAuraList);

Expand All @@ -120,6 +137,7 @@ export default defineComponent({
reportIsShown,
toggleUpdatedAuraList,
toggleReport,
selectedVersion,
};
},
data() {
Expand Down Expand Up @@ -152,8 +170,8 @@ export default defineComponent({
return this.stash.tohtml();
},
accountHash() {
if (this.versionSelected) {
const { account } = this.versionSelected;
if (this.selectedVersion) {
const { account } = this.selectedVersion;
return hash.hashFnv32a(account, true);
}
return null;
Expand Down Expand Up @@ -194,26 +212,12 @@ export default defineComponent({
this.addonSelected.toLowerCase(),
);
},
versionSelected(): Version | undefined {
if (!this.config.wowpath.version || !this.config.wowpath.versions) {
return undefined;
}

const selectedVersion = this.config.wowpath.versions.find(
(version) => version.name === this.config.wowpath.version,
);

return selectedVersion || undefined;
},
accountSelected(): Account {
const versionSelected = this.versionSelected;
const versionSelected = this.selectedVersion;

if (typeof versionSelected === "object") {
return versionSelected.accounts.find(
(account) => account.name === versionSelected.account,
);
}
return null;
return versionSelected?.accounts?.find(
(account) => account.name === versionSelected.account,
) as Account;
},
aurasWithData() {
return this.auras.filter(
Expand Down Expand Up @@ -280,7 +284,7 @@ export default defineComponent({
handler() {
writeAddonData(
this.config,
this.addonsInstalled,
this.addonsInstalled as AddonConfig[],
this.aurasWithData,
this.stash,
);
Expand All @@ -292,15 +296,15 @@ export default defineComponent({
this.config,
this.versionOptions,
this.accountOptions,
this.versionSelected,
this.selectedVersion,
this.auras,
);
},
"config.wowpath.version": function () {
buildAccountList(
this.config,
this.accountOptions,
this.versionSelected,
this.selectedVersion,
this.auras,
);
},
Expand All @@ -320,19 +324,21 @@ export default defineComponent({

if (link) {
const result = link.match(pattern);
let slug: string;
let slug: string = "";

if (result) {
({ 1: slug } = result);
}

if (slug) {
await wagoPushHandler(
this.config,
slug,
this.stash,
this.versionSelected,
);
if (this.selectedVersion) {
await wagoPushHandler(
this.config,
slug,
this.stash,
this.selectedVersion,
);
}
}
}
});
Expand Down Expand Up @@ -397,7 +403,7 @@ export default defineComponent({
this.config,
this.versionOptions,
this.accountOptions,
this.versionSelected,
this.selectedVersion,
this.auras,
);
}
Expand Down Expand Up @@ -460,22 +466,22 @@ export default defineComponent({
getWeakAurasSaved() {
return WeakAurasSaved(
this.config,
this.versionSelected,
this.selectedVersion,
this.accountSelected,
);
},
getPlaterSaved() {
return PlaterSaved(
this.config,
this.versionSelected,
this.selectedVersion,
this.accountSelected,
);
},
getIsAddonInstalled(addon: string) {
return isAddonInstalled(
this.config,
addon,
this.versionSelected,
this.selectedVersion,
this.accountSelected,
);
},
Expand Down Expand Up @@ -503,7 +509,7 @@ export default defineComponent({
async doCompareSVwithWago() {
return compareSVwithWago(
this.config,
this.versionSelected,
this.selectedVersion,
this.accountSelected,
this.fetching,
this.addonsInstalled,
Expand Down Expand Up @@ -609,11 +615,11 @@ export default defineComponent({
/>
</div>
<div
v-if="config.wowpath.validated && versionSelected"
v-if="config.wowpath.validated && selectedVersion"
id="account-selector"
>
<Dropdown
v-model:value="versionSelected.account"
v-model:value="selectedVersion.account"
:options="accountOptions"
:label="$t('app.wowpath.account' /* Account */)"
@change="doCompareSVwithWago()"
Expand Down Expand Up @@ -645,7 +651,7 @@ export default defineComponent({
<div id="dashboard">
<RefreshButton
:is-settings-ok="config.wowpath.validated"
:is-version-selected="versionSelected"
:is-version-selected="selectedVersion"
:is-account-selected="accountSelected"
:is-sv-ok="!!getWeakAurasSaved() || !!getPlaterSaved()"
:fetching="fetching"
Expand Down Expand Up @@ -748,7 +754,7 @@ export default defineComponent({
<div class="app-update">
<a
v-if="updater.status === 'update-available'"
:href="updater.path"
:href="updater.path || ''"
target="_blank"
>
<i
Expand Down
2 changes: 1 addition & 1 deletion src/components/UI/Dropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default defineComponent({
type: Array as () => Array<DropdownOption>,
default: () => [],
},
label: { type: [String, null], default: null },
label: { type: [String], default: null },
placeholder: {
type: String,
default: "",
Expand Down
8 changes: 5 additions & 3 deletions src/stores/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ export interface AuraType {
}

export interface Version {
account?: string;
accounts?: Account[];
name?: string;
account: string;
accounts: Account[];
name: string;
}

export interface VersionOptions {
Expand Down Expand Up @@ -112,6 +112,7 @@ export interface ConfigState {
wagoApiKey: string | null;
wagoUsername: string | null;
wowpath: WowPath;
selectedVersion: Version | undefined;
}

export const useConfigStore = defineStore("configStore", {
Expand All @@ -138,6 +139,7 @@ export const useConfigStore = defineStore("configStore", {
maxSize: 100,
defaultBackupPath: path.join(userDataPath, "WeakAurasData-Backup"),
},
selectedVersion: undefined,
};
},
});

0 comments on commit ba2d2c4

Please sign in to comment.