Skip to content

Commit

Permalink
fix: too high polling
Browse files Browse the repository at this point in the history
  • Loading branch information
arthaud-proust committed Oct 26, 2023
1 parent 55474ad commit 40a1eff
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 31 deletions.
57 changes: 28 additions & 29 deletions resources/js/Components/Pigeon/PigeonPerch.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<script setup lang="ts">
import PigeonData = App.Data.PigeonData;
import PigeonSentModal from "@/Components/Pigeon/PigeonSentModal.vue";
import {computed, onMounted, onUnmounted, ref, watch} from "vue";
import {computed, ref} from "vue";
import {router} from "@inertiajs/vue3";
import PigeonNoNewsModal from "@/Components/Pigeon/PigeonNoNewsModal.vue";
import {DateTime} from "luxon";
const props = defineProps<{
pigeon: PigeonData
Expand Down Expand Up @@ -39,30 +38,30 @@ const hasMessage = computed<boolean>(() => {
return !props.pigeon.news[0]?.message?.is_read
})
const secondsLeft = ref(props.pigeon.secondsToArrive);
let secondsLeftUpdater: number | null = null;
watch(() => props.pigeon, () => {
secondsLeft.value = props.pigeon.secondsToArrive;
})
onMounted(() => {
secondsLeftUpdater = setInterval(() => {
secondsLeft.value--;
}, 1_000);
})
onUnmounted(() => {
if (secondsLeftUpdater) {
clearInterval(secondsLeftUpdater);
}
})
const timeLeft = computed(() => {
return DateTime.fromISO("2017-05-15T00:00:00")
.plus({second: secondsLeft.value > 0 ? secondsLeft.value : 0})
.toLocaleString(DateTime.TIME_24_WITH_SECONDS);
})
// const secondsLeft = ref(props.pigeon.secondsToArrive);
// let secondsLeftUpdater: number | null = null;
//
// watch(() => props.pigeon, () => {
// secondsLeft.value = props.pigeon.secondsToArrive;
// })
//
// onMounted(() => {
// secondsLeftUpdater = setInterval(() => {
// secondsLeft.value--;
// }, 1_000);
// })
//
// onUnmounted(() => {
// if (secondsLeftUpdater) {
// clearInterval(secondsLeftUpdater);
// }
// })
//
// const timeLeft = computed(() => {
// return DateTime.fromISO("2017-05-15T00:00:00")
// .plus({second: secondsLeft.value > 0 ? secondsLeft.value : 0})
// .toLocaleString(DateTime.TIME_24_WITH_SECONDS);
// })
</script>
<template>
Expand Down Expand Up @@ -94,9 +93,9 @@ const timeLeft = computed(() => {

</div>

<div class="bg-white px-2 py-0.5 rounded">
<span class="h-6 text-meta" v-if="pigeon.isTravelling">{{ timeLeft }}</span>
</div>
<!-- <div class="bg-white px-2 py-0.5 rounded">-->
<!-- <span class="h-6 text-meta" v-if="pigeon.isTravelling">{{ timeLeft }}</span>-->
<!-- </div>-->

<button @click="handlePerchClick" class="absolute top-0 left-0 h-full w-full pointer-events-auto">
<span class="sr-only">
Expand Down
3 changes: 1 addition & 2 deletions resources/js/Pages/News/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ const parentElementSize = useElementSize(parentElement);
let newsStatePollingInterval: number;
onMounted(() => {
// dirty but poc
newsStatePollingInterval = setInterval(() => router.reload({only: ['news', 'pigeon']}), 1_000);
newsStatePollingInterval = setInterval(() => router.reload({only: ['news', 'pigeon']}), 10_000);
})
onUnmounted(() => {
Expand Down

0 comments on commit 40a1eff

Please sign in to comment.