mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-04-24 19:39:11 +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
|
@ -3,9 +3,18 @@ import { fontCSS } from '@roleypoly/design-system/atoms/fonts';
|
||||||
import { text300, text400 } from '@roleypoly/design-system/atoms/typography';
|
import { text300, text400 } from '@roleypoly/design-system/atoms/typography';
|
||||||
import styled, { css } from 'styled-components';
|
import styled, { css } from 'styled-components';
|
||||||
|
|
||||||
export const IconContainer = styled.div`
|
export const IconContainer = styled.div<{ small?: boolean }>`
|
||||||
margin-right: 0.6rem;
|
margin-right: 0.6rem;
|
||||||
font-size: 1.75em;
|
font-size: 1.75em;
|
||||||
|
|
||||||
|
${(props) =>
|
||||||
|
props.small &&
|
||||||
|
css`
|
||||||
|
margin-right: 0.2rem;
|
||||||
|
font-size: 1.25em;
|
||||||
|
position: relative;
|
||||||
|
top: 2px;
|
||||||
|
`}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const base = css`
|
const base = css`
|
||||||
|
|
|
@ -31,7 +31,9 @@ export const Button = (props: ButtonProps) => {
|
||||||
onClick={props.onClick}
|
onClick={props.onClick}
|
||||||
disabled={props.disabled}
|
disabled={props.disabled}
|
||||||
>
|
>
|
||||||
{props.icon && <IconContainer>{props.icon}</IconContainer>}
|
{props.icon && (
|
||||||
|
<IconContainer small={props.size === 'small'}>{props.icon}</IconContainer>
|
||||||
|
)}
|
||||||
<div>{props.children}</div>
|
<div>{props.children}</div>
|
||||||
</StyledButton>
|
</StyledButton>
|
||||||
);
|
);
|
||||||
|
|
|
@ -29,12 +29,18 @@ export const Box = styled.div`
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export const Section = styled.div<{ big?: boolean }>`
|
export const Section = styled.div<{ big?: boolean; actions?: boolean }>`
|
||||||
padding: 7px 5px;
|
padding: 7px 5px;
|
||||||
flex: 1 2 ${(props) => (props.big ? '100%' : '50%')};
|
flex: 1 2 ${(props) => (props.big ? '100%' : '50%')};
|
||||||
${onSmallScreen(css`
|
${onSmallScreen(css`
|
||||||
flex-basis: 100%;
|
flex-basis: 100%;
|
||||||
`)}
|
`)}
|
||||||
|
|
||||||
|
${(props) =>
|
||||||
|
props.actions &&
|
||||||
|
css`
|
||||||
|
display: flex;
|
||||||
|
`};
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export const RoleContainer = styled.div`
|
export const RoleContainer = styled.div`
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { Button } from '@roleypoly/design-system/atoms/button';
|
||||||
import { Popover } from '@roleypoly/design-system/atoms/popover';
|
import { Popover } from '@roleypoly/design-system/atoms/popover';
|
||||||
import { Role } from '@roleypoly/design-system/atoms/role';
|
import { Role } from '@roleypoly/design-system/atoms/role';
|
||||||
import { TextInput } from '@roleypoly/design-system/atoms/text-input';
|
import { TextInput } from '@roleypoly/design-system/atoms/text-input';
|
||||||
|
@ -7,7 +8,7 @@ import { RoleSearch } from '@roleypoly/design-system/molecules/role-search';
|
||||||
import { Category as CategoryT, CategoryType, Role as RoleT } from '@roleypoly/types';
|
import { Category as CategoryT, CategoryType, Role as RoleT } from '@roleypoly/types';
|
||||||
import { sortBy, uniq } from 'lodash';
|
import { sortBy, uniq } from 'lodash';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { GoPlus } from 'react-icons/go';
|
import { GoHistory, GoPlus, GoTrashcan } from 'react-icons/go';
|
||||||
import ReactTooltip from 'react-tooltip';
|
import ReactTooltip from 'react-tooltip';
|
||||||
import { AddRoleButton, Box, RoleContainer, Section } from './EditorCategory.styled';
|
import { AddRoleButton, Box, RoleContainer, Section } from './EditorCategory.styled';
|
||||||
|
|
||||||
|
@ -17,6 +18,8 @@ export type CategoryProps = {
|
||||||
category: CategoryT;
|
category: CategoryT;
|
||||||
unselectedRoles: RoleT[];
|
unselectedRoles: RoleT[];
|
||||||
onChange: (updatedCategory: CategoryT) => void;
|
onChange: (updatedCategory: CategoryT) => void;
|
||||||
|
onReset: () => void;
|
||||||
|
onDelete: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const EditorCategory = (props: CategoryProps) => {
|
export const EditorCategory = (props: CategoryProps) => {
|
||||||
|
@ -43,6 +46,16 @@ export const EditorCategory = (props: CategoryProps) => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box>
|
<Box>
|
||||||
|
<Section big actions>
|
||||||
|
<Button size="small" color="muted" icon={<GoHistory />} onClick={props.onReset}>
|
||||||
|
Reset to Default
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button size="small" color="muted" icon={<GoTrashcan />} onClick={props.onDelete}>
|
||||||
|
Delete Category
|
||||||
|
</Button>
|
||||||
|
</Section>
|
||||||
|
|
||||||
<Section>
|
<Section>
|
||||||
<div>
|
<div>
|
||||||
<Text>Category Name</Text>
|
<Text>Category Name</Text>
|
||||||
|
|
|
@ -34,6 +34,13 @@ const resetOrder = (categories: Category[]) =>
|
||||||
const forceOrder = (categories: Category[]) =>
|
const forceOrder = (categories: Category[]) =>
|
||||||
categories.map((c, index) => ({ ...c, position: index }));
|
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) => {
|
export const ServerCategoryEditor = (props: Props) => {
|
||||||
const [reorderMode, setReorderMode] = React.useState(false);
|
const [reorderMode, setReorderMode] = React.useState(false);
|
||||||
|
|
||||||
|
@ -62,12 +69,9 @@ export const ServerCategoryEditor = (props: Props) => {
|
||||||
const categories = resetOrder(props.guild.data.categories);
|
const categories = resetOrder(props.guild.data.categories);
|
||||||
|
|
||||||
const newCategory: Category = {
|
const newCategory: Category = {
|
||||||
|
...defaultCategory,
|
||||||
id: KSUID.randomSync().string,
|
id: KSUID.randomSync().string,
|
||||||
name: 'New Category',
|
|
||||||
type: CategoryType.Multi,
|
|
||||||
position: categories.length,
|
position: categories.length,
|
||||||
roles: [],
|
|
||||||
hidden: false,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
props.onChange([...categories, newCategory]);
|
props.onChange([...categories, newCategory]);
|
||||||
|
@ -82,6 +86,25 @@ export const ServerCategoryEditor = (props: Props) => {
|
||||||
props.onChange(resetOrder(categories));
|
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) {
|
if (reorderMode) {
|
||||||
return <ReorderMode {...props} exitReorderMode={onReorder} />;
|
return <ReorderMode {...props} exitReorderMode={onReorder} />;
|
||||||
}
|
}
|
||||||
|
@ -109,6 +132,8 @@ export const ServerCategoryEditor = (props: Props) => {
|
||||||
.filter((r) => r !== undefined) as Role[]
|
.filter((r) => r !== undefined) as Role[]
|
||||||
}
|
}
|
||||||
onChange={updateSingleCategory}
|
onChange={updateSingleCategory}
|
||||||
|
onDelete={onCategoryDelete(category)}
|
||||||
|
onReset={onCategoryReset(category)}
|
||||||
/>
|
/>
|
||||||
</CategoryContainer>
|
</CategoryContainer>
|
||||||
))
|
))
|
||||||
|
|
Loading…
Add table
Reference in a new issue