[frontend] Custom Emoji Deletion (#994)

* re-add eslint

* fix oauth url getting too long

* actually attach single emoji get and delete routes

* basic emoji details + deletion using rtk query

* refactor emoji upload to rtk query

* clean up old redux api+reducers for custom emoji

* fix validation order

* refactor custom emoji form fields

* remove unused requires

* cleanup, fix most eslint errors

* more small eslint fixes

* fix max emoji size

* tiny bit of function documentation
This commit is contained in:
f0x52
2022-11-08 17:51:44 +01:00
committed by GitHub
parent be011b1641
commit eb25739c34
32 changed files with 1467 additions and 506 deletions

View File

@ -19,7 +19,6 @@
"use strict";
const { createSlice } = require("@reduxjs/toolkit");
const defaultValue = require("default-value");
function sortBlocks(blocks) {
return blocks.sort((a, b) => { // alphabetical sort
@ -35,13 +34,6 @@ function emptyBlock() {
};
}
function emptyEmojiForm() {
return {
id: Date.now(),
shortcode: ""
};
}
module.exports = createSlice({
name: "admin",
initialState: {
@ -52,10 +44,7 @@ module.exports = createSlice({
exportType: "plain",
...emptyBlock()
},
newInstanceBlocks: {},
emoji: {},
emojiById: {},
newEmoji: emptyEmojiForm()
newInstanceBlocks: {}
},
reducers: {
setBlockedInstances: (state, { payload }) => {
@ -105,34 +94,6 @@ module.exports = createSlice({
state.bulkBlock.list = Object.values(state.blockedInstances).map((entry) => {
return entry.domain;
}).join("\n");
},
setEmoji: (state, {payload}) => {
state.emoji = {};
payload.forEach((emoji) => {
if (emoji.category == undefined) {
emoji.category = "Unsorted";
}
state.emoji[emoji.category] = defaultValue(state.emoji[emoji.category], []);
state.emoji[emoji.category].push(emoji);
state.emojiById[emoji.id] = emoji;
});
},
updateNewEmojiVal: (state, { payload: [key, val] }) => {
state.newEmoji[key] = val;
},
addEmoji: (state, {payload: emoji}) => {
if (emoji.category == undefined) {
emoji.category = "Unsorted";
}
if (emoji.id == undefined) {
emoji.id = Date.now();
}
state.emoji[emoji.category] = defaultValue(state.emoji[emoji.category], []);
state.emoji[emoji.category].push(emoji);
state.emojiById[emoji.id] = emoji;
},
}
}
});