docs/.vitepress/theme/components/Feedback.vue

eb2baf7005c932d7dbd97f8d4c8d4057ac6eedef
wotaku/docs/.vitepress/theme/components/Feedback.vue history · blame · raw

363 lines · 11601 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 loading = ref<boolean>(false)
 65const error = ref<unknown>(null)
 66const success = ref<boolean>(false)
 67
 68const isDisabled = computed(() => {
 69  return (
 70    !feedback.message.length ||
 71    feedback.message.length < 5 ||
 72    feedback.message.length > 1000
 73  )
 74})
 75
 76const router = useRouter()
 77// prettier-ignore
 78const feedback = reactive<
 79  Pick<FeedbackType, 'message' | 'page'> & Partial<Pick<FeedbackType, 'type'>>
 80>({
 81  page: getURL(props.heading!),
 82  message: ''
 83})
 84
 85const selectedOption = ref(feedbackOptions[0])
 86
 87async function handleSubmit(type?: FeedbackType['type']) {
 88  if (type) {
 89    feedback.type = type
 90    selectedOption.value = getFeedbackOption(type)!
 91  }
 92  loading.value = true
 93
 94  const body: FeedbackType = {
 95    message: feedback.message,
 96    type: feedback.type!,
 97    page: feedback.page,
 98    ...(props.heading && { heading: props.heading })
 99  }
100
101  try {
102    const response = await fetch('https://wotaku.tasky.workers.dev', {
103      method: 'POST',
104      headers: {
105        'Content-Type': 'application/json'
106      },
107      body: JSON.stringify(body)
108    })
109
110    const data = await response.json()
111    if (data.error) {
112      error.value = data.error
113      return
114    }
115    if (data.status === 'ok') {
116      success.value = true
117    }
118  } catch (err) {
119    error.value = err
120  } finally {
121    loading.value = false
122  }
123}
124
125const isCardShown = ref<boolean>(false)
126const helpfulText = props.heading
127  ? 'What do you think about this section?'
128  : 'What do you think about this page?'
129const helpfulDescription = props.heading
130  ? 'Let us know how helpful this section is.'
131  : 'Let us know how helpful this page is.'
132
133const prompt = computed(() => getPrompt())
134const toggleCard = () => (isCardShown.value = !isCardShown.value)
135</script>
136
137<template>
138  <template v-if="props.heading">
139    <button
140      @click="toggleCard()"
141      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"
142    >
143      <span
144        :class="isCardShown === false ? `i-lucide:mail` : `i-lucide:mail-x`"
145      />
146    </button>
147  </template>
148  <template v-else>
149    <button
150      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"
151      @click="toggleCard()"
152    >
153      <span
154        :class="
155          isCardShown === false ? `i-lucide:mail mr-2` : `i-lucide:mail-x mr-2`
156        "
157      />
158      <span>Send Feedback</span>
159    </button>
160  </template>
161
162  <Transition name="fade" mode="out-in">
163    <div
164      v-if="isCardShown"
165      class="border-$vp-c-divider bg-$vp-c-bg-alt b-rd-4 m-[2rem 0] mt-4 border-2 border-solid p-6"
166    >
167      <Transition name="fade" mode="out-in">
168        <div v-if="!feedback.type">
169          <p class="heading">
170            {{ helpfulText }}
171          </p>
172          <div class="flex flex-wrap gap-2">
173            <button
174              v-for="item in feedbackOptions"
175              :key="item.value"
176              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"
177              @click="handleSubmit(item.value)"
178            >
179              <span>{{ item.label }}</span>
180            </button>
181          </div>
182        </div>
183        <div v-else-if="feedback.type && !success">
184          <div class="mb-2">
185            <p class="desc">{{ helpfulDescription }} - {{ prompt }}</p>
186            <span>{{ getFeedbackOption(feedback.type)?.label }}</span>
187          </div>
188
189          <div v-if="feedback.type === 'suggestion'" class="mb-2 text-sm">
190            <details>
191              <summary>
192                <span class="i-lucide-shield-x bg-cerise-400 mb-1 ml-1" />
193                Things we won't add in the wiki
194              </summary>
195              <ol>
196                <li>
197                  Websites that are only or primarily for generative AI
198                  (Chatbot, roleplaying bot, ai art generator etc.)
199                </li>
200                <li>
201                  Sites that
202                  <ul>
203                    <li>imitate other websites</li>
204                    <li>have very small libraries</li>
205                    <li>only feature MTL'd works</li>
206                    <li>are mostly paywalled</li>
207                    <li>sell unofficial merch</li>
208                    <li>exlusively sell sex toys</li>
209                  </ul>
210                </li>
211                <li>Adult content sites similar to OnlyFans</li>
212                <li>
213                  Software that's too general (for example Windows OS related or
214                  Tweaking for privacy)
215                </li>
216                <li>Sites focused on lolicon or furry stuff</li>
217                <li>
218                  Sites scraping only one or two common sources, such as HiAnime
219                  or Animepahe
220                </li>
221                <li>
222                  Sites found in the Unsafe lists of
223                  <a
224                    href="https://fmhy.net/unsafesites"
225                    class="text-primary text-underline font-semibold"
226                  >
227                    FMHY
228                  </a>
229                  ,
230                  <a
231                    href="https://megathread.pages.dev/unsafe"
232                    class="text-primary text-underline font-semibold"
233                  >
234                    Privateersclub
235                  </a>
236                  and/or
237                  <a
238                    href="https://rentry.org/pgames#untrusted-sites"
239                    class="text-primary text-underline font-semibold"
240                  >
241                    r/PiratedGames
242                  </a>
243                  .
244                </li>
245              </ol>
246            </details>
247            <details>
248              <summary>
249                <span class="i-lucide-shield-alert bg-cerise-400 mb-1 ml-1" />
250                Things we will try to avoid
251              </summary>
252              <ol>
253                <li>Closed source software (with good FOSS alternatives)</li>
254                <li>
255                  Sites that only use hosters such Katfile, Nitroflare,
256                  DDownload and Rapidgator
257                </li>
258                <li>
259                  Sites that aren't primarily for anime but have it as a side
260                  product
261                </li>
262                <li>Things that are too niche and/or have a small userbase</li>
263              </ol>
264            </details>
265          </div>
266          <textarea
267            v-model="feedback.message"
268            autofocus
269            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"
270            placeholder="Tip: Did you know that starring our GitHub repo doubles the chances that your feedback will be read?"
271          />
272          <p class="desc mb-2">
273            If you want a reply to your feedback, feel free to mention a contact
274            in the message or join our
275            <a
276              class="text-primary text-underline font-semibold"
277              href="https://discord.gg/wZMuSGpZ8s"
278            >
279              Discord.
280            </a>
281          </p>
282          <div class="flex flex-row gap-2">
283            <button
284              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"
285              @click="feedback.type = undefined"
286            >
287              <span class="i-lucide:panel-left-close">close</span>
288            </button>
289            <button
290              type="submit"
291              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"
292              :disabled="isDisabled"
293              @click="handleSubmit()"
294            >
295              Send Feedback 📩
296            </button>
297          </div>
298        </div>
299        <div v-else>
300          <p class="heading">Thanks for your feedback!</p>
301        </div>
302      </Transition>
303    </div>
304  </Transition>
305</template>
306
307<style scoped lang="css">
308.btn {
309  border: 1px solid var(--vp-c-divider);
310  background-color: var(--vp-c-bg);
311  border-radius: 8px;
312  transition: border-color 0.25s, background-color 0.25s;
313  display: inline-block;
314  font-size: 14px;
315  font-weight: 500;
316  line-height: 1.5;
317  margin: 0;
318  padding: 0.375rem 0.75rem;
319  text-align: center;
320  vertical-align: middle;
321  white-space: nowrap;
322}
323
324.btn:disabled {
325  opacity: 0.5;
326}
327
328.btn:hover {
329  border-color: var(--vp-c-brand);
330}
331
332.btn-primary {
333  color: #fff;
334  background-color: var(--vp-c-brand);
335  border-color: var(--vp-c-brand);
336}
337
338.btn-primary:hover {
339  background-color: var(--vp-c-brand-darker);
340  border-color: var(--vp-c-brand-darker);
341}
342
343.heading {
344  font-size: 1.2rem;
345  font-weight: 700;
346}
347
348.desc {
349  display: block;
350  font-size: 12px;
351  color: var(--vp-c-text-2);
352}
353
354.fade-enter-active,
355.fade-leave-active {
356  transition: opacity 0.25s ease;
357}
358
359.fade-enter-from,
360.fade-leave-to {
361  opacity: 0;
362}
363</style>