drawDB/src/components/sidebar.jsx

144 lines
4.0 KiB
React
Raw Normal View History

2023-09-19 20:50:52 +08:00
import React, { useContext, useState } from "react";
import chatIcon from "../assets/chat.png";
import botIcon from "../assets/bot.png";
import teamIcon from "../assets/group.png";
import timeLine from "../assets/process.png";
import todo from "../assets/calendar.png";
2023-09-19 20:50:55 +08:00
import { Tooltip, SideSheet, List } from "@douyinfe/semi-ui";
2023-09-19 20:50:52 +08:00
import { UndoRedoContext } from "../pages/editor";
2023-09-19 20:50:53 +08:00
import Todo from "./todo";
2023-09-19 20:50:57 +08:00
import Chat from "./chat";
2023-09-19 20:46:48 +08:00
export default function Sidebar() {
2023-09-19 20:50:52 +08:00
const SidesheetType = {
NONE: 0,
CHAT: 1,
TEAM: 2,
TODO: 3,
TIMELINE: 4,
BOT: 5,
};
const { undoStack } = useContext(UndoRedoContext);
2023-09-19 20:50:53 +08:00
const [sidesheet, setSidesheet] = useState(SidesheetType.NONE);
2023-09-19 20:50:52 +08:00
const getTitle = (type) => {
switch (type) {
case SidesheetType.TIMELINE:
return (
<div className="flex items-center">
<img src={timeLine} className="w-7" alt="chat icon" />
<div className="ms-3">Timeline</div>
</div>
);
case SidesheetType.CHAT:
return (
<div className="flex items-center">
<img src={chatIcon} className="w-7" alt="chat icon" />
<div className="ms-3">Chat</div>
</div>
);
2023-09-19 20:50:53 +08:00
case SidesheetType.TODO:
2023-09-19 20:50:52 +08:00
return (
<div className="flex items-center">
2023-09-19 20:50:53 +08:00
<img src={todo} className="w-7" alt="todo icon" />
<div className="ms-3">To-do list</div>
2023-09-19 20:50:52 +08:00
</div>
);
default:
break;
}
};
const getContent = (type) => {
switch (type) {
case SidesheetType.TIMELINE:
2023-09-19 20:50:53 +08:00
return renderTimeline();
case SidesheetType.TODO:
return <Todo />;
2023-09-19 20:50:57 +08:00
case SidesheetType.CHAT:
return <Chat />;
2023-09-19 20:50:52 +08:00
default:
break;
}
};
2023-09-19 20:46:48 +08:00
return (
2023-09-19 20:50:52 +08:00
<>
<div className="px-3 py-3 shadow-lg h-full select-none">
<Tooltip content="Chat">
<button
className="block"
onClick={() => setSidesheet(SidesheetType.CHAT)}
>
<img src={chatIcon} className="w-8 mb-5" alt="chat icon" />
</button>
</Tooltip>
<Tooltip content="Team">
<button className="block">
<img src={teamIcon} className="w-8 mb-5" alt="chat icon" />
</button>
</Tooltip>
<Tooltip content="To-do">
2023-09-19 20:50:53 +08:00
<button
className="block"
onClick={() => setSidesheet(SidesheetType.TODO)}
>
<img src={todo} className="w-8 mb-5" alt="todo icon" />
2023-09-19 20:50:52 +08:00
</button>
</Tooltip>
<Tooltip content="Timeline">
<button
className="block"
onClick={() => setSidesheet(SidesheetType.TIMELINE)}
>
<img src={timeLine} className="w-8 mb-5" alt="chat icon" />
</button>
</Tooltip>
<Tooltip content="Botle">
<button className="block">
<img src={botIcon} className="w-8 mb-5" alt="chat icon" />
</button>
</Tooltip>
</div>
<SideSheet
visible={sidesheet !== SidesheetType.NONE}
2023-09-19 20:50:53 +08:00
onCancel={() => {
setSidesheet(SidesheetType.NONE);
}}
2023-09-19 20:50:52 +08:00
width={340}
title={getTitle(sidesheet)}
style={{ paddingBottom: "16px" }}
2023-09-19 20:50:53 +08:00
bodyStyle={{ padding: "0px" }}
2023-09-19 20:50:52 +08:00
>
{getContent(sidesheet)}
</SideSheet>
</>
2023-09-19 20:46:48 +08:00
);
2023-09-19 20:50:52 +08:00
2023-09-19 20:50:53 +08:00
function renderTimeline() {
2023-09-19 20:50:52 +08:00
if (undoStack.length > 0) {
return (
2023-09-19 20:50:55 +08:00
<List>
2023-09-19 20:50:52 +08:00
{[...undoStack].reverse().map((e) => (
2023-09-19 20:50:57 +08:00
<List.Item
style={{ padding: "4px 18px 4px 18px" }}
className="hover:bg-slate-100"
>
2023-09-19 20:50:55 +08:00
<div className="flex items-center py-1 w-full">
2023-09-19 20:50:52 +08:00
<i className="block fa-regular fa-circle fa-xs"></i>
<div className="ms-2">{e.message}</div>
</div>
2023-09-19 20:50:55 +08:00
</List.Item>
2023-09-19 20:50:52 +08:00
))}
2023-09-19 20:50:55 +08:00
</List>
2023-09-19 20:50:52 +08:00
);
} else {
return (
2023-09-19 20:50:53 +08:00
<div className="m-5">
2023-09-19 20:50:52 +08:00
You havent added anything to your diagram yet.
</div>
);
}
}
2023-09-19 20:46:48 +08:00
}