docs/.vitepress/theme/components/Feedback.vue
357 lines · 11349 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 a couple popular sources
211 </li>
212 <li>
213 Sites scraping the servers of other scrapers
214 </li>
215 <li>
216 Sites found in the Unsafe lists of
217 <a
218 href="https://fmhy.net/unsafesites"
219 class="text-primary text-underline font-semibold"
220 >
221 FMHY
222 </a>
223 ,
224 <a
225 href="https://privateers.wiki/unsafe"
226 class="text-primary text-underline font-semibold"
227 >
228 Privateersclub
229 </a>
230 and/or
231 <a
232 href="https://rentry.org/pgames#untrusted-sites"
233 class="text-primary text-underline font-semibold"
234 >
235 r/PiratedGames
236 </a>
237 .
238 </li>
239 </ol>
240 </details>
241 <details>
242 <summary>
243 <span class="i-lucide-shield-alert bg-cerise-400 mb-1 ml-1" />
244 Things we will try to avoid
245 </summary>
246 <ol>
247 <li>Closed source software (with good FOSS alternatives)</li>
248 <li>
249 Sites that only use hosters such Katfile, Nitroflare,
250 DDownload and Rapidgator
251 </li>
252 <li>
253 Sites that aren't primarily for anime but have it as a side
254 product
255 </li>
256 <li>Things that are too niche and/or have a small userbase</li>
257 </ol>
258 </details>
259 </div>
260 <textarea
261 v-model="feedback.message"
262 autofocus
263 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"
264 placeholder="Tip: Did you know that starring our GitHub repo doubles the chances that your feedback will be read?"
265 />
266 <p class="desc mb-2">
267 If you want a reply to your feedback, feel free to mention a contact
268 in the message or join our
269 <a
270 class="text-primary text-underline font-semibold"
271 href="https://discord.gg/wZMuSGpZ8s"
272 >
273 Discord.
274 </a>
275 </p>
276 <div class="flex flex-row gap-2">
277 <button
278 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"
279 @click="feedback.type = undefined"
280 >
281 <span class="i-lucide:panel-left-close">close</span>
282 </button>
283 <button
284 type="submit"
285 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"
286 :disabled="isDisabled"
287 @click="handleSubmit()"
288 >
289 Send Feedback 📩
290 </button>
291 </div>
292 </div>
293 <div v-else>
294 <p class="heading">Thanks for your feedback!</p>
295 </div>
296 </Transition>
297 </div>
298 </Transition>
299</template>
300
301<style scoped lang="css">
302.btn {
303 border: 1px solid var(--vp-c-divider);
304 background-color: var(--vp-c-bg);
305 border-radius: 8px;
306 transition: border-color 0.25s, background-color 0.25s;
307 display: inline-block;
308 font-size: 14px;
309 font-weight: 500;
310 line-height: 1.5;
311 margin: 0;
312 padding: 0.375rem 0.75rem;
313 text-align: center;
314 vertical-align: middle;
315 white-space: nowrap;
316}
317
318.btn:disabled {
319 opacity: 0.5;
320}
321
322.btn:hover {
323 border-color: var(--vp-c-brand);
324}
325
326.btn-primary {
327 color: #fff;
328 background-color: var(--vp-c-brand);
329 border-color: var(--vp-c-brand);
330}
331
332.btn-primary:hover {
333 background-color: var(--vp-c-brand-darker);
334 border-color: var(--vp-c-brand-darker);
335}
336
337.heading {
338 font-size: 1.2rem;
339 font-weight: 700;
340}
341
342.desc {
343 display: block;
344 font-size: 12px;
345 color: var(--vp-c-text-2);
346}
347
348.fade-enter-active,
349.fade-leave-active {
350 transition: opacity 0.25s ease;
351}
352
353.fade-enter-from,
354.fade-leave-to {
355 opacity: 0;
356}
357</style>