-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from formsible/feat/components
redirect component update
- Loading branch information
Showing
4 changed files
with
21 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,30 @@ | ||
<script setup lang="ts"> | ||
import { ref, onMounted, onBeforeUnmount } from 'vue' | ||
import { useTimeoutFn } from '@vueuse/core' | ||
import { onMounted } from 'vue' | ||
import type { ActionRedirectProperties } from '~/types' | ||
// Props declaration | ||
interface Props { | ||
display: ActionRedirectProperties | ||
} | ||
const props = defineProps<Props>() | ||
// Countdown timer and progress | ||
const countdown = ref(5) | ||
const progress = ref(100) | ||
const interval = ref<NodeJS.Timeout | null>(null) | ||
const redirecting = ref(true) | ||
// Automatically redirect after 5 seconds | ||
onMounted(() => { | ||
interval.value = setInterval(() => { | ||
countdown.value -= 1 | ||
progress.value = (countdown.value / 5) * 100 | ||
if (countdown.value === 0) { | ||
clearInterval(interval.value!) | ||
window.location.href = props.display.src as string | ||
} | ||
}, 1000) | ||
}) | ||
// Option to cancel redirection | ||
const cancelRedirect = () => { | ||
redirecting.value = false | ||
if (interval.value) { | ||
clearInterval(interval.value) | ||
} | ||
// Countdown complete event | ||
const onCountdownComplete = () => { | ||
window.location.href = props.display.url | ||
} | ||
// Cleanup on component unmount | ||
onBeforeUnmount(() => { | ||
if (interval.value) { | ||
clearInterval(interval.value) | ||
} | ||
}) | ||
</script> | ||
// Timeout composable by vusue | ||
const { start } = useTimeoutFn( | ||
onCountdownComplete, | ||
props.display.countDown || 3000, | ||
) | ||
// Hooks | ||
onMounted(start) | ||
</script> | ||
<template> | ||
<div class="p-4 max-w-md mx-auto"> | ||
<div v-if="redirecting"> | ||
<p class="text-lg mb-4"> | ||
You are being redirected to | ||
<strong>{{ display.src }}</strong> in {{ countdown }} seconds. | ||
</p> | ||
<div class="relative w-full bg-surface-200 rounded-full h-2 mb-4"> | ||
<div :style="{ width: progress + '%' }"></div> | ||
</div> | ||
<Button severity="danger" @click="cancelRedirect"> Cancel </Button> | ||
</div> | ||
<div v-else> | ||
<p class="text-lg text-red-500">Redirection has been canceled.</p> | ||
</div> | ||
<div class="text-center"> | ||
<p>You are being directed to {{ display.url }}.</p> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters