From 63a00d06819de5ec0acb682c3f26f87b257f4d08 Mon Sep 17 00:00:00 2001 From: James Lyne Date: Wed, 8 Sep 2021 15:23:21 +0100 Subject: [PATCH] Move loginEnabled logic to store getter --- src/App.vue | 2 +- src/providers/DynmapMapProvider.ts | 6 +++--- src/store/getters.ts | 5 +++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/App.vue b/src/App.vue index 043eb7a..ce82d87 100644 --- a/src/App.vue +++ b/src/App.vue @@ -58,7 +58,7 @@ export default defineComponent({ loggedIn = computed(() => store.state.loggedIn), //Whether the user is currently logged in loginRequired = computed(() => store.state.loginRequired), //Whether logging is required to view the current server - loginEnabled = computed(() => store.state.components.login || loginRequired.value), //Whether logging in is enabled for the current server + loginEnabled = computed(() => store.getters.loginEnabled), //Whether logging in is enabled for the current server //Hide the login modal if we are logged out on a login-required server, but the server list is open //Allows switching servers without the modal overlapping diff --git a/src/providers/DynmapMapProvider.ts b/src/providers/DynmapMapProvider.ts index ff08c12..00e2b4e 100644 --- a/src/providers/DynmapMapProvider.ts +++ b/src/providers/DynmapMapProvider.ts @@ -807,7 +807,7 @@ export default class DynmapMapProvider extends MapProvider { } async login(data: any) { - if (!this.store.state.components.login && !this.store.state.loginRequired) { + if (!this.store.getters.loginEnabled) { return Promise.reject(this.store.state.messages.loginErrorDisabled); } @@ -844,7 +844,7 @@ export default class DynmapMapProvider extends MapProvider { } async logout() { - if (!this.store.state.components.login && !this.store.state.loginRequired) { + if (!this.store.getters.loginEnabled) { return Promise.reject(this.store.state.messages.loginErrorDisabled); } @@ -860,7 +860,7 @@ export default class DynmapMapProvider extends MapProvider { } async register(data: any) { - if (!this.store.state.components.login && !this.store.state.loginRequired) { + if (!this.store.getters.loginEnabled) { return Promise.reject(this.store.state.messages.loginErrorDisabled); } diff --git a/src/store/getters.ts b/src/store/getters.ts index 56baffb..7523e7b 100644 --- a/src/store/getters.ts +++ b/src/store/getters.ts @@ -22,6 +22,7 @@ export type Getters = { playerMarkersEnabled(state: State): boolean; coordinatesControlEnabled(state: State): boolean; clockControlEnabled(state: State): boolean; + loginEnabled(state: State): boolean; night(state: State): boolean; mapBackground(state: State, getters: GetterTree & Getters): string; url(state: State, getters: GetterTree & Getters): string; @@ -42,6 +43,10 @@ export const getters: GetterTree & Getters = { return state.components.clockControl !== undefined; }, + loginEnabled(state: State): boolean { + return state.components.login || state.loginRequired; + }, + night(state: State): boolean { return getMinecraftTime(state.currentWorldState.timeOfDay).night; },