docs/.vitepress/theme/components/Feedback.vue

6d09ee3bcdf292e5dc6d7e2b58b2610ce9cc4b0f
wotaku/docs/.vitepress/theme/components/Feedback.vue history · blame · raw

325 lines · 10898 bytes

  1<!--
  2  All Rights Reserved
  3
  4  Copyright (c) 2025 taskylizard
  5
  6  All rights reserved. This code and its associated files may not be copied, modified, distributed, sublicensed, or used in any form, in whole or in part, without prior written permission from the copyright holder.
  7-->
  8<script setup lang="ts">
  9import { computed, ref, reactive } from 'vue'
 10import {
 11  feedbackOptions,
 12  type FeedbackType,
 13  getFeedbackOption
 14} from '../../types/Feedback'
 15import { useRouter, withBase } from 'vitepress'
 16
 17const props = defineProps<{
 18  heading?: string
 19}>()
 20
 21const sluggify = (text: string) =>
 22  text
 23    .toLowerCase()
 24    .replace(/[^a-z0-9_]+/g, '-')
 25    .replace(/--+/g, '-')
 26    .replace(/(^-+|-+$)/g, '')
 27    .substring(0, 60)
 28
 29const getURL = (heading: string) =>
 30  `https://wotaku.wiki${withBase(router.route.path)}#${sluggify(heading)}`
 31
 32const prompts = [
 33  'Make it count!',
 34  'Leave some feedback for us!',
 35  `We're all ears 🐰`,
 36  'Tell us what is missing in Wotaku',
 37  'Your thoughts matter to us 💡',
 38  'Feedback is a gift 🎁',
 39  'What do you think?',
 40  'We appreciate your support 🙏',
 41  'We need your help 👋',
 42  'Your feedback is valuable 💯',
 43  'So... what do you think?',
 44  "I guess you don't need to say anything 😉",
 45  'Spill the beans 💣',
 46  "We're always looking for ways to improve!.",
 47  'aliens are watching you 👽',
 48  'tasky was here 👀',
 49  'The internet is full of crap 😱'
 50]
 51
 52function getPrompt() {
 53  return prompts[Math.floor(Math.random() * prompts.length)]
 54}
 55
 56const loading = ref<boolean>(false)
 57const error = ref<unknown>(null)
 58const success = ref<boolean>(false)
 59
 60const isDisabled = computed(() => {
 61  return (
 62    !feedback.message.length ||
 63    feedback.message.length < 5 ||
 64    feedback.message.length > 1000
 65  )
 66})
 67
 68const router = useRouter()
 69// prettier-ignore
 70const feedback = reactive<
 71  Pick<FeedbackType, "message" | "page"> & Partial<Pick<FeedbackType, "type">>
 72>({
 73  page: getURL(props.heading!),
 74  message: "",
 75});
 76
 77const selectedOption = ref(feedbackOptions[0])
 78
 79async function handleSubmit(type?: FeedbackType['type']) {
 80  if (type) {
 81    feedback.type = type
 82    selectedOption.value = getFeedbackOption(type)!
 83  }
 84  loading.value = true
 85
 86  const body: FeedbackType = {
 87    message: feedback.message,
 88    type: feedback.type!,
 89    page: feedback.page,
 90    ...(props.heading && { heading: props.heading })
 91  }
 92
 93  try {
 94    const response = await fetch('https://wotaku.tasky.workers.dev', {
 95      method: 'POST',
 96      headers: {
 97        'Content-Type': 'application/json'
 98      },
 99      body: JSON.stringify(body)
100    })
101
102    const data = await response.json()
103    if (data.error) {
104      error.value = data.error
105      return
106    }
107    if (data.status === 'ok') {
108      success.value = true
109    }
110  } catch (err) {
111    error.value = err
112  } finally {
113    loading.value = false
114  }
115}
116
117const isCardShown = ref<boolean>(false)
118const helpfulText = props.heading
119  ? 'What do you think about this section?'
120  : 'What do you think about this page?'
121const helpfulDescription = props.heading
122  ? 'Let us know how helpful this section is.'
123  : 'Let us know how helpful this page is.'
124
125const prompt = computed(() => getPrompt())
126const toggleCard = () => (isCardShown.value = !isCardShown.value)
127</script>
128
129<template>
130  <template v-if="props.heading">
131    <button @click="toggleCard()"
132      class="bg-$vp-c-default-soft text-primary border-$vp-c-default-soft hover:border-primary ml-3 inline-flex h-7 items-center justify-center whitespace-nowrap rounded-md border-2 border-solid px-1.5 py-3.5 text-sm font-medium transition-all duration-300 sm:h-6">
133      <span :class="isCardShown === false ? `i-lucide:mail` : `i-lucide:mail-x`" />
134    </button>
135  </template>
136  <template v-else>
137    <button
138      class="bg-$vp-c-default-soft text-primary px2 py1 border-$vp-c-default-soft hover:border-primary mt-2 select-none rounded border-2 border-solid font-bold transition-all duration-300"
139      @click="toggleCard()">
140      <span :class="isCardShown === false ? `i-lucide:mail mr-2` : `i-lucide:mail-x mr-2`
141        " />
142      <span>Send Feedback</span>
143    </button>
144  </template>
145
146  <Transition name="fade" mode="out-in">
147    <div v-if="isCardShown"
148      class="border-$vp-c-divider bg-$vp-c-bg-alt b-rd-4 m-[2rem 0] mt-4 border-2 border-solid p-6">
149      <Transition name="fade" mode="out-in">
150        <div v-if="!feedback.type">
151          <p class="heading">
152            {{ helpfulText }}
153          </p>
154          <div class="flex flex-wrap gap-2">
155            <button v-for="item in feedbackOptions" :key="item.value"
156              class="bg-bg border-$vp-c-default-soft hover:border-primary mt-2 select-none rounded border-2 border-solid font-bold transition-all duration-250 rounded-lg text-[14px] font-500 leading-normal m-0 px-3 py-1.5 text-center align-middle whitespace-nowrap"
157              @click="handleSubmit(item.value)">
158              <span>{{ item.label }}</span>
159            </button>
160          </div>
161        </div>
162        <div v-else-if="feedback.type && !success">
163          <div class="mb-2">
164            <p class="desc">{{ helpfulDescription }} - {{ prompt }}</p>
165            <span>{{ getFeedbackOption(feedback.type)?.label }}</span>
166          </div>
167
168          <div v-if="feedback.type === 'suggestion'" class="mb-2 text-sm">
169            <details>
170              <summary>
171                <span class="i-lucide-shield-x bg-cerise-400 mb-1 ml-1" />
172                Things we won't add in the wiki
173              </summary>
174              <ol>
175                <li>
176                  Websites that are only or primarily for generative AI
177                  (Chatbot, roleplaying bot, ai art generator etc.)
178                </li>
179                <li>
180                  Sites that
181                  <ul>
182                    <li>imitate other websites</li>
183                    <li>have very small libraries</li>
184                    <li>only feature MTL'd works</li>
185                    <li>are mostly paywalled</li>
186                    <li>sell unofficial merch</li>
187                    <li>exlusively sell sex toys</li>
188                  </ul>
189                </li>
190                <li>Adult content sites similar to OnlyFans</li>
191                <li>
192                  Software that's too general (for example Windows OS related or
193                  Tweaking for privacy)
194                </li>
195                <li>Sites focused on lolicon or furry stuff</li>
196                <li>
197                  Sites scraping only one or two common sources, such as HiAnime
198                  or Animepahe
199                </li>
200                <li>
201                  Sites found in the Unsafe lists of
202                  <a href="https://fmhy.net/unsafesites" class="text-primary text-underline font-semibold">
203                    FMHY
204                  </a>
205                  ,
206                  <a href="https://megathread.pages.dev/unsafe" class="text-primary text-underline font-semibold">
207                    Privateersclub
208                  </a>
209                  and/or
210                  <a href="https://rentry.org/pgames#untrusted-sites" class="text-primary text-underline font-semibold">
211                    r/PiratedGames
212                  </a>
213                  .
214                </li>
215              </ol>
216            </details>
217            <details>
218              <summary>
219                <span class="i-lucide-shield-alert bg-cerise-400 mb-1 ml-1" />
220                Things we will try to avoid
221              </summary>
222              <ol>
223                <li>Closed source software (with good FOSS alternatives)</li>
224                <li>
225                  Sites that only use hosters such Katfile, Nitroflare,
226                  DDownload and Rapidgator
227                </li>
228                <li>
229                  Sites that aren't primarily for anime but have it as a side
230                  product
231                </li>
232                <li>Things that are too niche and/or have a small userbase</li>
233              </ol>
234            </details>
235          </div>
236          <textarea v-model="feedback.message" autofocus
237            class="bg-$vp-c-bg-alt text-$vp-c-text-2 w-full h-[100px] border border-$vp-c-divider rounded px-3 py-1.5 border-$vp-c-divider bg-$vp-c-bg-alt b-rd-4 border-2 border-solid"
238            placeholder="Tip: Did you know that starring our GitHub repo doubles the chances that your feedback will be read?" />
239          <p class="desc mb-2">
240            If you want a reply to your feedback, feel free to mention a contact
241            in the message or join our
242            <a class="text-primary text-underline font-semibold" href="https://discord.gg/wZMuSGpZ8s">
243              Discord.
244            </a>
245          </p>
246          <div class="flex flex-row gap-2">
247            <button
248              class="bg-$vp-c-default-soft text-primary border-$vp-c-default-soft inline-flex h-7 items-center justify-center whitespace-nowrap rounded-md border-2 border-solid px-1.5 py-3.5 text-sm font-medium transition-all duration-300 sm:h-6"
249              @click="feedback.type = undefined">
250              <span class="i-lucide:panel-left-close">close</span>
251            </button>
252            <button type="submit"
253              class="border border-div rounded-lg transition-colors duration-250 inline-block text-14px font-500 leading-1.5 px-3 py-3 text-center align-middle whitespace-nowrap disabled:opacity-50 text-text-2 bg-swarm-100 dark:bg-swarm-700 border-swarm-800 dark:border-swarm-700 disabled:bg-swarm-100 dark:disabled:bg-swarm-900 hover:border-swarm-900 dark:hover:border-swarm-800 hover:bg-swarm-200 dark:hover:bg-swarm-800"
254              :disabled="isDisabled" @click="handleSubmit()">
255              Send Feedback 📩
256            </button>
257          </div>
258        </div>
259        <div v-else>
260          <p class="heading">Thanks for your feedback!</p>
261        </div>
262      </Transition>
263    </div>
264  </Transition>
265</template>
266
267<style scoped lang="css">
268.btn {
269  border: 1px solid var(--vp-c-divider);
270  background-color: var(--vp-c-bg);
271  border-radius: 8px;
272  transition:
273    border-color 0.25s,
274    background-color 0.25s;
275  display: inline-block;
276  font-size: 14px;
277  font-weight: 500;
278  line-height: 1.5;
279  margin: 0;
280  padding: 0.375rem 0.75rem;
281  text-align: center;
282  vertical-align: middle;
283  white-space: nowrap;
284}
285
286.btn:disabled {
287  opacity: 0.5;
288}
289
290.btn:hover {
291  border-color: var(--vp-c-brand);
292}
293
294.btn-primary {
295  color: #fff;
296  background-color: var(--vp-c-brand);
297  border-color: var(--vp-c-brand);
298}
299
300.btn-primary:hover {
301  background-color: var(--vp-c-brand-darker);
302  border-color: var(--vp-c-brand-darker);
303}
304
305.heading {
306  font-size: 1.2rem;
307  font-weight: 700;
308}
309
310.desc {
311  display: block;
312  font-size: 12px;
313  color: var(--vp-c-text-2);
314}
315
316.fade-enter-active,
317.fade-leave-active {
318  transition: opacity 0.25s ease;
319}
320
321.fade-enter-from,
322.fade-leave-to {
323  opacity: 0;
324}
325</style>