2024-06-16 10:33:05 +02:00
|
|
|
<template>
|
2024-06-21 05:51:06 +02:00
|
|
|
<AutocompleteSuggestbox :currently-typing="currentlyTypingMention" :textarea="textarea" :suggestions="mentions"
|
|
|
|
|
:distance-function="distance">
|
|
|
|
|
<template #default="{ suggestion }">
|
|
|
|
|
<Avatar :src="(suggestion.value as Account).avatar" class="w-full h-full rounded"
|
|
|
|
|
:alt="`User ${(suggestion.value as Account).acct}`" />
|
|
|
|
|
</template>
|
|
|
|
|
</AutocompleteSuggestbox>
|
2024-06-16 10:33:05 +02:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2024-06-20 01:57:38 +02:00
|
|
|
import type { Account } from "@lysand-org/client/types";
|
2024-06-16 10:33:05 +02:00
|
|
|
import { distance } from "fastest-levenshtein";
|
2024-06-21 05:51:06 +02:00
|
|
|
import Avatar from "../avatars/avatar.vue";
|
|
|
|
|
import AutocompleteSuggestbox from "./autocomplete-suggestbox.vue";
|
2024-06-16 10:33:05 +02:00
|
|
|
const props = defineProps<{
|
|
|
|
|
currentlyTypingMention: string | null;
|
|
|
|
|
textarea: HTMLTextAreaElement | undefined;
|
|
|
|
|
}>();
|
|
|
|
|
|
2024-06-21 05:51:06 +02:00
|
|
|
const mentions = ref<{ key: string; value: Account }[]>([]);
|
2024-06-16 10:33:05 +02:00
|
|
|
|
|
|
|
|
watch(
|
2024-06-21 05:51:06 +02:00
|
|
|
() => props.currentlyTypingMention,
|
|
|
|
|
async (value) => {
|
|
|
|
|
if (!value) {
|
|
|
|
|
return;
|
2024-06-16 10:33:05 +02:00
|
|
|
}
|
|
|
|
|
|
2024-06-21 05:51:06 +02:00
|
|
|
const users = await client.value.searchAccount(value, { limit: 20 });
|
|
|
|
|
mentions.value = users.data
|
|
|
|
|
.map((user) => ({
|
|
|
|
|
key: user.username,
|
|
|
|
|
value: user,
|
|
|
|
|
distance: distance(value, user.username),
|
|
|
|
|
}))
|
|
|
|
|
.sort((a, b) => a.distance - b.distance)
|
|
|
|
|
.slice(0, 20);
|
2024-06-16 10:33:05 +02:00
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
</script>
|