RightPanel.tsx 6.2 KB

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