diff options
| author | Hazelnoot <acomputerdog@gmail.com> | 2025-05-12 10:33:25 +0000 |
|---|---|---|
| committer | Hazelnoot <acomputerdog@gmail.com> | 2025-05-12 10:33:25 +0000 |
| commit | 835e76152e982bc6f8bfc09d7afa1aba4d872367 (patch) | |
| tree | 37632f56ebf45c7841a9960266fdaebfd5e00417 /packages/frontend/src/components/SkPatternTest.vue | |
| parent | merge: Fix hidden hashtags showing on the explore / trending page (!1014) (diff) | |
| parent | rename SkWordMuteTest to SkPatternTest (diff) | |
| download | sharkey-835e76152e982bc6f8bfc09d7afa1aba4d872367.tar.gz sharkey-835e76152e982bc6f8bfc09d7afa1aba4d872367.tar.bz2 sharkey-835e76152e982bc6f8bfc09d7afa1aba4d872367.zip | |
merge: Add pattern checker for word mutes (resolves #1003) (!1020)
View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/1020
Closes #1003
Approved-by: dakkar <dakkar@thenautilus.net>
Approved-by: Marie <github@yuugi.dev>
Diffstat (limited to 'packages/frontend/src/components/SkPatternTest.vue')
| -rw-r--r-- | packages/frontend/src/components/SkPatternTest.vue | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/packages/frontend/src/components/SkPatternTest.vue b/packages/frontend/src/components/SkPatternTest.vue new file mode 100644 index 0000000000..2ed2b3fdc3 --- /dev/null +++ b/packages/frontend/src/components/SkPatternTest.vue @@ -0,0 +1,57 @@ +<!-- +SPDX-FileCopyrightText: hazelnoot and other Sharkey contributors +SPDX-License-Identifier: AGPL-3.0-only +--> + +<template> +<MkFolder> + <template #label>{{ i18n.ts.wordMuteTestLabel }}</template> + + <div class="_gaps"> + <MkTextarea v-model="testWords"> + <template #caption>{{ i18n.ts.wordMuteTestDescription }}</template> + </MkTextarea> + <div><MkButton :disabled="!testWords" @click="testWordMutes">{{ i18n.ts.wordMuteTestTest }}</MkButton></div> + <div v-if="testMatches == null">{{ i18n.ts.wordMuteTestNoResults}}</div> + <div v-else-if="testMatches === ''">{{ i18n.ts.wordMuteTestNoMatch }}</div> + <div v-else>{{ i18n.tsx.wordMuteTestMatch({ words: testMatches }) }}</div> + </div> +</MkFolder> +</template> + +<script setup lang="ts"> +import { ref } from 'vue'; +import { i18n } from '@/i18n'; +import MkFolder from '@/components/MkFolder.vue'; +import MkButton from '@/components/MkButton.vue'; +import MkTextarea from '@/components/MkTextarea.vue'; +import { parseMutes } from '@/utility/parse-mutes'; +import { checkWordMute } from '@/utility/check-word-mute'; + +const props = defineProps<{ + mutedWords?: string | null, +}>(); + +const testWords = ref<string | null>(null); +const testMatches = ref<string | null>(null); + +function testWordMutes() { + if (!testWords.value || !props.mutedWords) { + testMatches.value = null; + return; + } + + try { + const mutes = parseMutes(props.mutedWords); + const matches = checkWordMute(testWords.value, null, mutes); + testMatches.value = matches ? matches.flat(2).join(', ') : ''; + } catch { + // Error is displayed by above function + testMatches.value = null; + } +} +</script> + +<style module lang="scss"> + +</style> |