This commit is contained in:
tamaina 2023-01-16 10:13:19 +00:00
parent 4cd70df7f4
commit f2a9194c79
2 changed files with 20 additions and 2 deletions

View file

@ -6,6 +6,7 @@ import * as Misskey from 'misskey-js';
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) : []);
fetchCustomEmojis();
window.setInterval(fetchCustomEmojis, 1000 * 60 * 10); window.setInterval(fetchCustomEmojis, 1000 * 60 * 10);
export async function fetchCustomEmojis() { export async function fetchCustomEmojis() {

View file

@ -79,7 +79,7 @@ import { selectFile, selectFiles } from '@/scripts/select-file';
import * as os from '@/os'; import * as os from '@/os';
import { i18n } from '@/i18n'; import { i18n } from '@/i18n';
import { definePageMetadata } from '@/scripts/page-metadata'; import { definePageMetadata } from '@/scripts/page-metadata';
import { fetchCustomEmojis } from '@/custom-emojis'; import { fetchCustomEmojis, customEmojis } from '@/custom-emojis';
const emojisPaginationComponent = shallowRef<InstanceType<typeof MkPagination>>(); const emojisPaginationComponent = shallowRef<InstanceType<typeof MkPagination>>();
@ -146,10 +146,27 @@ const edit = (emoji) => {
...oldEmoji, ...oldEmoji,
...result.updated, ...result.updated,
})); }));
if (customEmojis.value.some(e => e.name === emoji.name)) {
customEmojis.value = [
{
name: result.updated.name,
aliases: result.updated.aliases,
category: result.updated.category,
},
...customEmojis.value,
];
} else {
customEmojis.value = customEmojis.value.map(e => e.name !== emoji.name ? e : {
name: result.updated.name,
aliases: result.updated.aliases,
category: result.updated.category,
});
}
} else if (result.deleted) { } else if (result.deleted) {
emojisPaginationComponent.value.removeItem((item) => item.id === emoji.id); emojisPaginationComponent.value.removeItem((item) => item.id === emoji.id);
customEmojis.value = customEmojis.value.filter(e => e.name !== emoji.name);
} }
fetchCustomEmojis();
}, },
}, 'closed'); }, 'closed');
}; };