This repository has been archived by the owner on Aug 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 151
/
Copy pathfrog.vue
75 lines (64 loc) · 2.01 KB
/
frog.vue
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
<script setup lang="ts">
const vintl = useVIntl()
const { formatMessage } = vintl
const messages = defineMessages({
frogTitle: {
id: 'frog.title',
defaultMessage: 'Frog',
},
frogDescription: {
id: 'frog',
defaultMessage: "You've been frogged! 🐸",
},
frogAltText: {
id: 'frog.altText',
defaultMessage: 'A photorealistic painting of a frog labyrinth',
},
frogSinceOpened: {
id: 'frog.sinceOpened',
defaultMessage: 'This page was opened {ago}',
},
frogFroggedPeople: {
id: 'frog.froggedPeople',
defaultMessage:
'{count, plural, one {{count} more person} other {{count} more people}} were also frogged!',
},
})
const formatCompactNumber = useCompactNumber()
const formatRelativeTime = useRelativeTime()
const pageOpen = useState('frogPageOpen', () => Date.now())
const peopleFrogged = useState('frogPeopleFrogged', () => Math.round(Math.random() * 100_000_000))
const peopleFroggedCount = computed(() => formatCompactNumber(peopleFrogged.value))
let interval: ReturnType<typeof setTimeout>
const formattedOpenedCounter = ref(formatRelativeTime(Date.now()))
onMounted(() => {
interval = setInterval(() => {
formattedOpenedCounter.value = formatRelativeTime(pageOpen.value)
}, 1000)
})
onUnmounted(() => clearInterval(interval))
</script>
<template>
<div class="card">
<h1>{{ formatMessage(messages.frogTitle) }}</h1>
<p>{{ formatMessage(messages.frogDescription) }}</p>
<img src="https://cdn.modrinth.com/frog.png" :alt="formatMessage(messages.frogAltText)" />
<p>{{ formatMessage(messages.frogSinceOpened, { ago: formattedOpenedCounter }) }}</p>
<p>{{ formatMessage(messages.frogFroggedPeople, { count: peopleFroggedCount }) }}</p>
</div>
</template>
<style lang="scss" scoped>
.card {
width: calc(100% - 2 * var(--spacing-card-md));
max-width: 1280px;
margin-inline: auto;
text-align: center;
box-sizing: border-box;
margin-block: var(--spacing-card-md);
}
img {
margin-block: 0 1.5rem;
width: 60%;
max-width: 40rem;
}
</style>