docs/.vitepress/theme/components/Feedback.vue
355 lines · 11297 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 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
132 @click="toggleCard()"
133 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"
134 >
135 <span
136 :class="isCardShown === false ? `i-lucide:mail` : `i-lucide:mail-x`"
137 />
138 </button>
139 </template>
140 <template v-else>
141 <button
142 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"
143 @click="toggleCard()"
144 >
145 <span
146 :class="isCardShown === false
147 ? `i-lucide:mail mr-2`
148 : `i-lucide:mail-x mr-2`"
149 />
150 <span>Send Feedback</span>
151 </button>
152 </template>
153
154 <Transition name="fade" mode="out-in">
155 <div
156 v-if="isCardShown"
157 class="border-$vp-c-divider bg-$vp-c-bg-alt b-rd-4 m-[2rem 0] mt-4 border-2 border-solid p-6"
158 >
159 <Transition name="fade" mode="out-in">
160 <div v-if="!feedback.type">
161 <p class="heading">
162 {{ helpfulText }}
163 </p>
164 <div class="flex flex-wrap gap-2">
165 <button
166 v-for="item in feedbackOptions"
167 :key="item.value"
168 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"
169 @click="handleSubmit(item.value)"
170 >
171 <span>{{ item.label }}</span>
172 </button>
173 </div>
174 </div>
175 <div v-else-if="feedback.type && !success">
176 <div class="mb-2">
177 <p class="desc">{{ helpfulDescription }} - {{ prompt }}</p>
178 <span>{{ getFeedbackOption(feedback.type)?.label }}</span>
179 </div>
180
181 <div v-if="feedback.type === 'suggestion'" class="mb-2 text-sm">
182 <details>
183 <summary>
184 <span class="i-lucide-shield-x bg-cerise-400 mb-1 ml-1" />
185 Things we won't add in the wiki
186 </summary>
187 <ol>
188 <li>
189 Websites that are only or primarily for generative AI
190 (Chatbot, roleplaying bot, ai art generator etc.)
191 </li>
192 <li>
193 Sites that
194 <ul>
195 <li>imitate other websites</li>
196 <li>have very small libraries</li>
197 <li>only feature MTL'd works</li>
198 <li>are mostly paywalled</li>
199 <li>sell unofficial merch</li>
200 <li>exlusively sell sex toys</li>
201 </ul>
202 </li>
203 <li>Adult content sites similar to OnlyFans</li>
204 <li>
205 Software that's too general (for example Windows OS related or
206 Tweaking for privacy)
207 </li>
208 <li>Sites focused on lolicon or furry stuff</li>
209 <li>
210 Sites scraping only one or two common sources, such as HiAnime
211 or Animepahe
212 </li>
213 <li>
214 Sites found in the Unsafe lists of
215 <a
216 href="https://fmhy.net/unsafesites"
217 class="text-primary text-underline font-semibold"
218 >
219 FMHY
220 </a>
221 ,
222 <a
223 href="https://megathread.pages.dev/unsafe"
224 class="text-primary text-underline font-semibold"
225 >
226 Privateersclub
227 </a>
228 and/or
229 <a
230 href="https://rentry.org/pgames#untrusted-sites"
231 class="text-primary text-underline font-semibold"
232 >
233 r/PiratedGames
234 </a>
235 .
236 </li>
237 </ol>
238 </details>
239 <details>
240 <summary>
241 <span class="i-lucide-shield-alert bg-cerise-400 mb-1 ml-1" />
242 Things we will try to avoid
243 </summary>
244 <ol>
245 <li>Closed source software (with good FOSS alternatives)</li>
246 <li>
247 Sites that only use hosters such Katfile, Nitroflare,
248 DDownload and Rapidgator
249 </li>
250 <li>
251 Sites that aren't primarily for anime but have it as a side
252 product
253 </li>
254 <li>Things that are too niche and/or have a small userbase</li>
255 </ol>
256 </details>
257 </div>
258 <textarea
259 v-model="feedback.message"
260 autofocus
261 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"
262 placeholder="Tip: Did you know that starring our GitHub repo doubles the chances that your feedback will be read?"
263 />
264 <p class="desc mb-2">
265 If you want a reply to your feedback, feel free to mention a contact
266 in the message or join our
267 <a
268 class="text-primary text-underline font-semibold"
269 href="https://discord.gg/wZMuSGpZ8s"
270 >
271 Discord.
272 </a>
273 </p>
274 <div class="flex flex-row gap-2">
275 <button
276 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"
277 @click="feedback.type = undefined"
278 >
279 <span class="i-lucide:panel-left-close">close</span>
280 </button>
281 <button
282 type="submit"
283 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"
284 :disabled="isDisabled"
285 @click="handleSubmit()"
286 >
287 Send Feedback 📩
288 </button>
289 </div>
290 </div>
291 <div v-else>
292 <p class="heading">Thanks for your feedback!</p>
293 </div>
294 </Transition>
295 </div>
296 </Transition>
297</template>
298
299<style scoped lang="css">
300.btn {
301 border: 1px solid var(--vp-c-divider);
302 background-color: var(--vp-c-bg);
303 border-radius: 8px;
304 transition: border-color 0.25s, background-color 0.25s;
305 display: inline-block;
306 font-size: 14px;
307 font-weight: 500;
308 line-height: 1.5;
309 margin: 0;
310 padding: 0.375rem 0.75rem;
311 text-align: center;
312 vertical-align: middle;
313 white-space: nowrap;
314}
315
316.btn:disabled {
317 opacity: 0.5;
318}
319
320.btn:hover {
321 border-color: var(--vp-c-brand);
322}
323
324.btn-primary {
325 color: #fff;
326 background-color: var(--vp-c-brand);
327 border-color: var(--vp-c-brand);
328}
329
330.btn-primary:hover {
331 background-color: var(--vp-c-brand-darker);
332 border-color: var(--vp-c-brand-darker);
333}
334
335.heading {
336 font-size: 1.2rem;
337 font-weight: 700;
338}
339
340.desc {
341 display: block;
342 font-size: 12px;
343 color: var(--vp-c-text-2);
344}
345
346.fade-enter-active,
347.fade-leave-active {
348 transition: opacity 0.25s ease;
349}
350
351.fade-enter-from,
352.fade-leave-to {
353 opacity: 0;
354}
355</style>