docs/.vitepress/theme/components/Feedback.vue
384 lines · 12306 bytes
1<!--
2 Copyright (c) 2024 taskylizard
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15-->
16<script setup lang="ts">
17import { computed, ref, reactive } from 'vue'
18import {
19 feedbackOptions,
20 type FeedbackType,
21 getFeedbackOption
22} from '../../types/Feedback'
23import { useRouter, withBase } from 'vitepress'
24
25const props = defineProps<{
26 heading?: string
27}>()
28
29const sluggify = (text: string) =>
30 text
31 .toLowerCase()
32 .replace(/[^a-z0-9_]+/g, '-')
33 .replace(/--+/g, '-')
34 .replace(/(^-+|-+$)/g, '')
35 .substring(0, 60)
36
37const getURL = (heading: string) =>
38 `https://wotaku.wiki${withBase(router.route.path)}#${sluggify(heading)}`
39
40const prompts = [
41 'Make it count!',
42 'Leave some feedback for us!',
43 `We're all ears 🐰`,
44 'Tell us what is missing in Wotaku',
45 'Your thoughts matter to us 💡',
46 'Feedback is a gift 🎁',
47 'What do you think?',
48 'We appreciate your support 🙏',
49 'We need your help 👋',
50 'Your feedback is valuable 💯',
51 'So... what do you think?',
52 "I guess you don't need to say anything 😉",
53 'Spill the beans 💣',
54 "We're always looking for ways to improve!.",
55 'aliens are watching you 👽',
56 'tasky was here 👀',
57 'The internet is full of crap 😱'
58]
59
60function getPrompt() {
61 return prompts[Math.floor(Math.random() * prompts.length)]
62}
63
64const messages = {
65 suggestion: [
66 "We're glad you want to share your ideas!",
67 'Nix the fluff and just tell us what you think!',
68 "We'll be happy to read your thoughts and incorporate them into our wiki.",
69 "Hello! We're glad you want to share your ideas!"
70 ],
71 appreciation: [
72 'We appreciate your support!',
73 "We're always looking for ways to improve!"
74 ],
75 other: ["We're always looking for ways to improve!"]
76}
77
78function getMessage(type: FeedbackType['type']) {
79 return messages[type][Math.floor(Math.random() * messages[type].length)]
80}
81
82const loading = ref<boolean>(false)
83const error = ref<unknown>(null)
84const success = ref<boolean>(false)
85
86const isDisabled = computed(() => {
87 return (
88 !feedback.message.length ||
89 feedback.message.length < 5 ||
90 feedback.message.length > 1000
91 )
92})
93
94const router = useRouter()
95// prettier-ignore
96const feedback = reactive<
97 Pick<FeedbackType, 'message' | 'page'> & Partial<Pick<FeedbackType, 'type'>>
98>({
99 page: getURL(props.heading!),
100 message: ''
101})
102
103const selectedOption = ref(feedbackOptions[0])
104
105async function handleSubmit(type?: FeedbackType['type']) {
106 if (type) {
107 feedback.type = type
108 selectedOption.value = getFeedbackOption(type)!
109 }
110 loading.value = true
111
112 const body: FeedbackType = {
113 message: feedback.message,
114 type: feedback.type!,
115 page: feedback.page,
116 ...(props.heading && { heading: props.heading })
117 }
118
119 try {
120 const response = await fetch('https://wotaku.tasky.workers.dev', {
121 method: 'POST',
122 headers: {
123 'Content-Type': 'application/json'
124 },
125 body: JSON.stringify(body)
126 })
127
128 const data = await response.json()
129 if (data.error) {
130 error.value = data.error
131 return
132 }
133 if (data.status === 'ok') {
134 success.value = true
135 }
136 } catch (err) {
137 error.value = err
138 } finally {
139 loading.value = false
140 }
141}
142
143const isCardShown = ref<boolean>(false)
144const helpfulText = props.heading
145 ? 'What do you think about this section?'
146 : 'What do you think about this page?'
147const helpfulDescription = props.heading
148 ? 'Let us know how helpful this section is.'
149 : 'Let us know how helpful this page is.'
150
151const prompt = computed(() => getPrompt())
152const message = computed(() => getMessage(feedback.type!))
153const toggleCard = () => (isCardShown.value = !isCardShown.value)
154</script>
155
156<template>
157 <template v-if="props.heading">
158 <button
159 @click="toggleCard()"
160 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"
161 >
162 <span
163 :class="isCardShown === false ? `i-lucide:mail` : `i-lucide:mail-x`"
164 />
165 </button>
166 </template>
167 <template v-else>
168 <button
169 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"
170 @click="toggleCard()"
171 >
172 <span
173 :class="
174 isCardShown === false ? `i-lucide:mail mr-2` : `i-lucide:mail-x mr-2`
175 "
176 />
177 <span>Send Feedback</span>
178 </button>
179 </template>
180
181 <Transition name="fade" mode="out-in">
182 <div
183 v-if="isCardShown"
184 class="border-$vp-c-divider bg-$vp-c-bg-alt b-rd-4 m-[2rem 0] mt-4 border-2 border-solid p-6"
185 >
186 <Transition name="fade" mode="out-in">
187 <div v-if="!feedback.type">
188 <p class="heading">
189 {{ helpfulText }}
190 </p>
191 <div class="flex flex-wrap gap-2">
192 <button
193 v-for="item in feedbackOptions"
194 :key="item.value"
195 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"
196 @click="handleSubmit(item.value)"
197 >
198 <span>{{ item.label }}</span>
199 </button>
200 </div>
201 </div>
202 <div v-else-if="feedback.type && !success">
203 <div>
204 <p class="desc">{{ helpfulDescription }} - {{ prompt }}</p>
205 <span>{{ getFeedbackOption(feedback.type)?.label }}</span>
206 </div>
207 <p class="heading" v-text="message"></p>
208 <div v-if="feedback.type === 'suggestion'" class="mb-2 text-sm">
209 <details>
210 <summary>
211 <span class="i-lucide-shield-x bg-cerise-400 mb-1 ml-1" />
212 Things we won't add in the wiki
213 </summary>
214 <ol>
215 <li>
216 Websites that are only or primarily for generative AI
217 (Chatbot, roleplaying bot, ai art generator etc.)
218 </li>
219 <li>
220 Sites that
221 <ul>
222 <li>imitate other websites</li>
223 <li>have very small libraries</li>
224 <li>only feature MTL'd works</li>
225 <li>are mostly paywalled</li>
226 <li>sell unofficial merch</li>
227 <li>exlusively sell sex toys</li>
228 </ul>
229 </li>
230 <li>Adult content sites similar to OnlyFans</li>
231 <li>
232 Software that's too general (for example Windows OS related or
233 Tweaking for privacy)
234 </li>
235 <li>Sites focused on lolicon or furry stuff</li>
236 <li>
237 Sites scraping only one or two common sources, such as HiAnime
238 or Animepahe
239 </li>
240 <li>
241 Sites found in the Unsafe lists of
242 <a
243 href="https://fmhy.net/unsafesites"
244 class="text-primary text-underline font-semibold"
245 >
246 FMHY
247 </a>
248 ,
249 <a
250 href="https://megathread.pages.dev/unsafe"
251 class="text-primary text-underline font-semibold"
252 >
253 Privateersclub
254 </a>
255 and/or
256 <a
257 href="https://rentry.org/pgames#untrusted-sites"
258 class="text-primary text-underline font-semibold"
259 >
260 r/PiratedGames
261 </a>
262 .
263 </li>
264 </ol>
265 </details>
266 <details>
267 <summary>
268 <span class="i-lucide-shield-alert bg-cerise-400 mb-1 ml-1" />
269 Things we will try to avoid
270 </summary>
271 <ol>
272 <li>Closed source software (with good FOSS alternatives)</li>
273 <li>
274 Sites that only use hosters such Katfile, Nitroflare,
275 DDownload and Rapidgator
276 </li>
277 <li>
278 Sites that aren't primarily for anime but have it as a side
279 product
280 </li>
281 <li>Things that are too niche and/or have a small userbase</li>
282 </ol>
283 </details>
284 </div>
285 <textarea
286 v-model="feedback.message"
287 autofocus
288 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"
289 placeholder="Tip: Did you know that starring our GitHub repo doubles the chances that your feedback will be read?"
290 />
291 <p class="desc mb-2">
292 If you want a reply to your feedback, feel free to mention a contact
293 in the message or join our
294 <a
295 class="text-primary text-underline font-semibold"
296 href="https://discord.gg/wZMuSGpZ8s"
297 >
298 Discord.
299 </a>
300 </p>
301 <div class="flex flex-row gap-2">
302 <button
303 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"
304 @click="feedback.type = undefined"
305 >
306 <span class="i-lucide:panel-left-close">close</span>
307 </button>
308 <button
309 type="submit"
310 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"
311 :disabled="isDisabled"
312 @click="handleSubmit()"
313 >
314 Send Feedback 📩
315 </button>
316 </div>
317 </div>
318 <div v-else>
319 <p class="heading">Thanks for your feedback!</p>
320 </div>
321 </Transition>
322 </div>
323 </Transition>
324</template>
325
326<style scoped lang="css">
327.btn {
328 border: 1px solid var(--vp-c-divider);
329 background-color: var(--vp-c-bg);
330 border-radius: 8px;
331 transition: border-color 0.25s, background-color 0.25s;
332 display: inline-block;
333 font-size: 14px;
334 font-weight: 500;
335 line-height: 1.5;
336 margin: 0;
337 padding: 0.375rem 0.75rem;
338 text-align: center;
339 vertical-align: middle;
340 white-space: nowrap;
341}
342
343.btn:disabled {
344 opacity: 0.5;
345}
346
347.btn:hover {
348 border-color: var(--vp-c-brand);
349}
350
351.btn-primary {
352 color: #fff;
353 background-color: var(--vp-c-brand);
354 border-color: var(--vp-c-brand);
355}
356
357.btn-primary:hover {
358 background-color: var(--vp-c-brand-darker);
359 border-color: var(--vp-c-brand-darker);
360}
361
362.heading {
363 font-size: 1.2rem;
364 font-weight: 700;
365}
366
367.desc {
368 display: block;
369 line-height: 20px;
370 font-size: 12px;
371 font-weight: 500;
372 color: var(--vp-c-text-2);
373}
374
375.fade-enter-active,
376.fade-leave-active {
377 transition: opacity 0.25s ease;
378}
379
380.fade-enter-from,
381.fade-leave-to {
382 opacity: 0;
383}
384</style>