feat: boards dnd editor for mobile
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
import React, { FC, useState } from "react";
|
import React, { CSSProperties, FC, useState } from "react";
|
||||||
import { Box, Group, Text } from "@mantine/core";
|
import { Box, Group, Text } from "@mantine/core";
|
||||||
import BoardMenu from "@/app/deals/components/Board/BoardMenu";
|
import BoardMenu from "@/app/deals/components/Board/BoardMenu";
|
||||||
import { useBoardsContext } from "@/app/deals/contexts/BoardsContext";
|
import { useBoardsContext } from "@/app/deals/contexts/BoardsContext";
|
||||||
@ -7,9 +7,10 @@ import { BoardSchema } from "@/lib/client";
|
|||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
board: BoardSchema;
|
board: BoardSchema;
|
||||||
|
containerStyle?: CSSProperties;
|
||||||
};
|
};
|
||||||
|
|
||||||
const Board: FC<Props> = ({ board }) => {
|
const Board: FC<Props> = ({ board, containerStyle }) => {
|
||||||
const [isHovered, setIsHovered] = useState(false);
|
const [isHovered, setIsHovered] = useState(false);
|
||||||
const { onUpdateBoard } = useBoardsContext();
|
const { onUpdateBoard } = useBoardsContext();
|
||||||
|
|
||||||
@ -20,7 +21,7 @@ const Board: FC<Props> = ({ board }) => {
|
|||||||
py={"xs"}
|
py={"xs"}
|
||||||
justify={"space-between"}
|
justify={"space-between"}
|
||||||
wrap={"nowrap"}
|
wrap={"nowrap"}
|
||||||
style={{ borderWidth: 1 }}
|
style={{ ...containerStyle, borderWidth: 1 }}
|
||||||
onMouseEnter={() => setIsHovered(true)}
|
onMouseEnter={() => setIsHovered(true)}
|
||||||
onMouseLeave={() => setIsHovered(false)}>
|
onMouseLeave={() => setIsHovered(false)}>
|
||||||
<InPlaceInput
|
<InPlaceInput
|
||||||
|
|||||||
@ -6,12 +6,13 @@ import { useBoardsContext } from "@/app/deals/contexts/BoardsContext";
|
|||||||
import { BoardSchema } from "@/lib/client";
|
import { BoardSchema } from "@/lib/client";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
isHovered: boolean;
|
|
||||||
board: BoardSchema;
|
board: BoardSchema;
|
||||||
startEditing: () => void;
|
startEditing: () => void;
|
||||||
|
isHovered?: boolean;
|
||||||
|
menuIconSize?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
const BoardMenu: FC<Props> = ({ isHovered, board, startEditing }) => {
|
const BoardMenu: FC<Props> = ({ board, startEditing, isHovered = true, menuIconSize = 16 }) => {
|
||||||
const { selectedBoard, onDeleteBoard } = useBoardsContext();
|
const { selectedBoard, onDeleteBoard } = useBoardsContext();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -28,7 +29,7 @@ const BoardMenu: FC<Props> = ({ isHovered, board, startEditing }) => {
|
|||||||
cursor: "pointer",
|
cursor: "pointer",
|
||||||
}}
|
}}
|
||||||
onClick={e => e.stopPropagation()}>
|
onClick={e => e.stopPropagation()}>
|
||||||
<IconDotsVertical size={16} />
|
<IconDotsVertical size={menuIconSize} />
|
||||||
</Box>
|
</Box>
|
||||||
</Menu.Target>
|
</Menu.Target>
|
||||||
<Menu.Dropdown>
|
<Menu.Dropdown>
|
||||||
|
|||||||
@ -17,9 +17,9 @@ const DealContainer: FC<Props> = ({ deal, disabled = false }) => {
|
|||||||
<SortableItem
|
<SortableItem
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
dragHandleStyle={{ cursor: "pointer" }}
|
dragHandleStyle={{ cursor: "pointer" }}
|
||||||
id={deal.id}>
|
id={deal.id}
|
||||||
{dealBody}
|
renderItem={() => dealBody}
|
||||||
</SortableItem>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import React, { FC } from "react";
|
import React, { FC, ReactNode } from "react";
|
||||||
import { IconChevronLeft } from "@tabler/icons-react";
|
import { IconChevronLeft, IconGripVertical } from "@tabler/icons-react";
|
||||||
import { Box, Center, Drawer, Group, rem, Text } from "@mantine/core";
|
import { Box, Center, Divider, Drawer, Group, rem, Text } from "@mantine/core";
|
||||||
import Board from "@/app/deals/components/Board/Board";
|
|
||||||
import { useBoardsContext } from "@/app/deals/contexts/BoardsContext";
|
import { useBoardsContext } from "@/app/deals/contexts/BoardsContext";
|
||||||
import { useProjectsContext } from "@/app/deals/contexts/ProjectsContext";
|
import { useProjectsContext } from "@/app/deals/contexts/ProjectsContext";
|
||||||
import CreateBoardButtonMobile from "@/app/deals/drawers/ProjectBoardsEditorDrawer/components/CreateBoardButtonMobile";
|
import BoardMobile from "@/app/deals/drawers/ProjectBoardsEditorDrawer/components/BoardMobile";
|
||||||
|
import CreateBoardButton from "@/app/deals/drawers/ProjectBoardsEditorDrawer/components/CreateBoardButton";
|
||||||
import SortableDnd from "@/components/dnd/SortableDnd";
|
import SortableDnd from "@/components/dnd/SortableDnd";
|
||||||
import { BoardSchema } from "@/lib/client";
|
import { BoardSchema } from "@/lib/client";
|
||||||
|
|
||||||
@ -20,8 +20,22 @@ const ProjectBoardsEditorDrawer: FC = () => {
|
|||||||
const { selectedProject } = useProjectsContext();
|
const { selectedProject } = useProjectsContext();
|
||||||
const onClose = () => setIsEditorDrawerOpened(false);
|
const onClose = () => setIsEditorDrawerOpened(false);
|
||||||
|
|
||||||
const renderBoard = (board: BoardSchema) => {
|
const renderDraggable = () => (
|
||||||
return <Board board={board} />;
|
<Box p={"xs"}>
|
||||||
|
<IconGripVertical size={22} />
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
|
||||||
|
const renderBoard = (
|
||||||
|
board: BoardSchema,
|
||||||
|
renderDraggable?: (item: BoardSchema) => ReactNode
|
||||||
|
) => {
|
||||||
|
return (
|
||||||
|
<Group wrap={"nowrap"}>
|
||||||
|
{renderDraggable && renderDraggable(board)}
|
||||||
|
<BoardMobile board={board} />
|
||||||
|
</Group>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const onDragEnd = (itemId: number, newLexorank: string) => {
|
const onDragEnd = (itemId: number, newLexorank: string) => {
|
||||||
@ -55,13 +69,16 @@ const ProjectBoardsEditorDrawer: FC = () => {
|
|||||||
</Center>
|
</Center>
|
||||||
<Box p={"lg"} />
|
<Box p={"lg"} />
|
||||||
</Group>
|
</Group>
|
||||||
|
<Divider />
|
||||||
<SortableDnd
|
<SortableDnd
|
||||||
initialItems={boards}
|
initialItems={boards}
|
||||||
renderItem={renderBoard}
|
|
||||||
onDragEnd={onDragEnd}
|
onDragEnd={onDragEnd}
|
||||||
|
renderItem={renderBoard}
|
||||||
|
renderDraggable={renderDraggable}
|
||||||
|
dragHandleStyle={{ width: "auto" }}
|
||||||
vertical
|
vertical
|
||||||
/>
|
/>
|
||||||
<CreateBoardButtonMobile />
|
<CreateBoardButton />
|
||||||
</Drawer>
|
</Drawer>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -0,0 +1,46 @@
|
|||||||
|
import React, { FC } from "react";
|
||||||
|
import { Box, Group, Text } from "@mantine/core";
|
||||||
|
import { modals } from "@mantine/modals";
|
||||||
|
import BoardMenu from "@/app/deals/components/Board/BoardMenu";
|
||||||
|
import { useBoardsContext } from "@/app/deals/contexts/BoardsContext";
|
||||||
|
import { BoardSchema } from "@/lib/client";
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
board: BoardSchema;
|
||||||
|
};
|
||||||
|
|
||||||
|
const BoardMobile: FC<Props> = ({ board }) => {
|
||||||
|
const { onUpdateBoard } = useBoardsContext();
|
||||||
|
|
||||||
|
const startEditing = () => {
|
||||||
|
modals.openContextModal({
|
||||||
|
modal: "enterNameModal",
|
||||||
|
title: "Редактирование доски",
|
||||||
|
withCloseButton: true,
|
||||||
|
innerProps: {
|
||||||
|
onComplete: name => onUpdateBoard(board.id, { name }),
|
||||||
|
defaultValue: board.name,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Group
|
||||||
|
w={"100%"}
|
||||||
|
pr={"md"}
|
||||||
|
py={"xs"}
|
||||||
|
justify={"space-between"}
|
||||||
|
wrap={"nowrap"}>
|
||||||
|
<Box>
|
||||||
|
<Text>{board.name}</Text>
|
||||||
|
</Box>
|
||||||
|
<BoardMenu
|
||||||
|
board={board}
|
||||||
|
startEditing={startEditing}
|
||||||
|
menuIconSize={22}
|
||||||
|
/>
|
||||||
|
</Group>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default BoardMobile;
|
||||||
@ -3,7 +3,7 @@ import { Box, Group, Text } from "@mantine/core";
|
|||||||
import { modals } from "@mantine/modals";
|
import { modals } from "@mantine/modals";
|
||||||
import { useBoardsContext } from "@/app/deals/contexts/BoardsContext";
|
import { useBoardsContext } from "@/app/deals/contexts/BoardsContext";
|
||||||
|
|
||||||
const CreateBoardButtonMobile = () => {
|
const CreateBoardButton = () => {
|
||||||
const { onCreateBoard } = useBoardsContext();
|
const { onCreateBoard } = useBoardsContext();
|
||||||
|
|
||||||
const onStartCreating = () => {
|
const onStartCreating = () => {
|
||||||
@ -18,7 +18,7 @@ const CreateBoardButtonMobile = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Group onClick={onStartCreating}>
|
<Group ml={"xs"} onClick={onStartCreating}>
|
||||||
<IconPlus />
|
<IconPlus />
|
||||||
<Box mt={5}>
|
<Box mt={5}>
|
||||||
<Text>Создать доску</Text>
|
<Text>Создать доску</Text>
|
||||||
@ -27,4 +27,4 @@ const CreateBoardButtonMobile = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default CreateBoardButtonMobile;
|
export default CreateBoardButton;
|
||||||
@ -84,16 +84,18 @@ const FunnelDnd = <
|
|||||||
<SortableItem
|
<SortableItem
|
||||||
key={containerId}
|
key={containerId}
|
||||||
id={containerId}
|
id={containerId}
|
||||||
disabled={disabled}>
|
disabled={disabled}
|
||||||
{renderContainer(
|
renderItem={() =>
|
||||||
container,
|
renderContainer(
|
||||||
<FunnelColumn
|
container,
|
||||||
id={containerId}
|
<FunnelColumn
|
||||||
items={containerItems}
|
id={containerId}
|
||||||
renderItem={renderItem}
|
items={containerItems}
|
||||||
/>
|
renderItem={renderItem}
|
||||||
)}
|
/>
|
||||||
</SortableItem>
|
)
|
||||||
|
}
|
||||||
|
/>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
<FunnelOverlay
|
<FunnelOverlay
|
||||||
|
|||||||
@ -23,11 +23,15 @@ type BaseItem = {
|
|||||||
|
|
||||||
type Props<T extends BaseItem> = {
|
type Props<T extends BaseItem> = {
|
||||||
initialItems: T[];
|
initialItems: T[];
|
||||||
renderItem: (item: T) => ReactNode;
|
renderItem: (
|
||||||
|
item: T,
|
||||||
|
renderDraggable?: (item: T) => ReactNode
|
||||||
|
) => ReactNode;
|
||||||
|
renderDraggable?: (item: T) => ReactNode; // if not passed - the whole item renders as draggable
|
||||||
|
dragHandleStyle?: CSSProperties;
|
||||||
onDragEnd: (itemId: number, newLexorank: string) => void;
|
onDragEnd: (itemId: number, newLexorank: string) => void;
|
||||||
onItemClick?: (item: T) => void;
|
onItemClick?: (item: T) => void;
|
||||||
containerStyle?: CSSProperties;
|
containerStyle?: CSSProperties;
|
||||||
itemStyle?: CSSProperties;
|
|
||||||
vertical?: boolean;
|
vertical?: boolean;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
};
|
};
|
||||||
@ -35,10 +39,11 @@ type Props<T extends BaseItem> = {
|
|||||||
const SortableDnd = <T extends BaseItem>({
|
const SortableDnd = <T extends BaseItem>({
|
||||||
initialItems,
|
initialItems,
|
||||||
renderItem,
|
renderItem,
|
||||||
|
renderDraggable,
|
||||||
|
dragHandleStyle,
|
||||||
onDragEnd,
|
onDragEnd,
|
||||||
onItemClick,
|
onItemClick,
|
||||||
containerStyle,
|
containerStyle,
|
||||||
itemStyle,
|
|
||||||
vertical,
|
vertical,
|
||||||
disabled = false,
|
disabled = false,
|
||||||
}: Props<T>) => {
|
}: Props<T>) => {
|
||||||
@ -120,18 +125,24 @@ const SortableDnd = <T extends BaseItem>({
|
|||||||
onItemClick(item);
|
onItemClick(item);
|
||||||
}}>
|
}}>
|
||||||
<SortableItem
|
<SortableItem
|
||||||
dragHandleStyle={{ cursor: "pointer" }}
|
|
||||||
itemStyle={itemStyle}
|
|
||||||
id={item.id}
|
id={item.id}
|
||||||
disabled={disabled}>
|
disabled={disabled}
|
||||||
{renderItem(item)}
|
renderItem={renderDraggable =>
|
||||||
</SortableItem>
|
renderItem(item, renderDraggable)
|
||||||
|
}
|
||||||
|
renderDraggable={
|
||||||
|
renderDraggable
|
||||||
|
? () => renderDraggable(item)
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
dragHandleStyle={dragHandleStyle}
|
||||||
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
))}
|
))}
|
||||||
</Flex>
|
</Flex>
|
||||||
</SortableContext>
|
</SortableContext>
|
||||||
<SortableOverlay>
|
<SortableOverlay>
|
||||||
{activeItem ? renderItem(activeItem) : null}
|
{activeItem ? renderItem(activeItem, renderDraggable) : null}
|
||||||
</SortableOverlay>
|
</SortableOverlay>
|
||||||
</DndContext>
|
</DndContext>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import React, { CSSProperties, PropsWithChildren, useMemo } from "react";
|
import React, { CSSProperties, ReactNode, useMemo } from "react";
|
||||||
import { useSortable } from "@dnd-kit/sortable";
|
import { useSortable } from "@dnd-kit/sortable";
|
||||||
import { CSS } from "@dnd-kit/utilities";
|
import { CSS } from "@dnd-kit/utilities";
|
||||||
import DragHandle from "./DragHandle";
|
import DragHandle from "./DragHandle";
|
||||||
@ -6,18 +6,19 @@ import SortableItemContext from "./SortableItemContext";
|
|||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
id: number | string;
|
id: number | string;
|
||||||
itemStyle?: CSSProperties;
|
renderItem: (renderDraggable?: () => ReactNode) => ReactNode;
|
||||||
dragHandleStyle?: CSSProperties;
|
renderDraggable?: () => ReactNode; // if not passed - the whole item renders as draggable
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
|
dragHandleStyle?: CSSProperties;
|
||||||
};
|
};
|
||||||
|
|
||||||
const SortableItem = ({
|
const SortableItem = ({
|
||||||
children,
|
renderItem,
|
||||||
itemStyle,
|
|
||||||
id,
|
|
||||||
dragHandleStyle,
|
dragHandleStyle,
|
||||||
|
renderDraggable,
|
||||||
|
id,
|
||||||
disabled,
|
disabled,
|
||||||
}: PropsWithChildren<Props>) => {
|
}: Props) => {
|
||||||
const {
|
const {
|
||||||
attributes,
|
attributes,
|
||||||
isDragging,
|
isDragging,
|
||||||
@ -41,15 +42,26 @@ const SortableItem = ({
|
|||||||
opacity: isDragging ? 0.4 : undefined,
|
opacity: isDragging ? 0.4 : undefined,
|
||||||
transform: CSS.Translate.toString(transform),
|
transform: CSS.Translate.toString(transform),
|
||||||
transition,
|
transition,
|
||||||
...itemStyle,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const renderDragHandle = () => (
|
||||||
|
<DragHandle style={dragHandleStyle}>
|
||||||
|
{renderDraggable && renderDraggable()}
|
||||||
|
</DragHandle>
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SortableItemContext.Provider value={context}>
|
<SortableItemContext.Provider value={context}>
|
||||||
<div
|
<div
|
||||||
ref={setNodeRef}
|
ref={setNodeRef}
|
||||||
style={style}>
|
style={style}>
|
||||||
<DragHandle style={dragHandleStyle}>{children}</DragHandle>
|
{renderDraggable ? (
|
||||||
|
renderItem(renderDragHandle)
|
||||||
|
) : (
|
||||||
|
<DragHandle style={dragHandleStyle}>
|
||||||
|
{renderItem()}
|
||||||
|
</DragHandle>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</SortableItemContext.Provider>
|
</SortableItemContext.Provider>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user