| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- import { Affix, Button, Space, Tabs } from "antd";
- import { useEffect, useState } from "react";
- import { CloseOutlined } from "@ant-design/icons";
- import { FullscreenOutlined, FullscreenExitOutlined } from "@ant-design/icons";
- import type { IChannel } from "../channel/Channel";
- import DictComponent from "../dict/DictComponent";
- import type { ArticleType } from "./Article";
- import { useAppSelector } from "../../hooks";
- import { openPanel, rightPanel } from "../../reducers/right-panel";
- import store from "../../store";
- import DiscussionBox from "../discussion/DiscussionBox";
- import { show } from "../../reducers/discussion";
- import { useIntl } from "react-intl";
- import SuggestionBox from "../template/SentEdit/SuggestionBox";
- import ChannelMy from "../channel/ChannelMy";
- import GrammarBook from "../term/GrammarBook";
- interface IWidget {
- curr?: TPanelName;
- type: ArticleType;
- articleId: string;
- selectedChannelsId?: string[];
- onChannelSelect?: Function;
- onClose?: Function;
- onTabChange?: Function;
- }
- const RightPanelWidget = ({
- curr = "close",
- type,
- articleId,
- onChannelSelect,
- selectedChannelsId,
- onClose,
- onTabChange,
- }: IWidget) => {
- const [open, setOpen] = useState(false);
- const [activeTab, setActiveTab] = useState<string>("dict");
- const _openPanel = useAppSelector(rightPanel);
- const intl = useIntl();
- const divMinWidth = 400;
- const divMaxWidth = 700;
- const [divWidth, setDivWidth] = useState(divMinWidth);
- const tabInnerStyle: React.CSSProperties = {
- width: "100%",
- height: `calc(100vh - 96px)`,
- overflowY: "scroll",
- };
- useEffect(() => {
- console.log("panel", _openPanel);
- if (typeof _openPanel !== "undefined") {
- if (typeof onTabChange !== "undefined") {
- onTabChange(_openPanel);
- }
- store.dispatch(openPanel(undefined));
- }
- }, [_openPanel]);
- useEffect(() => {
- switch (curr) {
- case "open":
- setOpen(true);
- break;
- case "dict":
- setOpen(true);
- setActiveTab(curr);
- break;
- case "channel":
- setOpen(true);
- setActiveTab(curr);
- break;
- case "discussion":
- setOpen(true);
- setActiveTab(curr);
- break;
- case "suggestion":
- setOpen(true);
- setActiveTab(curr);
- break;
- case "grammar":
- setOpen(true);
- setActiveTab(curr);
- break;
- case "close":
- setOpen(false);
- break;
- default:
- setOpen(false);
- break;
- }
- }, [curr]);
- return (
- <Affix offsetTop={44}>
- <div
- key="panel"
- style={{
- width: divWidth,
- height: `calc(100vh - 44px)`,
- overflowY: "hidden",
- display: open ? "block" : "none",
- paddingLeft: 8,
- paddingTop: 8,
- }}
- >
- <Tabs
- type="card"
- size="small"
- defaultActiveKey={curr}
- activeKey={activeTab}
- onChange={(activeKey: string) => setActiveTab(activeKey)}
- tabBarExtraContent={{
- right: (
- <Space>
- {divWidth === divMinWidth ? (
- <Button
- type="link"
- icon={<FullscreenOutlined />}
- onClick={() => setDivWidth(divMaxWidth)}
- />
- ) : (
- <Button
- type="link"
- icon={<FullscreenExitOutlined />}
- onClick={() => setDivWidth(divMinWidth)}
- />
- )}
- <Button
- type="text"
- size="small"
- icon={<CloseOutlined />}
- onClick={() => {
- store.dispatch(
- show({
- type: "discussion",
- resType: "sentence",
- })
- );
- if (typeof onClose !== "undefined") {
- onClose();
- }
- }}
- />
- </Space>
- ),
- }}
- items={[
- {
- label: intl.formatMessage({
- id: "columns.library.dict.title",
- }),
- key: "dict",
- children: (
- <div className="dict_component" style={tabInnerStyle}>
- <DictComponent />
- </div>
- ),
- },
- {
- label: intl.formatMessage({
- id: "columns.studio.channel.title",
- }),
- key: "channel",
- children: (
- <div style={tabInnerStyle}>
- <ChannelMy
- type={type}
- articleId={articleId}
- selectedKeys={selectedChannelsId}
- onSelect={(e: IChannel[]) => {
- console.log(e);
- if (typeof onChannelSelect !== "undefined") {
- onChannelSelect(e);
- }
- }}
- />
- </div>
- ),
- },
- {
- label: intl.formatMessage({
- id: "buttons.discussion",
- }),
- key: "discussion",
- children: (
- <div style={tabInnerStyle}>
- <DiscussionBox />
- </div>
- ),
- },
- {
- label: intl.formatMessage({
- id: "buttons.suggestion",
- }),
- key: "suggestion",
- children: (
- <div style={tabInnerStyle}>
- <SuggestionBox />
- </div>
- ),
- },
- {
- label: intl.formatMessage({
- id: "columns.library.palihandbook.title",
- }),
- key: "grammar",
- children: (
- <div style={tabInnerStyle}>
- <GrammarBook />
- </div>
- ),
- },
- ]}
- />
- </div>
- </Affix>
- );
- };
- export default RightPanelWidget;
|