add short editor item and data model for categories

This commit is contained in:
41666 2021-07-04 19:57:12 -05:00
parent 17bceae60f
commit 0deca68ca8
9 changed files with 231 additions and 29 deletions

View file

@ -1,18 +1,39 @@
import { TabDepth } from '@roleypoly/design-system/atoms/tab-view/TabView.styled';
import { EditorCategory } from '@roleypoly/design-system/molecules/editor-category';
import { EditorCategoryShort } from '@roleypoly/design-system/molecules/editor-category-short/EditorCategoryShort';
import { EditorShellProps } from '@roleypoly/design-system/organisms/editor-shell';
import { Category } from '@roleypoly/types';
import { sortBy } from 'lodash';
import * as React from 'react';
import { CategoryContainer } from './EditorCategoriesTab.styled';
export const EditorCategoriesTab = (props: EditorShellProps) => (
<div>
{props.guild.data.categories.map((category, idx) => (
<CategoryContainer key={idx}>
<EditorCategory
category={category}
uncategorizedRoles={[]}
guildRoles={props.guild.roles}
onChange={(x) => console.log(x)}
/>
</CategoryContainer>
))}
</div>
);
export const EditorCategoriesTab = (props: EditorShellProps) => {
const [openStates, setOpenStates] = React.useState<Category['id'][]>([]);
const onCategoryOpen = (id: Category['id']) => () => {
setOpenStates([...new Set(openStates).add(id)]);
};
return (
<TabDepth>
{sortBy(props.guild.data.categories, ['position', 'id']).map((category, idx) =>
openStates.includes(category.id) ? (
<CategoryContainer key={idx}>
<EditorCategory
category={category}
uncategorizedRoles={[]}
guildRoles={props.guild.roles}
onChange={(category) => props.onCategoryChange?.(category)}
/>
</CategoryContainer>
) : (
<EditorCategoryShort
key={idx}
category={category}
onOpen={onCategoryOpen(category.id)}
/>
)
)}
</TabDepth>
);
};

View file

@ -1,16 +1,20 @@
import { Space } from '@roleypoly/design-system/atoms/space';
import { TabDepth } from '@roleypoly/design-system/atoms/tab-view/TabView.styled';
import { MultilineTextInput } from '@roleypoly/design-system/atoms/text-input';
import { Text } from '@roleypoly/design-system/atoms/typography';
import { EditorShellProps } from '@roleypoly/design-system/organisms/editor-shell';
import * as React from 'react';
export const EditorDetailsTab = (props: EditorShellProps) => {
const [serverMessage, updateServerMessage] = React.useState(props.guild.data.message);
return (
<div>
Server Message
<TabDepth>
<Space />
<Text>Server Message</Text>
<MultilineTextInput
value={serverMessage}
onChange={(eventData) => updateServerMessage(eventData.target.value)}
value={props.guild.data.message}
onChange={(eventData) => props.onMessageChange?.(eventData.target.value)}
/>
</div>
<Space />
</TabDepth>
);
};

View file

@ -1,16 +1,56 @@
import { Tab, TabView } from '@roleypoly/design-system/atoms/tab-view';
import { EditorCategoriesTab } from '@roleypoly/design-system/organisms/editor-categories-tab';
import { EditorDetailsTab } from '@roleypoly/design-system/organisms/editor-details-tab';
import { PresentableGuild } from '@roleypoly/types';
import { Category, PresentableGuild } from '@roleypoly/types';
import React from 'react';
export type EditorShellProps = {
guild: PresentableGuild;
onGuildChange?: (guild: PresentableGuild) => void;
onCategoryChange?: (category: Category) => void;
onMessageChange?: (message: PresentableGuild['data']['message']) => void;
};
export const EditorShell = (props: EditorShellProps) => (
<TabView initialTab={0}>
<Tab title="Guild Details">{() => <EditorDetailsTab {...props} />}</Tab>
<Tab title="Categories & Roles">{() => <EditorCategoriesTab {...props} />}</Tab>
<Tab title="Utilities">{() => <div>hi2!</div>}</Tab>
</TabView>
);
export const EditorShell = (props: EditorShellProps) => {
const [guild, setGuild] = React.useState<PresentableGuild>(props.guild);
const reset = () => {
setGuild(props.guild);
};
const onCategoryChange = (category: Category) => {
setGuild((currentGuild) => {
const categories = [
...currentGuild.data.categories.filter((x) => x.id !== category.id),
category,
];
return { ...currentGuild, data: { ...currentGuild.data, categories } };
});
};
const onMessageChange = (message: PresentableGuild['data']['message']) => {
setGuild((currentGuild) => {
return { ...currentGuild, data: { ...guild.data, message } };
});
};
return (
<TabView initialTab={0}>
<Tab title="Guild Details">
{() => (
<EditorDetailsTab {...props} guild={guild} onMessageChange={onMessageChange} />
)}
</Tab>
<Tab title="Categories & Roles">
{() => (
<EditorCategoriesTab
{...props}
guild={guild}
onCategoryChange={onCategoryChange}
/>
)}
</Tab>
<Tab title="Utilities">{() => <div>hi2!</div>}</Tab>
</TabView>
);
};