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