mirror of
https://github.com/modrinth/code.git
synced 2026-08-27 01:54:47 +00:00
* feat: refactor button components
* fix: qa
* fix: storybook
* a11y: pass
* fix: build
* fix: rename default ->md
* fix: lint
* docs: buttons.md
* refactor part 1
* refactor part 2
* fix: undo refactor for fresh restart
* refactor
* Revert "refactor"
This reverts commit 96d65902d7.
* refactor: part 1
* fix: qa
* fix: qa
* fix: qa
* fix: qa
* fix: qa
* fix: qa
* fix: qa
* fix: qa
* fix: remove text-contrast
* fix: qa
* fix: v-tooltip
* fix: lint
* fix: split broken
* fix: passkey qa
* fix: qa
* fix: qa
* fix: prepr
* fix: splitbutton
* improve button group seam
---------
Signed-off-by: Calum H. <calum@modrinth.com>
Co-authored-by: Prospector <6166773+Prospector@users.noreply.github.com>
77 lines
2.1 KiB
Vue
77 lines
2.1 KiB
Vue
<script setup lang="ts">
|
|
import { CheckIcon, MailIcon } from '@modrinth/assets'
|
|
import { Button, defineMessages, injectModrinthClient, useVIntl } from '@modrinth/ui'
|
|
import { useQuery, useQueryClient } from '@tanstack/vue-query'
|
|
import { computed, ref } from 'vue'
|
|
|
|
const { formatMessage } = useVIntl()
|
|
|
|
const messages = defineMessages({
|
|
tooltipSubscribe: {
|
|
id: 'ui.newsletter-button.tooltip',
|
|
defaultMessage: 'Subscribe to the Modrinth newsletter',
|
|
},
|
|
subscribe: {
|
|
id: 'ui.newsletter-button.subscribe',
|
|
defaultMessage: 'Subscribe',
|
|
},
|
|
subscribed: {
|
|
id: 'ui.newsletter-button.subscribed',
|
|
defaultMessage: 'Subscribed!',
|
|
},
|
|
})
|
|
|
|
const auth = (await useAuth()) as unknown as {
|
|
value: { user: { id: string; username: string; email: string; created: string } }
|
|
}
|
|
const client = injectModrinthClient()
|
|
const queryClient = useQueryClient()
|
|
const showSubscriptionConfirmation = ref(false)
|
|
|
|
const { data: showSubscribeButton, isSuccess } = useQuery({
|
|
queryKey: computed(() => ['newsletter', 'subscribed', auth.value?.user?.id]),
|
|
queryFn: async () => {
|
|
if (auth.value?.user) {
|
|
try {
|
|
const { subscribed } = await client.labrinth.auth_internal.getNewsletterStatus()
|
|
return !subscribed
|
|
} catch {
|
|
return true
|
|
}
|
|
} else {
|
|
return false
|
|
}
|
|
},
|
|
enabled: computed(() => !!auth.value?.user),
|
|
})
|
|
|
|
async function subscribe() {
|
|
try {
|
|
await client.labrinth.auth_internal.subscribeNewsletter()
|
|
showSubscriptionConfirmation.value = true
|
|
} catch {
|
|
// Ignored
|
|
} finally {
|
|
setTimeout(() => {
|
|
showSubscriptionConfirmation.value = false
|
|
queryClient.setQueryData(['newsletter', 'subscribed', auth.value?.user?.id], false)
|
|
}, 2500)
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<Button
|
|
v-if="isSuccess && showSubscribeButton"
|
|
v-tooltip="formatMessage(messages.tooltipSubscribe)"
|
|
type="outlined"
|
|
class="!text-brand !shadow-[inset_0_0_0_1px_var(--color-brand)] [&>svg]:!text-brand"
|
|
@click="subscribe"
|
|
>
|
|
<template v-if="!showSubscriptionConfirmation">
|
|
<MailIcon /> {{ formatMessage(messages.subscribe) }}
|
|
</template>
|
|
<template v-else> <CheckIcon /> {{ formatMessage(messages.subscribed) }} </template>
|
|
</Button>
|
|
</template>
|