You've already forked AstralRinth
forked from didirus/AstralRinth
* feat: blog migration w/ fixes Co-authored-by: Prospector <prospectordev@gmail.com> * feat: add changelog button to news page * fix: lint issues * refactor: replace nuxt content with `@modrinth/blog` * feat: shared public folder * feat: try lazy loading html content * feat: rss + hide newsletter btn + blog.config.ts * feat: add new chapter modrinth servers post * fix: lint issues * fix: only generate RSS feed if changes detected * fix: utils dep * fix: lockfile dep * feat: GET /email/subscribe + subscription button * fix: lint issues * feat: articles.json for app * Made grid more responsive * fix: changes * Make margin slightly smaller in lists * Fix footer link * feat: latest news * Fix responsiveness * Remove old utm link * Update changelog * Lint --------- Co-authored-by: Prospector <prospectordev@gmail.com>
52 lines
1.3 KiB
Vue
52 lines
1.3 KiB
Vue
<script setup lang="ts">
|
|
import { ButtonStyled } from "@modrinth/ui";
|
|
import { MailIcon, CheckIcon } from "@modrinth/assets";
|
|
import { ref, watchEffect } from "vue";
|
|
import { useBaseFetch } from "~/composables/fetch.js";
|
|
|
|
const auth = await useAuth();
|
|
const showSubscriptionConfirmation = ref(false);
|
|
const subscribed = ref(false);
|
|
|
|
async function checkSubscribed() {
|
|
if (auth.value?.user) {
|
|
try {
|
|
const { data } = await useBaseFetch("auth/email/subscribe", {
|
|
method: "GET",
|
|
});
|
|
subscribed.value = data?.subscribed || false;
|
|
} catch {
|
|
subscribed.value = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
watchEffect(() => {
|
|
checkSubscribed();
|
|
});
|
|
|
|
async function subscribe() {
|
|
try {
|
|
await useBaseFetch("auth/email/subscribe", {
|
|
method: "POST",
|
|
});
|
|
showSubscriptionConfirmation.value = true;
|
|
} catch {
|
|
} finally {
|
|
setTimeout(() => {
|
|
showSubscriptionConfirmation.value = false;
|
|
subscribed.value = true;
|
|
}, 2500);
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<ButtonStyled v-if="auth?.user && !subscribed" color="brand" type="outlined">
|
|
<button v-tooltip="`Subscribe to the Modrinth newsletter`" @click="subscribe">
|
|
<template v-if="!showSubscriptionConfirmation"> <MailIcon /> Subscribe </template>
|
|
<template v-else> <CheckIcon /> Subscribed! </template>
|
|
</button>
|
|
</ButtonStyled>
|
|
</template>
|