mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-06-16 01:29:09 +00:00
Feat/editor category pass2 (#290)
* feat(design-system): add editor skeletons * use css media queries rather than JS media queries * init remake * feat: add basis of toggle atom * finish toggle * use pointer cursor with toggle * sync * feat: add server message in editor * cleanup storybook * add short editor item and data model for categories * chore: fix build by moving jest version downward * chore: remove old category editor * chore: fix EditorCategoryShort index * add editor wiring and styling updates * fix linting issues
This commit is contained in:
parent
a37d481b18
commit
7d681d69d6
48 changed files with 927 additions and 1100 deletions
|
@ -0,0 +1,12 @@
|
|||
import { BreakpointsProvider } from '@roleypoly/design-system/atoms/breakpoints';
|
||||
import { guildEnum } from '@roleypoly/design-system/fixtures/storyData';
|
||||
import * as React from 'react';
|
||||
import { EditorShell } from './EditorShell';
|
||||
|
||||
export default {
|
||||
title: 'Organisms/Editor',
|
||||
component: EditorShell,
|
||||
decorators: [(story) => <BreakpointsProvider>{story()}</BreakpointsProvider>],
|
||||
};
|
||||
|
||||
export const Shell = () => <EditorShell guild={guildEnum.guilds[0]} />;
|
|
@ -0,0 +1,81 @@
|
|||
import { Space } from '@roleypoly/design-system/atoms/space';
|
||||
import { Tab, TabView } from '@roleypoly/design-system/atoms/tab-view';
|
||||
import { EditorMasthead } from '@roleypoly/design-system/molecules/editor-masthead';
|
||||
import { EditorCategoriesTab } from '@roleypoly/design-system/organisms/editor-categories-tab';
|
||||
import { EditorDetailsTab } from '@roleypoly/design-system/organisms/editor-details-tab';
|
||||
import { Category, PresentableGuild } from '@roleypoly/types';
|
||||
import deepEqual from 'deep-equal';
|
||||
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) => {
|
||||
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 } };
|
||||
});
|
||||
};
|
||||
|
||||
const hasChanges = React.useMemo(
|
||||
() => !deepEqual(guild.data, props.guild.data),
|
||||
[guild.data, props.guild.data]
|
||||
);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Space />
|
||||
<TabView
|
||||
initialTab={0}
|
||||
masthead={
|
||||
<EditorMasthead
|
||||
guild={guild}
|
||||
onReset={reset}
|
||||
onSubmit={() => props.onGuildChange?.(guild)}
|
||||
showSaveReset={hasChanges}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<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>
|
||||
</div>
|
||||
);
|
||||
};
|
1
packages/design-system/organisms/editor-shell/index.ts
Normal file
1
packages/design-system/organisms/editor-shell/index.ts
Normal file
|
@ -0,0 +1 @@
|
|||
export * from './EditorShell';
|
Loading…
Add table
Add a link
Reference in a new issue