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

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

398 lines · 11983 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 { useRouter, withBase } from 'vitepress'
 10import { computed, reactive, ref } from 'vue'
 11import {
 12  feedbackOptions,
 13  type FeedbackType,
 14  getFeedbackOption
 15} from '../../types/Feedback'
 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 prompt = computed(() => getPrompt())
122const toggleCard = () => (isCardShown.value = !isCardShown.value)
123</script>
124
125<template>
126  <template v-if="props.heading">
127    <button
128      @click="toggleCard()"
129      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"
130    >
131      <span
132        :class="isCardShown === false ? `i-lucide:mail` : `i-lucide:mail-x`"
133      />
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    >
141      <span
142        :class="isCardShown === false
143        ? `i-lucide:mail mr-2`
144        : `i-lucide:mail-x mr-2`"
145      />
146      <span>Send Feedback</span>
147    </button>
148  </template>
149
150  <Transition name="fade" mode="out-in">
151    <div
152      v-if="isCardShown"
153      class="border-$vp-c-divider bg-$vp-c-bg-alt b-rd-4 m-[2rem 0] mt-4 border-2 border-solid px-6 pt-3 pb-6"
154    >
155      <Transition name="fade" mode="out-in">
156        <div v-if="!feedback.type">
157          <p class="heading">
158            {{ helpfulText }}
159          </p>
160          <div class="flex flex-wrap gap-2">
161            <button
162              v-for="item in feedbackOptions"
163              :key="item.value"
164              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"
165              @click="handleSubmit(item.value)"
166            >
167              <span :class="[item.icon, 'mr-1 inline-block align-middle']" />
168              <span class="align-middle">{{ item.label }}</span>
169            </button>
170          </div>
171        </div>
172        <div v-else-if="feedback.type && !success" class="pt-2">
173          <div class="mb-3">
174            <span class="text-[22px] font-bold flex items-center gap-2">
175              <span :class="getFeedbackOption(feedback.type)?.icon" />
176              {{ getFeedbackOption(feedback.type)?.label }}
177            </span>
178          </div>
179
180          <div v-if="feedback.type === 'submit'" class="mb-2 text-sm">
181            <details>
182              <summary class="flex items-center gap-1">
183                <span class="i-lucide-arrow-right arrow-right" />
184                <span class="i-lucide-arrow-down arrow-down" />
185                <span class="i-lucide-shield-x bg-cerise-400" />
186                Things we won't add in the wiki
187              </summary>
188              <ol>
189                <li>
190                  Websites that are only or primarily for generative AI
191                  (Chatbot, roleplaying bot, ai art generator etc.)
192                </li>
193                <li>
194                  Sites that
195                  <ul>
196                    <li>imitate other websites</li>
197                    <li>have very small libraries</li>
198                    <li>only feature MTL'd works</li>
199                    <li>are mostly paywalled</li>
200                    <li>sell unofficial merch</li>
201                    <li>exlusively sell sex toys</li>
202                  </ul>
203                </li>
204                <li>Adult content sites similar to OnlyFans</li>
205                <li>
206                  Software that's too general (for example Windows OS related or
207                  Tweaking for privacy)
208                </li>
209                <li>Sites focused on lolicon or furry stuff</li>
210                <li>
211                  Sites scraping only a couple popular sources
212                </li>
213                <li>
214                  Sites scraping the servers of other scrapers
215                </li>
216                <li>
217                  Sites found in the Unsafe lists of
218                  <a
219                    href="https://privateers.wiki/unsafe"
220                    class="text-primary text-underline font-semibold"
221                  >
222                    Privateersclub
223                  </a>
224                  and/or
225                  <a
226                    href="https://rentry.org/pgames#untrusted-sites"
227                    class="text-primary text-underline font-semibold"
228                  >
229                    r/PiratedGames
230                  </a>
231                  .
232                </li>
233              </ol>
234            </details>
235            <details>
236              <summary class="flex items-center gap-1">
237                <span class="i-lucide-arrow-right arrow-right" />
238                <span class="i-lucide-arrow-down arrow-down" />
239                <span class="i-lucide-shield-alert bg-yellow-400" />
240                Things we will try to avoid
241              </summary>
242              <ol>
243                <li>Closed source software (with good FOSS alternatives)</li>
244                <li>
245                  Sites that only use hosters such Katfile, Nitroflare,
246                  DDownload and Rapidgator
247                </li>
248                <li>
249                  Sites that aren't primarily for anime but have it as a side
250                  product
251                </li>
252                <li>Things that are too niche and/or have a small userbase</li>
253              </ol>
254            </details>
255          </div>
256          <textarea
257            v-model="feedback.message"
258            autofocus
259            class="feedback-textarea 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"
260            :placeholder="prompt"
261          />
262          <p class="desc mb-2">
263            If you want a reply to your feedback, feel free to mention a contact
264            in the message or join our
265            <a
266              class="text-primary text-underline font-semibold"
267              href="https://discord.gg/wZMuSGpZ8s"
268            >
269              Discord.
270            </a>
271          </p>
272          <div class="flex flex-row gap-2">
273            <button
274              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"
275              @click="feedback.type = undefined"
276            >
277              <span class="i-lucide:arrow-left-from-line">close</span>
278            </button>
279            <button
280              type="submit"
281              style="background-color: #438afe; border-color: #438afe;" class="border rounded-lg transition-colors duration-250 inline-flex items-center gap-1 text-14px font-500 leading-1.5 px-3 py-1.5 text-center align-middle whitespace-nowrap disabled:opacity-50 text-white hover:brightness-110 disabled:opacity-50"
282              :disabled="isDisabled"
283              @click="handleSubmit()"
284            >
285              Send Feedback <span class="i-lucide:mail-check" />
286            </button>
287          </div>
288        </div>
289        <div v-else>
290          <p class="heading">Thanks for your feedback!</p>
291        </div>
292      </Transition>
293    </div>
294  </Transition>
295</template>
296
297<style scoped lang="css">
298.btn {
299  border: 1px solid var(--vp-c-divider);
300  background-color: var(--vp-c-bg);
301  border-radius: 8px;
302  transition: border-color 0.25s, background-color 0.25s;
303  display: inline-block;
304  font-size: 14px;
305  font-weight: 500;
306  line-height: 1.5;
307  margin: 0;
308  padding: 0.375rem 0.75rem;
309  text-align: center;
310  vertical-align: middle;
311  white-space: nowrap;
312}
313
314.btn:disabled {
315  opacity: 0.5;
316}
317
318.btn:hover {
319  border-color: var(--vp-c-brand);
320}
321
322.btn-primary {
323  color: #fff;
324  background-color: var(--vp-c-brand);
325  border-color: var(--vp-c-brand);
326}
327
328.btn-primary:hover {
329  background-color: var(--vp-c-brand-darker);
330  border-color: var(--vp-c-brand-darker);
331}
332
333.heading {
334  font-size: 1.2rem;
335  font-weight: 700;
336}
337
338.desc {
339  display: block;
340  font-size: 12px;
341  color: var(--vp-c-text-2);
342}
343
344.prompt-text {
345  display: block;
346  font-size: 10px;
347  color: var(--vp-c-text-2);
348  opacity: 0.75;
349}
350
351.feedback-textarea {
352  font-size: 14px;
353}
354
355.feedback-textarea::placeholder {
356  font-size: 12px;
357}
358
359details summary {
360  display: flex;
361  align-items: center;
362  gap: 0.25rem;
363  cursor: pointer;
364  list-style: none;
365}
366
367details summary::-webkit-details-marker {
368  display: none;
369}
370
371details summary .arrow-right {
372  display: inline-block;
373  flex-shrink: 0;
374}
375
376details summary .arrow-down {
377  display: none;
378  flex-shrink: 0;
379}
380
381details[open] summary .arrow-right {
382  display: none;
383}
384
385details[open] summary .arrow-down {
386  display: inline-block;
387}
388
389.fade-enter-active,
390.fade-leave-active {
391  transition: opacity 0.25s ease;
392}
393
394.fade-enter-from,
395.fade-leave-to {
396  opacity: 0;
397}
398</style>