make emoji categories reactive
This commit is contained in:
parent
2b7583c8de
commit
1f45482cf2
1 changed files with 28 additions and 21 deletions
|
|
@ -150,6 +150,9 @@ const props = withDefaults(defineProps<{
|
|||
targetNote?: Misskey.entities.Note;
|
||||
}>(), {
|
||||
showPinned: true,
|
||||
pinnedEmojis: undefined,
|
||||
maxHeight: undefined,
|
||||
targetNote: undefined,
|
||||
});
|
||||
|
||||
const emit = defineEmits<{
|
||||
|
|
@ -184,37 +187,41 @@ const searchResultCustom = ref<Misskey.entities.EmojiSimple[]>([]);
|
|||
const searchResultUnicode = ref<UnicodeEmojiDef[]>([]);
|
||||
const tab = ref<'index' | 'custom' | 'unicode' | 'tags'>('index');
|
||||
|
||||
const customEmojiFolderRoot: CustomEmojiFolderTree = { value: '', category: '', children: [] };
|
||||
const customEmojiFolderRoot = computed<CustomEmojiFolderTree>(() => {
|
||||
const root = { value: '', category: '', children: [] };
|
||||
|
||||
function parseAndMergeCategories(input: string, root: CustomEmojiFolderTree): CustomEmojiFolderTree {
|
||||
const parts = input.split('/').map(p => p.trim());
|
||||
let currentNode: CustomEmojiFolderTree = root;
|
||||
function parseAndMergeCategories(category: string): CustomEmojiFolderTree {
|
||||
const parts = category.split('/').map(p => p.trim());
|
||||
let currentNode: CustomEmojiFolderTree = root;
|
||||
|
||||
const currentPath = [] as string[];
|
||||
for (const part of parts) {
|
||||
currentPath.push(part);
|
||||
let existingNode = currentNode.children.find((node) => node.value === part);
|
||||
const currentPath = [] as string[];
|
||||
for (const part of parts) {
|
||||
currentPath.push(part);
|
||||
let existingNode = currentNode.children.find((node) => node.value === part);
|
||||
|
||||
if (!existingNode) {
|
||||
const newNode: CustomEmojiFolderTree = { value: part, category: currentPath.join("/"), children: [] };
|
||||
currentNode.children.push(newNode);
|
||||
existingNode = newNode;
|
||||
if (!existingNode) {
|
||||
const newNode: CustomEmojiFolderTree = { value: part, category: currentPath.join("/"), children: [] };
|
||||
currentNode.children.push(newNode);
|
||||
existingNode = newNode;
|
||||
}
|
||||
|
||||
currentNode = existingNode;
|
||||
}
|
||||
|
||||
currentNode = existingNode;
|
||||
return currentNode;
|
||||
}
|
||||
|
||||
return currentNode;
|
||||
}
|
||||
customEmojiCategories.value.forEach(ec => {
|
||||
if (ec !== null) {
|
||||
parseAndMergeCategories(ec);
|
||||
}
|
||||
});
|
||||
|
||||
customEmojiCategories.value.forEach(ec => {
|
||||
if (ec !== null) {
|
||||
parseAndMergeCategories(ec, customEmojiFolderRoot);
|
||||
}
|
||||
parseAndMergeCategories('');
|
||||
|
||||
return root;
|
||||
});
|
||||
|
||||
parseAndMergeCategories('', customEmojiFolderRoot);
|
||||
|
||||
watch(q, () => {
|
||||
if (emojisEl.value) emojisEl.value.scrollTop = 0;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue