mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-06-15 17:19:10 +00:00
fix(Editor): add reset/delete actions to each category (fixes #302)
This commit is contained in:
parent
5dce2fc949
commit
5671a408c1
5 changed files with 63 additions and 8 deletions
|
@ -34,6 +34,13 @@ const resetOrder = (categories: Category[]) =>
|
|||
const forceOrder = (categories: Category[]) =>
|
||||
categories.map((c, index) => ({ ...c, position: index }));
|
||||
|
||||
const defaultCategory: Omit<Omit<Category, 'id'>, 'position'> = {
|
||||
name: 'New Category',
|
||||
type: CategoryType.Multi,
|
||||
roles: [],
|
||||
hidden: false,
|
||||
};
|
||||
|
||||
export const ServerCategoryEditor = (props: Props) => {
|
||||
const [reorderMode, setReorderMode] = React.useState(false);
|
||||
|
||||
|
@ -62,12 +69,9 @@ export const ServerCategoryEditor = (props: Props) => {
|
|||
const categories = resetOrder(props.guild.data.categories);
|
||||
|
||||
const newCategory: Category = {
|
||||
...defaultCategory,
|
||||
id: KSUID.randomSync().string,
|
||||
name: 'New Category',
|
||||
type: CategoryType.Multi,
|
||||
position: categories.length,
|
||||
roles: [],
|
||||
hidden: false,
|
||||
};
|
||||
|
||||
props.onChange([...categories, newCategory]);
|
||||
|
@ -82,6 +86,25 @@ export const ServerCategoryEditor = (props: Props) => {
|
|||
props.onChange(resetOrder(categories));
|
||||
};
|
||||
|
||||
const onCategoryDelete = (category: Category) => () => {
|
||||
const newCategories = props.guild.data.categories.filter((c) => c.id !== category.id);
|
||||
props.onChange(resetOrder(newCategories));
|
||||
};
|
||||
|
||||
const onCategoryReset = (category: Category) => () => {
|
||||
const newCategories = props.guild.data.categories.map((c) => {
|
||||
if (c.id === category.id) {
|
||||
return {
|
||||
...defaultCategory,
|
||||
id: KSUID.randomSync().string,
|
||||
position: category.position,
|
||||
};
|
||||
}
|
||||
return c;
|
||||
});
|
||||
props.onChange(resetOrder(newCategories));
|
||||
};
|
||||
|
||||
if (reorderMode) {
|
||||
return <ReorderMode {...props} exitReorderMode={onReorder} />;
|
||||
}
|
||||
|
@ -109,6 +132,8 @@ export const ServerCategoryEditor = (props: Props) => {
|
|||
.filter((r) => r !== undefined) as Role[]
|
||||
}
|
||||
onChange={updateSingleCategory}
|
||||
onDelete={onCategoryDelete(category)}
|
||||
onReset={onCategoryReset(category)}
|
||||
/>
|
||||
</CategoryContainer>
|
||||
))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue