monkeeShark/packages/frontend/src/pages/about.emojis.vue

99 lines
3 KiB
Vue
Raw Normal View History

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