Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(highlights): confetti delay #9

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions components/Confetti.vue

This file was deleted.

26 changes: 26 additions & 0 deletions composables/useConfetti.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { confetti } from '@tsparticles/confetti';

export function useConfetti() {
let interval: NodeJS.Timeout;

onUnmounted(() => {
clearInterval(interval);
});

return () => {
let count = 0;

interval = setInterval(() => {
confetti({
particleCount: 100,
spread: 360,
origin: { x: Math.random(), y: Math.random() * 0.8 },
});

count++;
if (count === 5) {
clearInterval(interval);
}
}, 500);
};
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"dependencies": {
"@heroicons/vue": "^2.1.3",
"@pinia/nuxt": "^0.5.1",
"@tsparticles/confetti": "^3.3.0",
"@tsparticles/confetti": "^3.5.0",
"node-emoji": "^2.1.3",
"nuxt": "^3.11.2",
"vue": "^3.4.21",
Expand Down
10 changes: 8 additions & 2 deletions pages/highlights.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<script setup lang="ts">
import type { Card } from '~/components/HighlightCard.vue';
import '@tsparticles/confetti';

const { data } = await useFetch('/api/highlights');
const flippedCards = useFlippedCards();
const confetti = useConfetti();

type Entries<T> = {
[K in keyof T]: [K, T[K]];
Expand Down Expand Up @@ -58,7 +61,11 @@ function getFormattedValue(
}
}

const flippedCards = useFlippedCards();
watch(flippedCards, (newVal) => {
if (newVal.value.length === 6) {
confetti();
}
});
</script>

<template>
Expand All @@ -67,6 +74,5 @@ const flippedCards = useFlippedCards();
<ul class="flex w-fit grid-cols-3 flex-col gap-8 md:grid md:gap-0">
<highlightCard v-for="(card, index) of cards" :key="card.title" :card="card" :index="index" />
</ul>
<Confetti v-if="flippedCards.value.length === 6" />
</div>
</template>
Loading