RightPanel.tsx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. import { Affix, Button, Space, Tabs } from "antd";
  2. import { useEffect, useState } from "react";
  3. import { CloseOutlined } from "@ant-design/icons";
  4. import { FullscreenOutlined, FullscreenExitOutlined } from "@ant-design/icons";
  5. import { IChannel } from "../channel/Channel";
  6. import ChannelPickerTable from "../channel/ChannelPickerTable";
  7. import DictComponent from "../dict/DictComponent";
  8. import { ArticleType } from "./Article";
  9. import { useAppSelector } from "../../hooks";
  10. import { openPanel, rightPanel } from "../../reducers/right-panel";
  11. import store from "../../store";
  12. import DiscussionBox from "../discussion/DiscussionBox";
  13. import { show } from "../../reducers/discussion";
  14. import { useIntl } from "react-intl";
  15. import SuggestionBox from "../template/SentEdit/SuggestionBox";
  16. export type TPanelName =
  17. | "dict"
  18. | "channel"
  19. | "discussion"
  20. | "suggestion"
  21. | "close"
  22. | "open";
  23. interface IWidget {
  24. curr?: TPanelName;
  25. type: ArticleType;
  26. articleId: string;
  27. selectedChannelsId?: string[];
  28. onChannelSelect?: Function;
  29. onClose?: Function;
  30. onTabChange?: Function;
  31. }
  32. const RightPanelWidget = ({
  33. curr = "close",
  34. type,
  35. articleId,
  36. onChannelSelect,
  37. selectedChannelsId,
  38. onClose,
  39. onTabChange,
  40. }: IWidget) => {
  41. const [open, setOpen] = useState(false);
  42. const [activeTab, setActiveTab] = useState<string>("dict");
  43. const _openPanel = useAppSelector(rightPanel);
  44. const intl = useIntl();
  45. const divMinWidth = 400;
  46. const divMaxWidth = 700;
  47. const [divWidth, setDivWidth] = useState(divMinWidth);
  48. const tabInnerStyle: React.CSSProperties = {
  49. width: "100%",
  50. height: `calc(100vh - 96px)`,
  51. overflowY: "scroll",
  52. };
  53. useEffect(() => {
  54. console.log("panel", _openPanel);
  55. if (typeof _openPanel !== "undefined") {
  56. if (typeof onTabChange !== "undefined") {
  57. onTabChange(_openPanel);
  58. }
  59. store.dispatch(openPanel(undefined));
  60. }
  61. }, [_openPanel]);
  62. useEffect(() => {
  63. switch (curr) {
  64. case "open":
  65. setOpen(true);
  66. break;
  67. case "dict":
  68. setOpen(true);
  69. setActiveTab(curr);
  70. break;
  71. case "channel":
  72. setOpen(true);
  73. setActiveTab(curr);
  74. break;
  75. case "discussion":
  76. setOpen(true);
  77. setActiveTab(curr);
  78. break;
  79. case "suggestion":
  80. setOpen(true);
  81. setActiveTab(curr);
  82. break;
  83. case "close":
  84. setOpen(false);
  85. break;
  86. default:
  87. setOpen(false);
  88. break;
  89. }
  90. }, [curr]);
  91. return (
  92. <Affix offsetTop={44}>
  93. <div
  94. key="panel"
  95. style={{
  96. width: divWidth,
  97. height: `calc(100vh - 44px)`,
  98. overflowY: "hidden",
  99. display: open ? "block" : "none",
  100. paddingLeft: 8,
  101. paddingTop: 8,
  102. }}
  103. >
  104. <Tabs
  105. type="card"
  106. size="small"
  107. defaultActiveKey={curr}
  108. activeKey={activeTab}
  109. onChange={(activeKey: string) => setActiveTab(activeKey)}
  110. tabBarExtraContent={{
  111. right: (
  112. <Space>
  113. {divWidth === divMinWidth ? (
  114. <Button
  115. type="link"
  116. icon={<FullscreenOutlined />}
  117. onClick={() => setDivWidth(divMaxWidth)}
  118. />
  119. ) : (
  120. <Button
  121. type="link"
  122. icon={<FullscreenExitOutlined />}
  123. onClick={() => setDivWidth(divMinWidth)}
  124. />
  125. )}
  126. <Button
  127. type="text"
  128. size="small"
  129. icon={<CloseOutlined />}
  130. onClick={() => {
  131. store.dispatch(
  132. show({
  133. type: "discussion",
  134. resType: "sentence",
  135. })
  136. );
  137. if (typeof onClose !== "undefined") {
  138. onClose();
  139. }
  140. }}
  141. />
  142. </Space>
  143. ),
  144. }}
  145. items={[
  146. {
  147. label: intl.formatMessage({
  148. id: "columns.library.dict.title",
  149. }),
  150. key: "dict",
  151. children: (
  152. <div style={tabInnerStyle}>
  153. <DictComponent />
  154. </div>
  155. ),
  156. },
  157. {
  158. label: intl.formatMessage({
  159. id: "columns.studio.channel.title",
  160. }),
  161. key: "channel",
  162. children: (
  163. <div style={tabInnerStyle}>
  164. <ChannelPickerTable
  165. type={type}
  166. articleId={articleId}
  167. selectedKeys={selectedChannelsId}
  168. onSelect={(e: IChannel[]) => {
  169. console.log(e);
  170. if (typeof onChannelSelect !== "undefined") {
  171. onChannelSelect(e);
  172. }
  173. }}
  174. />
  175. </div>
  176. ),
  177. },
  178. {
  179. label: intl.formatMessage({
  180. id: "buttons.discussion",
  181. }),
  182. key: "discussion",
  183. children: (
  184. <div style={tabInnerStyle}>
  185. <DiscussionBox />
  186. </div>
  187. ),
  188. },
  189. {
  190. label: intl.formatMessage({
  191. id: "buttons.suggestion",
  192. }),
  193. key: "suggestion",
  194. children: (
  195. <div style={tabInnerStyle}>
  196. <SuggestionBox />
  197. </div>
  198. ),
  199. },
  200. ]}
  201. />
  202. </div>
  203. </Affix>
  204. );
  205. };
  206. export default RightPanelWidget;