-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorkflowCard.vue
More file actions
146 lines (136 loc) · 3.84 KB
/
WorkflowCard.vue
File metadata and controls
146 lines (136 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<script setup lang="ts">
import { Card, CardContent, CardHeader, CardTitle } from "../ui/card";
import Image from "../Image.vue";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "../ui/select";
import { computed, watch, ref } from "vue";
import {
humanReadableParticipationStatus,
participationNextValues,
participationStatusColor,
type ParticipationStatus,
} from "@/dto";
import { Badge } from "../ui/badge";
import type { RouteLocationRaw } from "vue-router";
import ConfettiExplosion from "vue-confetti-explosion";
import confettiAudio from "@/assets/audio/confetti.mp3";
const props = defineProps<{
title: string;
currentStatus?: ParticipationStatus;
image?: string;
loading?: boolean;
badge?: string;
to?: RouteLocationRaw;
}>();
// Track confetti state
const showConfetti = ref(false);
// Function to play confetti sound
const playConfettiSound = () => {
try {
const audio = new Audio(confettiAudio);
audio.volume = 0.5; // Set volume to 50%
audio.play().catch(console.error);
} catch (error) {
console.error("Error playing confetti sound:", error);
}
};
const selectedStatus = computed({
get: () => props.currentStatus || "SUGGESTED",
set: (value: number) => {
emits("statusChange", value);
},
});
const emits = defineEmits<{
(e: "statusChange", step: number): void;
}>();
const possibleStates = computed(
() => participationNextValues[selectedStatus.value] || [],
);
// Watch for status changes to trigger confetti
watch(
() => props.currentStatus,
(newStatus, oldStatus) => {
if (oldStatus && newStatus && oldStatus !== newStatus) {
if (newStatus === "ACCEPTED" || newStatus === "ANNOUNCED") {
showConfetti.value = true;
playConfettiSound(); // Play the confetti sound
// Reset confetti after animation
setTimeout(() => {
showConfetti.value = false;
}, 4000);
}
}
},
{ immediate: false },
);
</script>
<template>
<component
:is="props.to ? 'RouterLink' : 'div'"
:to="props.to"
:class="['block', props.to ? 'cursor-pointer' : '']"
>
<Card
:class="[
'ring',
'h-full',
'relative',
participationStatusColor[selectedStatus].ring,
]"
>
<div
v-if="showConfetti"
class="absolute left-1/2 top-1/2 pointer-events-none z-50 -translate-x-1/2 -translate-y-1/2"
>
<ConfettiExplosion />
</div>
<CardContent>
<div
v-if="!possibleStates.length"
:class="[
'w-full flex items-center rounded-md border bg-transparent px-3 py-2 text-sm shadow-xs pointer-events-none',
participationStatusColor[selectedStatus].background,
]"
>
{{ humanReadableParticipationStatus[selectedStatus] }}
</div>
<Select v-else v-model="selectedStatus" class="relative z-10">
<SelectTrigger
:class="[
'w-full',
participationStatusColor[selectedStatus].background,
]"
>
<SelectValue placeholder="State">
{{ humanReadableParticipationStatus[selectedStatus] }}
</SelectValue>
</SelectTrigger>
<SelectContent>
<SelectItem
v-for="(state, i) in possibleStates"
:key="state"
:value="i + 1"
>
{{ humanReadableParticipationStatus[state] }}
</SelectItem>
</SelectContent>
</Select>
<div class="block w-full">
<Image
:src="image"
class="w-full h-32 object-contain rounded-lg pt-2"
/>
</div>
</CardContent>
<CardHeader>
<CardTitle>{{ title }}</CardTitle>
<Badge v-if="badge">{{ badge }}</Badge>
</CardHeader>
</Card>
</component>
</template>