🔨 Fetch multual guilds with interval

This commit is contained in:
SebClem 2022-06-30 11:41:10 +02:00
parent a8c308dbd0
commit 4fb094b245
Signed by: sebclem
GPG Key ID: 5A4308F6A359EA50

View File

@ -43,11 +43,11 @@
<script setup lang="ts">
import type { Guild } from "@/data/guild/Guild";
import { getInviteLink } from "@/services/guildService";
import { getInviteLink, getMutualGuilds } from "@/services/guildService";
import { useInviteLinkStore } from "@/stores/inviteLink";
import { useMutualGuildsStore } from "@/stores/mutualGuilds";
import { storeToRefs } from "pinia";
import { onBeforeMount } from "vue";
import { onBeforeMount, onBeforeUnmount } from "vue";
import { useRouter, type RouteLocationRaw } from "vue-router";
const inviteLinkStore = useInviteLinkStore();
@ -79,6 +79,26 @@ function getToUrl(guild: Guild): RouteLocationRaw {
function clickOnGuild(guildId: string) {
mutualGuildsStore.lastGuildId = guildId;
}
function loadMutualGuilds() {
getMutualGuilds().then((value) => {
mutualGuildsStore.guilds = value;
mutualGuildsStore.loaded = true;
if (
!mutualGuildsStore.getGuild(
router.currentRoute.value.params?.guildId as string
)
) {
router.push("/");
}
});
}
const interval = setInterval(loadMutualGuilds, 5000);
onBeforeUnmount(() => {
clearInterval(interval);
});
</script>
<style scoped></style>