Fix detection

This commit is contained in:
Lorenz Padberg 2024-05-16 00:19:53 +02:00
parent 8049428fb1
commit e23549c677
1 changed files with 21 additions and 17 deletions

View File

@ -3,11 +3,11 @@
<textarea
:placeholder="placeholder"
:readonly="readonly"
v-model="editText"
:class="{ 'submission-form__textarea--readonly': readonly }"
data-cy="submission-textarea"
rows="1"
class="borderless-textarea"
v-model="editText"
v-auto-grow
@input="input"
/>
@ -23,14 +23,12 @@
>
<loading-icon class="submission-form__save-status-icon submission-form__saving-icon" />
</div>
</div>
</template>
<script setup lang="ts">
import {defineAsyncComponent, ref, watch} from 'vue';
import EmojiBar from "@/components/ui/EmojiBar.vue";
import { defineAsyncComponent, ref, watch } from 'vue';
const TickCircleIcon = defineAsyncComponent(() => import('@/components/icons/TickCircleIcon.vue'));
const LoadingIcon = defineAsyncComponent(() => import('@/components/icons/LoadingIcon.vue'));
@ -45,24 +43,30 @@ const props = withDefaults(defineProps<Props>(), {
placeholder: 'Ergebnis erfassen',
});
const editText = ref(props.inputText)
const editText = ref(props.inputText);
const emit = defineEmits(['input']);
const containsEmoji = (text: String) =>{
const emojis= ['🖐️', '👍', '👎', '👏', '👋', '🎉', '😍', '😮', '🤔']
const graphemes = Array.from(text);
const lastGrapheme = graphemes[graphemes.length - 1];
return emojis.includes(lastGrapheme);
}
const containsEmoji = (text: string) => {
const lastCharacter = Array.from(text)[Array.from(text).length - 1];
if (lastCharacter.charCodeAt(0)> 55000) //fix for the hand symbol 🖐
return true
const emojiRegex = /\p{Emoji}/u;
return emojiRegex.test(lastCharacter);
};
watch(() => props.inputText, (newValue) => {
// TODO: Lorenz this is an ugly fix!
if (containsEmoji(newValue)){
watch(
() => props.inputText,
(newValue) => {
// TODO: Lorenz this is an ugly fix!
console.log(newValue)
if (containsEmoji(newValue)) {
console.log("emoji found", newValue)
editText.value = newValue;
}
}
});
);
const input = (e: Event) => {
const value = (e.target as HTMLInputElement).value;