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

12477b9242fb06be8abaf5f2b874b35addef3897
wotaku/docs/.vitepress/theme/components/Feedback.vue

391 lines · 12093 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  "Tips: Starring our GitHub repo increases the chances of your feedback being accepted twofold.",
 34  "Tips: Keep your feedback precise.",
 35  "Tips: Don't ask us questions as we can't really answer you here, join our Discord instead.",
 36  "Tips: If you are submitting a scraper site, mention all the sources.",
 37  "Tips: English, motherf**ker, do you speak it?!",
 38  "Fun fact: We don't maintain any extension repos, complaining to us won't solve your issue.",
 39  "Fun fact: We can't really add or fix any type of extensions.",
 40  "Fun fact: Meme is evil and has almost taken over the wiki.",
 41  "Fun fact: Bloat ≠ quality.",
 42  "Damn! We got a visitor!"
 43]
 44
 45function getPrompt() {
 46  return prompts[Math.floor(Math.random() * prompts.length)]
 47}
 48
 49const loading = ref<boolean>(false)
 50const error = ref<unknown>(null)
 51const success = ref<boolean>(false)
 52
 53const isDisabled = computed(() => {
 54  return (
 55    !feedback.message.length ||
 56    feedback.message.length < 5 ||
 57    feedback.message.length > 1000
 58  )
 59})
 60
 61const router = useRouter()
 62// prettier-ignore
 63const feedback = reactive<
 64  Pick<FeedbackType, 'message' | 'page'> & Partial<Pick<FeedbackType, 'type'>>
 65>({
 66  page: getURL(props.heading!),
 67  message: ''
 68})
 69
 70const selectedOption = ref(feedbackOptions[0])
 71
 72async function handleSubmit(type?: FeedbackType['type']) {
 73  if (type) {
 74    feedback.type = type
 75    selectedOption.value = getFeedbackOption(type)!
 76  }
 77  loading.value = true
 78
 79  const body: FeedbackType = {
 80    message: feedback.message,
 81    type: feedback.type!,
 82    page: feedback.page,
 83    ...(props.heading && { heading: props.heading })
 84  }
 85
 86  try {
 87    const response = await fetch('https://wotaku.tasky.workers.dev', {
 88      method: 'POST',
 89      headers: {
 90        'Content-Type': 'application/json'
 91      },
 92      body: JSON.stringify(body)
 93    })
 94
 95    const data = await response.json()
 96    if (data.error) {
 97      error.value = data.error
 98      return
 99    }
100    if (data.status === 'ok') {
101      success.value = true
102    }
103  } catch (err) {
104    error.value = err
105  } finally {
106    loading.value = false
107  }
108}
109
110const isCardShown = ref<boolean>(false)
111const helpfulText = props.heading
112  ? 'What do you think about this section?'
113  : 'What do you think about this page?'
114const prompt = computed(() => getPrompt())
115const toggleCard = () => (isCardShown.value = !isCardShown.value)
116</script>
117
118<template>
119  <template v-if="props.heading">
120    <button
121      @click="toggleCard()"
122      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"
123    >
124      <span
125        :class="isCardShown === false ? `i-lucide:mail` : `i-lucide:mail-x`"
126      />
127    </button>
128  </template>
129  <template v-else>
130    <button
131      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"
132      @click="toggleCard()"
133    >
134      <span
135        :class="isCardShown === false
136        ? `i-lucide:mail mr-2`
137        : `i-lucide:mail-x mr-2`"
138      />
139      <span>Send Feedback</span>
140    </button>
141  </template>
142
143  <Transition name="fade" mode="out-in">
144    <div
145      v-if="isCardShown"
146      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"
147    >
148      <Transition name="fade" mode="out-in">
149        <div v-if="!feedback.type">
150          <p class="heading">
151            {{ helpfulText }}
152          </p>
153          <div class="flex flex-wrap gap-2">
154            <button
155              v-for="item in feedbackOptions"
156              :key="item.value"
157              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"
158              @click="handleSubmit(item.value)"
159            >
160              <span :class="[item.icon, 'mr-1 inline-block align-middle']" />
161              <span class="align-middle">{{ item.label }}</span>
162            </button>
163          </div>
164        </div>
165        <div v-else-if="feedback.type && !success" class="pt-2">
166          <div class="mb-3">
167            <span class="text-[22px] font-bold flex items-center gap-2">
168              <span :class="getFeedbackOption(feedback.type)?.icon" />
169              {{ getFeedbackOption(feedback.type)?.label }}
170            </span>
171          </div>
172
173          <div v-if="feedback.type === 'submit'" class="mb-2 text-sm">
174            <details>
175              <summary class="flex items-center gap-1">
176                <span class="i-iconoir-nav-arrow-right arrow-right" />
177                <span class="i-iconoir-nav-arrow-down arrow-down" />
178                <span class="i-lucide-shield-x bg-cerise-400" />
179                Things we won't add in the wiki
180              </summary>
181              <ol>
182                <li>
183                  Websites that are only or primarily for generative AI
184                  (Chatbot, roleplaying bot, ai art generator etc.)
185                </li>
186                <li>
187                  Sites that
188                  <ul>
189                    <li>imitate other websites</li>
190                    <li>have very small libraries</li>
191                    <li>only feature MTL'd works</li>
192                    <li>are mostly paywalled</li>
193                    <li>sell unofficial merch</li>
194                    <li>exlusively sell sex toys</li>
195                  </ul>
196                </li>
197                <li>Adult content sites similar to OnlyFans</li>
198                <li>
199                  Software that's too general (for example Windows OS related or
200                  Tweaking for privacy)
201                </li>
202                <li>Sites focused on lolicon or furry stuff</li>
203                <li>
204                  Sites scraping only a couple popular sources
205                </li>
206                <li>
207                  Sites scraping the servers of other scrapers
208                </li>
209                <li>
210                  Sites found in the Unsafe lists of
211                  <a
212                    href="https://privateers.wiki/unsafe"
213                    class="text-primary text-underline font-semibold"
214                  >
215                    Privateersclub
216                  </a>
217                  and/or
218                  <a
219                    href="https://rentry.org/pgames#untrusted-sites"
220                    class="text-primary text-underline font-semibold"
221                  >
222                    r/PiratedGames
223                  </a>
224                  .
225                </li>
226              </ol>
227            </details>
228            <details>
229              <summary class="flex items-center gap-1">
230                <span class="i-iconoir-nav-arrow-right arrow-right" />
231                <span class="i-iconoir-nav-arrow-down arrow-down" />
232                <span class="i-lucide-shield-alert bg-yellow-400" />
233                Things we will try to avoid
234              </summary>
235              <ol>
236                <li>Closed source software (with good FOSS alternatives)</li>
237                <li>
238                  Sites that only use hosters such Katfile, Nitroflare,
239                  DDownload and Rapidgator
240                </li>
241                <li>
242                  Sites that aren't primarily for anime but have it as a side
243                  product
244                </li>
245                <li>Things that are too niche and/or have a small userbase</li>
246              </ol>
247            </details>
248          </div>
249          <textarea
250            v-model="feedback.message"
251            autofocus
252            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"
253            :placeholder="prompt"
254          />
255          <p class="desc mb-2">
256            If you want a reply to your feedback, feel free to mention a contact
257            in the message or join our
258            <a
259              class="text-primary text-underline font-semibold"
260              href="https://discord.gg/wZMuSGpZ8s"
261            >
262              Discord.
263            </a>
264          </p>
265          <div class="flex flex-row gap-2">
266            <button
267              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"
268              @click="feedback.type = undefined"
269            >
270              <span class="i-lucide:arrow-left-from-line">close</span>
271            </button>
272            <button
273              type="submit"
274              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"
275              :disabled="isDisabled"
276              @click="handleSubmit()"
277            >
278              Send Feedback <span class="i-lucide:mail-check" />
279            </button>
280          </div>
281        </div>
282        <div v-else>
283          <p class="heading">Thanks for your feedback!</p>
284        </div>
285      </Transition>
286    </div>
287  </Transition>
288</template>
289
290<style scoped lang="css">
291.btn {
292  border: 1px solid var(--vp-c-divider);
293  background-color: var(--vp-c-bg);
294  border-radius: 8px;
295  transition: border-color 0.25s, background-color 0.25s;
296  display: inline-block;
297  font-size: 14px;
298  font-weight: 500;
299  line-height: 1.5;
300  margin: 0;
301  padding: 0.375rem 0.75rem;
302  text-align: center;
303  vertical-align: middle;
304  white-space: nowrap;
305}
306
307.btn:disabled {
308  opacity: 0.5;
309}
310
311.btn:hover {
312  border-color: var(--vp-c-brand);
313}
314
315.btn-primary {
316  color: #fff;
317  background-color: var(--vp-c-brand);
318  border-color: var(--vp-c-brand);
319}
320
321.btn-primary:hover {
322  background-color: var(--vp-c-brand-darker);
323  border-color: var(--vp-c-brand-darker);
324}
325
326.heading {
327  font-size: 1.2rem;
328  font-weight: 700;
329}
330
331.desc {
332  display: block;
333  font-size: 12px;
334  color: var(--vp-c-text-2);
335}
336
337.prompt-text {
338  display: block;
339  font-size: 10px;
340  color: var(--vp-c-text-2);
341  opacity: 0.75;
342}
343
344.feedback-textarea {
345  font-size: 14px;
346}
347
348.feedback-textarea::placeholder {
349  font-size: 12px;
350}
351
352details summary {
353  display: flex;
354  align-items: center;
355  gap: 0.25rem;
356  cursor: pointer;
357  list-style: none;
358}
359
360details summary::-webkit-details-marker {
361  display: none;
362}
363
364details summary .arrow-right {
365  display: inline-block;
366  flex-shrink: 0;
367}
368
369details summary .arrow-down {
370  display: none;
371  flex-shrink: 0;
372}
373
374details[open] summary .arrow-right {
375  display: none;
376}
377
378details[open] summary .arrow-down {
379  display: inline-block;
380}
381
382.fade-enter-active,
383.fade-leave-active {
384  transition: opacity 0.25s ease;
385}
386
387.fade-enter-from,
388.fade-leave-to {
389  opacity: 0;
390}
391</style>