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