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