better category null handling

This commit is contained in:
tamaina 2023-01-22 17:33:20 +00:00
parent 0d44129ae3
commit 93dd0638ad
2 changed files with 15 additions and 5 deletions

View File

@ -60,7 +60,15 @@
</div> </div>
<div v-once class="group"> <div v-once class="group">
<header class="_acrylic">{{ i18n.ts.customEmojis }}</header> <header class="_acrylic">{{ i18n.ts.customEmojis }}</header>
<XSection v-for="category in customEmojiCategories" :key="'custom:' + category" :initial-shown="false" :emojis="computed(() => customEmojis.filter(e => e.category === category).map(e => ':' + e.name + ':'))" @chosen="chosen">{{ category || i18n.ts.other }}</XSection> <XSection
v-for="category in customEmojiCategories"
:key="`custom:${category}`"
:initial-shown="false"
:emojis="computed(() => customEmojis.filter(e => category === null ? e.category == null || e.category === 'null' : e.category === category).map(e => `:${e.name}:`))"
@chosen="chosen"
>
{{ category || i18n.ts.other }}
</XSection>
</div> </div>
<div v-once class="group"> <div v-once class="group">
<header class="_acrylic">{{ i18n.ts.emoji }}</header> <header class="_acrylic">{{ i18n.ts.emoji }}</header>

View File

@ -1,17 +1,19 @@
import { apiGet } from './os'; import { apiGet } from './os';
import { miLocalStorage } from './local-storage'; import { miLocalStorage } from './local-storage';
import { shallowRef, computed, markRaw, watch } from 'vue'; import { shallowRef, computed, markRaw } from 'vue';
import * as Misskey from 'misskey-js'; import * as Misskey from 'misskey-js';
import { stream } from '@/stream'; import { stream } from '@/stream';
const storageCache = miLocalStorage.getItem('emojis'); const storageCache = miLocalStorage.getItem('emojis');
export const customEmojis = shallowRef<Misskey.entities.CustomEmoji[]>(storageCache ? JSON.parse(storageCache) : []); export const customEmojis = shallowRef<Misskey.entities.CustomEmoji[]>(storageCache ? JSON.parse(storageCache) : []);
export const customEmojiCategories = computed<string[]>(() => { export const customEmojiCategories = computed<[ ...string[], null ]>(() => {
const categories = new Set<string>(); const categories = new Set<string>();
for (const emoji of customEmojis.value) { for (const emoji of customEmojis.value) {
if (emoji.category && emoji.category !== 'null') {
categories.add(emoji.category); categories.add(emoji.category);
} }
return markRaw(Array.from(categories)); }
return markRaw([ ...Array.from(categories), null ]);
}); });
stream.on('emojiAdded', emojiData => { stream.on('emojiAdded', emojiData => {