misskey/src/client/pages/instance/emojis.vue

291 lines
6.8 KiB
Vue
Raw Normal View History

<template>
<div class="mk-instance-emojis">
<portal to="icon"><fa :icon="faLaugh"/></portal>
2020-07-25 01:36:39 +09:00
<portal to="title" v-t="'customEmojis'"></portal>
2020-02-14 01:09:39 +09:00
2020-01-30 11:10:42 +09:00
<section class="_card local">
<div class="_title"><fa :icon="faLaugh"/> {{ $t('customEmojis') }}</div>
<div class="_content">
<mk-pagination :pagination="pagination" class="emojis" ref="emojis">
2020-07-25 01:36:39 +09:00
<template #empty><span v-t="'noCustomEmojis'"></span></template>
<template #default="{items}">
2020-02-06 14:23:01 +09:00
<div class="emoji" v-for="(emoji, i) in items" :key="emoji.id" @click="selected = emoji" :class="{ selected: selected && (selected.id === emoji.id) }">
<img :src="emoji.url" class="img" :alt="emoji.name"/>
<div class="body">
<span class="name">{{ emoji.name }}</span>
2020-02-14 01:09:39 +09:00
<span class="info">
<b class="category">{{ emoji.category }}</b>
<span class="aliases">{{ emoji.aliases.join(' ') }}</span>
</span>
</div>
</div>
</template>
</mk-pagination>
</div>
2020-02-14 01:09:39 +09:00
<div class="_content" v-if="selected">
2020-07-25 01:36:39 +09:00
<mk-input v-model="name"><span v-t="'name'"></span></mk-input>
<mk-input v-model="category" :datalist="categories"><span v-t="'category'"></span></mk-input>
<mk-input v-model="aliases"><span v-t="'tags'"></span></mk-input>
2020-02-14 01:09:39 +09:00
<mk-button inline primary @click="update"><fa :icon="faSave"/> {{ $t('save') }}</mk-button>
<mk-button inline :disabled="selected == null" @click="del()"><fa :icon="faTrashAlt"/> {{ $t('delete') }}</mk-button>
</div>
2020-02-14 01:09:39 +09:00
<div class="_footer">
<mk-button inline primary @click="add"><fa :icon="faPlus"/> {{ $t('addEmoji') }}</mk-button>
</div>
</section>
2020-01-30 11:10:42 +09:00
<section class="_card remote">
<div class="_title"><fa :icon="faLaugh"/> {{ $t('customEmojisOfRemote') }}</div>
<div class="_content">
2020-07-25 01:36:39 +09:00
<mk-input v-model="host" :debounce="true"><span v-t="'host'"></span></mk-input>
<mk-pagination :pagination="remotePagination" class="emojis" ref="remoteEmojis">
2020-07-25 01:36:39 +09:00
<template #empty><span v-t="'noCustomEmojis'"></span></template>
<template #default="{items}">
2020-02-06 14:23:01 +09:00
<div class="emoji" v-for="(emoji, i) in items" :key="emoji.id" @click="selectedRemote = emoji" :class="{ selected: selectedRemote && (selectedRemote.id === emoji.id) }">
<img :src="emoji.url" class="img" :alt="emoji.name"/>
<div class="body">
<span class="name">{{ emoji.name }}</span>
2020-02-14 01:09:39 +09:00
<span class="info">{{ emoji.host }}</span>
</div>
</div>
</template>
</mk-pagination>
</div>
<div class="_footer">
<mk-button inline primary :disabled="selectedRemote == null" @click="im()"><fa :icon="faPlus"/> {{ $t('import') }}</mk-button>
</div>
</section>
</div>
</template>
<script lang="ts">
import Vue from 'vue';
2020-02-14 01:09:39 +09:00
import { faPlus, faSave } from '@fortawesome/free-solid-svg-icons';
import { faTrashAlt, faLaugh } from '@fortawesome/free-regular-svg-icons';
import MkButton from '../../components/ui/button.vue';
import MkInput from '../../components/ui/input.vue';
import MkPagination from '../../components/ui/pagination.vue';
2020-02-14 01:09:39 +09:00
import { selectFile } from '../../scripts/select-file';
2020-02-15 02:39:27 +09:00
import { unique } from '../../../prelude/array';
export default Vue.extend({
metaInfo() {
return {
title: `${this.$t('customEmojis')} | ${this.$t('instance')}`
};
},
components: {
MkButton,
MkInput,
MkPagination,
},
data() {
return {
selected: null,
selectedRemote: null,
2020-02-14 01:09:39 +09:00
name: null,
category: null,
aliases: null,
host: '',
pagination: {
endpoint: 'admin/emoji/list',
limit: 10,
},
remotePagination: {
endpoint: 'admin/emoji/list-remote',
limit: 10,
params: () => ({
host: this.host ? this.host : null
})
},
2020-02-14 01:09:39 +09:00
faTrashAlt, faPlus, faLaugh, faSave
}
},
2020-02-15 02:39:27 +09:00
computed: {
categories() {
if (this.$store.state.instance.meta) {
return unique(this.$store.state.instance.meta.emojis.map((x: any) => x.category || '').filter((x: string) => x !== ''));
} else {
return [];
}
}
},
watch: {
host() {
this.$refs.remoteEmojis.reload();
2020-02-14 01:09:39 +09:00
},
selected() {
this.name = this.selected ? this.selected.name : null;
this.category = this.selected ? this.selected.category : null;
this.aliases = this.selected ? this.selected.aliases.join(' ') : null;
}
},
methods: {
2020-02-14 01:09:39 +09:00
async add(e) {
const files = await selectFile(this, e.currentTarget || e.target, null, true);
const dialog = this.$root.dialog({
type: 'waiting',
2020-02-14 01:09:39 +09:00
text: this.$t('doing') + '...',
showOkButton: false,
showCancelButton: false,
cancelableByBgClick: false
});
2020-02-14 01:09:39 +09:00
Promise.all(files.map(file => this.$root.api('admin/emoji/add', {
fileId: file.id,
})))
.then(() => {
this.$refs.emojis.reload();
this.$root.dialog({
type: 'success',
iconOnly: true, autoClose: true
});
})
.finally(() => {
dialog.close();
});
},
2020-02-14 01:09:39 +09:00
async update() {
await this.$root.api('admin/emoji/update', {
id: this.selected.id,
name: this.name,
category: this.category,
aliases: this.aliases.split(' '),
});
this.$root.dialog({
type: 'success',
iconOnly: true, autoClose: true
});
this.$refs.emojis.reload();
},
async del() {
const { canceled } = await this.$root.dialog({
type: 'warning',
text: this.$t('removeAreYouSure', { x: this.selected.name }),
showCancelButton: true
});
if (canceled) return;
this.$root.api('admin/emoji/remove', {
id: this.selected.id
}).then(() => {
this.$refs.emojis.reload();
});
},
im() {
this.$root.api('admin/emoji/copy', {
emojiId: this.selectedRemote.id,
}).then(() => {
this.$refs.emojis.reload();
this.$root.dialog({
type: 'success',
iconOnly: true, autoClose: true
});
}).catch(e => {
this.$root.dialog({
type: 'error',
text: e
});
});
},
}
});
</script>
<style lang="scss" scoped>
.mk-instance-emojis {
> .local {
> ._content {
max-height: 300px;
overflow: auto;
> .emojis {
> .emoji {
display: flex;
align-items: center;
&.selected {
background: var(--accent);
box-shadow: 0 0 0 8px var(--accent);
color: #fff;
}
> .img {
width: 50px;
height: 50px;
}
> .body {
padding: 8px;
> .name {
display: block;
}
2020-02-14 01:09:39 +09:00
> .info {
opacity: 0.5;
> .category {
margin-right: 16px;
}
> .aliases {
font-style: oblique;
}
}
}
}
}
}
}
> .remote {
> ._content {
max-height: 300px;
overflow: auto;
> .emojis {
> .emoji {
display: flex;
align-items: center;
&.selected {
background: var(--accent);
box-shadow: 0 0 0 8px var(--accent);
color: #fff;
}
> .img {
width: 32px;
height: 32px;
}
> .body {
padding: 0 8px;
> .name {
display: block;
}
2020-02-14 01:09:39 +09:00
> .info {
opacity: 0.5;
}
}
}
}
}
}
}
</style>