2021-09-17 22:39:15 +09:00
|
|
|
<template>
|
2023-05-19 16:20:53 +09:00
|
|
|
<div class="_gaps">
|
2023-01-16 05:35:01 +09:00
|
|
|
<MkButton v-if="$i && ($i.isModerator || $i.policies.canManageCustomEmojis)" primary link to="/custom-emojis-manager">{{ i18n.ts.manageCustomEmojis }}</MkButton>
|
|
|
|
|
2021-09-17 22:39:15 +09:00
|
|
|
<div class="query">
|
2023-04-01 14:01:57 +09:00
|
|
|
<MkInput v-model="q" class="" :placeholder="i18n.ts.search">
|
2022-12-19 19:01:30 +09:00
|
|
|
<template #prefix><i class="ti ti-search"></i></template>
|
2021-09-17 22:39:15 +09:00
|
|
|
</MkInput>
|
|
|
|
|
2021-09-26 03:17:16 +09:00
|
|
|
<!-- たくさんあると邪魔
|
2021-09-17 22:39:15 +09:00
|
|
|
<div class="tags">
|
2023-01-09 15:50:25 +09:00
|
|
|
<span class="tag _button" v-for="tag in customEmojiTags" :class="{ active: selectedTags.has(tag) }" @click="toggleTag(tag)">{{ tag }}</span>
|
2021-09-17 22:39:15 +09:00
|
|
|
</div>
|
2021-09-26 03:16:30 +09:00
|
|
|
-->
|
2021-09-17 22:39:15 +09:00
|
|
|
</div>
|
|
|
|
|
2023-05-19 16:20:53 +09:00
|
|
|
<MkFoldableSection v-if="searchEmojis">
|
2023-04-01 14:01:57 +09:00
|
|
|
<template #header>{{ i18n.ts.searchResult }}</template>
|
2023-05-19 16:20:53 +09:00
|
|
|
<div :class="$style.emojis">
|
|
|
|
<XEmoji v-for="emoji in searchEmojis" :key="emoji.name" :emoji="emoji"/>
|
2021-09-17 22:39:15 +09:00
|
|
|
</div>
|
2023-01-09 09:41:25 +09:00
|
|
|
</MkFoldableSection>
|
2021-09-17 22:39:15 +09:00
|
|
|
|
2023-05-19 16:20:53 +09:00
|
|
|
<MkFoldableSection v-for="category in customEmojiCategories" v-once :key="category">
|
2023-04-01 14:01:57 +09:00
|
|
|
<template #header>{{ category || i18n.ts.other }}</template>
|
2023-05-19 16:20:53 +09:00
|
|
|
<div :class="$style.emojis">
|
|
|
|
<XEmoji v-for="emoji in customEmojis.filter(e => e.category === category)" :key="emoji.name" :emoji="emoji"/>
|
2021-09-17 22:39:15 +09:00
|
|
|
</div>
|
2023-01-09 09:41:25 +09:00
|
|
|
</MkFoldableSection>
|
2021-09-17 22:39:15 +09:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2023-01-09 15:50:25 +09:00
|
|
|
<script lang="ts" setup>
|
2023-02-16 23:09:41 +09:00
|
|
|
import { watch } from 'vue';
|
2023-04-01 13:52:07 +09:00
|
|
|
import * as Misskey from 'misskey-js';
|
2022-09-06 18:21:49 +09:00
|
|
|
import XEmoji from './emojis.emoji.vue';
|
|
|
|
import MkButton from '@/components/MkButton.vue';
|
2023-01-07 15:09:46 +09:00
|
|
|
import MkInput from '@/components/MkInput.vue';
|
2023-01-09 09:41:25 +09:00
|
|
|
import MkFoldableSection from '@/components/MkFoldableSection.vue';
|
2023-01-16 19:36:29 +09:00
|
|
|
import { customEmojis, customEmojiCategories, getCustomEmojiTags } from '@/custom-emojis';
|
2023-01-16 05:35:01 +09:00
|
|
|
import { i18n } from '@/i18n';
|
2023-04-01 13:52:07 +09:00
|
|
|
import { $i } from '@/account';
|
2021-09-17 22:39:15 +09:00
|
|
|
|
2023-01-09 16:45:05 +09:00
|
|
|
const customEmojiTags = getCustomEmojiTags();
|
2023-01-09 15:50:25 +09:00
|
|
|
let q = $ref('');
|
2023-01-16 18:39:58 +09:00
|
|
|
let searchEmojis = $ref<Misskey.entities.CustomEmoji[]>(null);
|
2023-01-09 15:50:25 +09:00
|
|
|
let selectedTags = $ref(new Set());
|
2021-09-17 22:39:15 +09:00
|
|
|
|
2023-01-09 15:50:25 +09:00
|
|
|
function search() {
|
|
|
|
if ((q === '' || q == null) && selectedTags.size === 0) {
|
|
|
|
searchEmojis = null;
|
|
|
|
return;
|
|
|
|
}
|
2021-09-17 22:39:15 +09:00
|
|
|
|
2023-01-09 15:50:25 +09:00
|
|
|
if (selectedTags.size === 0) {
|
2023-04-14 14:49:41 +09:00
|
|
|
const queryarry = q.match(/\:([a-z0-9_]*)\:/g);
|
|
|
|
|
|
|
|
if (queryarry) {
|
|
|
|
searchEmojis = customEmojis.value.filter(emoji =>
|
2023-05-19 16:20:53 +09:00
|
|
|
queryarry.includes(`:${emoji.name}:`),
|
2023-04-14 14:49:41 +09:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
searchEmojis = customEmojis.value.filter(emoji => emoji.name.includes(q) || emoji.aliases.includes(q));
|
|
|
|
}
|
2023-01-09 15:50:25 +09:00
|
|
|
} else {
|
2023-01-16 18:39:58 +09:00
|
|
|
searchEmojis = customEmojis.value.filter(emoji => (emoji.name.includes(q) || emoji.aliases.includes(q)) && [...selectedTags].every(t => emoji.aliases.includes(t)));
|
2023-01-09 15:50:25 +09:00
|
|
|
}
|
|
|
|
}
|
2021-09-17 22:39:15 +09:00
|
|
|
|
2023-01-09 15:50:25 +09:00
|
|
|
function toggleTag(tag) {
|
|
|
|
if (selectedTags.has(tag)) {
|
|
|
|
selectedTags.delete(tag);
|
|
|
|
} else {
|
|
|
|
selectedTags.add(tag);
|
|
|
|
}
|
|
|
|
}
|
2021-09-17 22:39:15 +09:00
|
|
|
|
2023-01-09 15:50:25 +09:00
|
|
|
watch($$(q), () => {
|
|
|
|
search();
|
2021-09-17 22:39:15 +09:00
|
|
|
});
|
2023-01-09 15:50:25 +09:00
|
|
|
|
|
|
|
watch($$(selectedTags), () => {
|
|
|
|
search();
|
|
|
|
}, { deep: true });
|
2021-09-17 22:39:15 +09:00
|
|
|
</script>
|
|
|
|
|
2023-05-19 16:20:53 +09:00
|
|
|
<style lang="scss" module>
|
|
|
|
.emojis {
|
|
|
|
display: grid;
|
|
|
|
grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
|
|
|
|
grid-gap: 12px;
|
2021-09-17 22:39:15 +09:00
|
|
|
}
|
|
|
|
</style>
|