🐛 Automatic positions for wrappers and categories

This commit is contained in:
Manuel Ruwe
2023-01-10 22:36:26 +01:00
parent 393a6c2dc2
commit 79074f960f

View File

@@ -38,29 +38,27 @@ export const AvailableElementTypes = ({
category: {
id: uuidv4(),
name: 'New category',
position: 0,
position: 0, // doesn't matter, is being overwritten
},
onSuccess: async (category) => {
if (!configName) return;
await updateConfig(configName, (previousConfig) => ({
...previousConfig,
wrappers:
previousConfig.wrappers.length <= previousConfig.categories.length
? [
wrappers: [
...previousConfig.wrappers,
{
id: uuidv4(),
position: previousConfig.categories.length,
// Thank you ChatGPT ;)
position: previousConfig.categories.length + 1,
},
]
: previousConfig.wrappers,
],
categories: [
...previousConfig.categories,
{
id: uuidv4(),
name: category.name,
position: previousConfig.categories.length,
position: previousConfig.categories.length + 1,
},
],
})).then(() => {