syncing agenda

This commit is contained in:
Julian Krauser 2024-10-15 16:24:29 +02:00
parent 52deb253c1
commit c0bfc00862
12 changed files with 221 additions and 62 deletions

View file

@ -1,8 +1,16 @@
<template>
<CloudIcon v-if="syncing == 'synced'" class="w-5 h-5" />
<CloudArrowUpIcon v-else-if="syncing == 'detectedChanges'" class="w-5 h-5 cursor-pointer" @click="syncAll" />
<CloudArrowUpIcon
v-else-if="syncing == 'detectedChanges'"
class="w-5 h-5 cursor-pointer animate-bounce"
@click="syncAll"
/>
<ArrowPathIcon v-else-if="syncing == 'syncing'" class="w-5 h-5 animate-spin" />
<ExclamationTriangleIcon v-else class="w-5 h-5 animate-[ping_1s_ease-in-out_3] text-red-500" />
<ExclamationTriangleIcon
v-else
class="w-5 h-5 animate-[ping_1s_ease-in-out_3] text-red-500 cursor-pointer"
@click="syncAll"
/>
</template>
<script setup lang="ts">
@ -10,6 +18,8 @@ import { defineComponent } from "vue";
import { mapState, mapActions } from "pinia";
import { useProtocolStore } from "@/stores/admin/protocol";
import { ArrowPathIcon, CloudArrowUpIcon, CloudIcon, ExclamationTriangleIcon } from "@heroicons/vue/24/outline";
import { useProtocolAgendaStore } from "@/stores/admin/protocolAgenda";
import { useProtocolPresenceStore } from "@/stores/admin/protocolPresence";
</script>
<script lang="ts">
@ -24,6 +34,7 @@ export default defineComponent({
},
detectedChangeProtocol() {
clearTimeout(this.protocolTimer);
this.setProtocolSyncingState("synced");
if (this.detectedChangeProtocol == false) {
return;
}
@ -32,6 +43,29 @@ export default defineComponent({
this.synchronizeActiveProtocol();
}, 10000);
},
detectedChangeProtocolAgenda() {
console.log(this.detectedChangeProtocolAgenda);
clearTimeout(this.protocolAgendaTimer);
if (this.detectedChangeProtocolAgenda == false) {
this.setProtocolAgendaSyncingState("synced");
return;
}
this.setProtocolAgendaSyncingState("detectedChanges");
this.protocolAgendaTimer = setTimeout(() => {
this.synchronizeActiveProtocolAgenda();
}, 10000);
},
detectedChangeProtocolPresence() {
clearTimeout(this.protocolPresenceTimer);
this.setProtocolPresenceSyncingState("synced");
if (this.detectedChangeProtocolPresence == false) {
return;
}
this.setProtocolPresenceSyncingState("detectedChanges");
this.protocolPresenceTimer = setTimeout(() => {
this.synchronizeActiveProtocolPresence();
}, 10000);
},
},
emits: {
syncState(state: "synced" | "syncing" | "detectedChanges" | "failed") {
@ -41,6 +75,8 @@ export default defineComponent({
data() {
return {
protocolTimer: undefined as undefined | any,
protocolAgendaTimer: undefined as undefined | any,
protocolPresenceTimer: undefined as undefined | any,
};
},
mounted() {
@ -48,12 +84,16 @@ export default defineComponent({
},
beforeUnmount() {
if (!this.protocolTimer) clearTimeout(this.protocolTimer);
if (!this.protocolAgendaTimer) clearTimeout(this.protocolAgendaTimer);
if (!this.protocolPresenceTimer) clearTimeout(this.protocolPresenceTimer);
},
computed: {
...mapState(useProtocolStore, ["activeProtocolObj", "syncingProtocol", "detectedChangeProtocol"]),
...mapState(useProtocolStore, ["syncingProtocol", "detectedChangeProtocol"]),
...mapState(useProtocolAgendaStore, ["syncingProtocolAgenda", "detectedChangeProtocolAgenda"]),
...mapState(useProtocolPresenceStore, ["syncingProtocolPresence", "detectedChangeProtocolPresence"]),
syncing(): "synced" | "syncing" | "detectedChanges" | "failed" {
let states = [this.syncingProtocol];
let states = [this.syncingProtocol, this.syncingProtocolAgenda, this.syncingProtocolPresence];
if (states.includes("failed")) return "failed";
else if (states.includes("syncing")) return "syncing";
@ -63,9 +103,15 @@ export default defineComponent({
},
methods: {
...mapActions(useProtocolStore, ["synchronizeActiveProtocol", "setProtocolSyncingState"]),
...mapActions(useProtocolAgendaStore, ["synchronizeActiveProtocolAgenda", "setProtocolAgendaSyncingState"]),
...mapActions(useProtocolPresenceStore, ["synchronizeActiveProtocolPresence", "setProtocolPresenceSyncingState"]),
syncAll() {
if (!this.protocolTimer) clearTimeout(this.protocolTimer);
if (!this.protocolAgendaTimer) clearTimeout(this.protocolAgendaTimer);
if (!this.protocolPresenceTimer) clearTimeout(this.protocolPresenceTimer);
this.synchronizeActiveProtocol();
this.synchronizeActiveProtocolAgenda();
this.synchronizeActiveProtocolPresence();
},
},
});