add user_doors into store

This commit is contained in:
Jörn-Michael Miehe 2023-11-04 04:17:36 +00:00
parent 6efa2aef9b
commit 644b1eb3e3
3 changed files with 15 additions and 19 deletions

View file

@ -11,7 +11,6 @@
</template>
<script lang="ts">
import { DoorsSaved } from "@/lib/api";
import { Door } from "@/lib/door";
import { advent22Store } from "@/plugins/store";
import { Options, Vue } from "vue-class-component";
@ -27,19 +26,15 @@ import CountDown from "./CountDown.vue";
})
export default class extends Vue {
public readonly store = advent22Store();
public doors: Door[] = [];
public mounted(): void {
this.$advent22
.api_get<DoorsSaved>("user/doors")
.then((data) => {
this.doors.length = 0;
public get doors(): Door[] {
const result = [];
for (const value of data) {
this.doors.push(Door.load(value));
}
})
.catch(this.$advent22.alert_user_error);
for (const value of this.store.user_doors) {
result.push(Door.load(value));
}
return result;
}
}
</script>

View file

@ -38,7 +38,7 @@
<h3>Rätsel</h3>
<dl>
<dt>Offene Türchen</dt>
<dd>{{ num_user_doors }}</dd>
<dd>{{ store.user_doors.length }}</dd>
<dt>Zeit zum nächsten Türchen</dt>
<dd v-if="store.next_door_target === null">
@ -217,7 +217,6 @@ export default class extends Vue {
},
};
public doors: DoorsSaved = [];
public num_user_doors = 0;
public dav_credentials: Credentials = ["", ""];
public ui_credentials: Credentials = ["", ""];
@ -232,12 +231,10 @@ export default class extends Vue {
Promise.all([
this.$advent22.api_get<AdminConfigModel>("admin/config_model"),
this.$advent22.api_get<DoorsSaved>("admin/doors"),
this.$advent22.api_get<DoorsSaved>("user/doors"),
])
.then(([admin_config_model, doors, user_doors]) => {
.then(([admin_config_model, doors]) => {
this.admin_config_model = admin_config_model;
this.doors = doors;
this.num_user_doors = user_doors.length;
ready();
})

View file

@ -1,4 +1,4 @@
import { Credentials, SiteConfigModel } from "@/lib/api";
import { Credentials, DoorsSaved, SiteConfigModel } from "@/lib/api";
import { ADVENT22 } from "@/plugins/advent22";
import { AxiosBasicCredentials } from "axios";
import { acceptHMRUpdate, defineStore } from "pinia";
@ -19,6 +19,7 @@ export const advent22Store = defineStore({
content: "",
footer: "",
} as SiteConfigModel,
user_doors: [] as DoorsSaved,
next_door_target: null as number | null,
}),
@ -47,15 +48,18 @@ export const advent22Store = defineStore({
Promise.all([
ADVENT22.api_get<SiteConfigModel>("user/site_config"),
ADVENT22.api_get<DoorsSaved>("user/doors"),
ADVENT22.api_get<number | null>("user/next_door"),
])
.then(([site_config, next_door]) => {
.then(([site_config, user_doors, next_door]) => {
document.title = site_config.title;
if (site_config.subtitle !== "")
document.title += " " + site_config.subtitle;
this.site_config = site_config;
this.user_doors = user_doors;
if (next_door !== null)
this.next_door_target = Date.now() + next_door;
})