LeftSider.tsx 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. import { Link } from "react-router-dom";
  2. import { useIntl } from "react-intl";
  3. import { useParams } from "react-router-dom";
  4. import type { MenuProps } from "antd";
  5. import { Affix, Layout } from "antd";
  6. import { Menu } from "antd";
  7. import {
  8. AppstoreOutlined,
  9. HomeOutlined,
  10. TeamOutlined,
  11. } from "@ant-design/icons";
  12. import { useAppSelector } from "../../hooks";
  13. import { currentUser } from "../../reducers/current-user";
  14. const { Sider } = Layout;
  15. const onClick: MenuProps["onClick"] = (e) => {
  16. console.log("click ", e);
  17. };
  18. type IWidgetHeadBar = {
  19. selectedKeys?: string;
  20. };
  21. const LeftSiderWidget = ({ selectedKeys = "" }: IWidgetHeadBar) => {
  22. //Library head bar
  23. const user = useAppSelector(currentUser);
  24. const intl = useIntl(); //i18n
  25. const { studioname } = useParams();
  26. const linkRecent = "/studio/" + studioname + "/recent/list";
  27. const linkChannel = "/studio/" + studioname + "/channel/list";
  28. const linkGroup = "/studio/" + studioname + "/group/list";
  29. const linkUserdict = "/studio/" + studioname + "/dict/list";
  30. const linkTerm = "/studio/" + studioname + "/term/list";
  31. const linkArticle = "/studio/" + studioname + "/article/list";
  32. const linkAnalysis = "/studio/" + studioname + "/exp/list";
  33. const linkCourse = "/studio/" + studioname + "/course/list";
  34. const linkSetting = "/studio/" + studioname + "/setting";
  35. const items: MenuProps["items"] = [
  36. {
  37. label: "常用",
  38. key: "basic",
  39. icon: <HomeOutlined />,
  40. children: [
  41. {
  42. label: (
  43. <Link to={`/studio/${studioname}/palicanon`}>
  44. {intl.formatMessage({
  45. id: "columns.studio.palicanon.title",
  46. })}
  47. </Link>
  48. ),
  49. key: "palicanon",
  50. disabled: true,
  51. },
  52. {
  53. label: (
  54. <Link to={linkRecent}>
  55. {intl.formatMessage({
  56. id: "columns.studio.recent.title",
  57. })}
  58. </Link>
  59. ),
  60. key: "recent",
  61. },
  62. {
  63. label: (
  64. <Link to={linkChannel}>
  65. {intl.formatMessage({
  66. id: "columns.studio.channel.title",
  67. })}
  68. </Link>
  69. ),
  70. key: "channel",
  71. },
  72. {
  73. label: (
  74. <Link to={linkAnalysis}>
  75. {intl.formatMessage({
  76. id: "columns.exp.title",
  77. })}
  78. </Link>
  79. ),
  80. key: "analysis",
  81. },
  82. ],
  83. },
  84. {
  85. label: "高级",
  86. key: "advance",
  87. icon: <AppstoreOutlined />,
  88. children: [
  89. {
  90. label: (
  91. <Link to={linkCourse}>
  92. {intl.formatMessage({
  93. id: "columns.library.course.title",
  94. })}
  95. </Link>
  96. ),
  97. key: "course",
  98. },
  99. {
  100. label: (
  101. <Link to={linkUserdict}>
  102. {intl.formatMessage({
  103. id: "columns.studio.userdict.title",
  104. })}
  105. </Link>
  106. ),
  107. key: "userdict",
  108. },
  109. {
  110. label: (
  111. <Link to={linkTerm}>
  112. {intl.formatMessage({
  113. id: "columns.studio.term.title",
  114. })}
  115. </Link>
  116. ),
  117. key: "term",
  118. },
  119. {
  120. label: (
  121. <Link to={linkArticle}>
  122. {intl.formatMessage({
  123. id: "columns.studio.article.title",
  124. })}
  125. </Link>
  126. ),
  127. key: "article",
  128. },
  129. {
  130. label: (
  131. <Link to={`/studio/${studioname}/anthology/list`}>
  132. {intl.formatMessage({
  133. id: "columns.studio.anthology.title",
  134. })}
  135. </Link>
  136. ),
  137. key: "anthology",
  138. },
  139. {
  140. label: (
  141. <Link to={`/studio/${studioname}/attachment/list`}>
  142. {intl.formatMessage({
  143. id: "columns.studio.attachment.title",
  144. })}
  145. </Link>
  146. ),
  147. key: "attachment",
  148. disabled: user?.roles?.includes("uploader") ? false : true,
  149. },
  150. {
  151. label: (
  152. <Link to={linkSetting}>
  153. {intl.formatMessage({
  154. id: "columns.studio.setting.title",
  155. })}
  156. </Link>
  157. ),
  158. key: "setting",
  159. },
  160. ],
  161. },
  162. {
  163. label: intl.formatMessage({ id: "labels.collaboration" }),
  164. key: "collaboration",
  165. icon: <TeamOutlined />,
  166. children: [
  167. {
  168. label: (
  169. <Link to={linkGroup}>
  170. {intl.formatMessage({
  171. id: "columns.studio.group.title",
  172. })}
  173. </Link>
  174. ),
  175. key: "group",
  176. disabled: user?.roles?.includes("basic"),
  177. },
  178. {
  179. label: (
  180. <Link to={`/studio/${studioname}/invite/list`}>
  181. {intl.formatMessage({
  182. id: "columns.studio.invite.title",
  183. })}
  184. </Link>
  185. ),
  186. key: "invite",
  187. disabled: user?.roles?.includes("basic"),
  188. },
  189. {
  190. label: (
  191. <Link to={`/studio/${studioname}/transfer/list`}>
  192. {intl.formatMessage({
  193. id: "columns.studio.transfer.title",
  194. })}
  195. </Link>
  196. ),
  197. key: "transfer",
  198. },
  199. ],
  200. },
  201. ];
  202. return (
  203. <Affix offsetTop={0}>
  204. <div
  205. style={{
  206. height: "100vh",
  207. overflowY: "scroll",
  208. }}
  209. >
  210. <Sider width={200} breakpoint="lg" className="site-layout-background">
  211. <Menu
  212. theme="light"
  213. onClick={onClick}
  214. defaultSelectedKeys={[selectedKeys]}
  215. defaultOpenKeys={["basic", "advance", "collaboration"]}
  216. mode="inline"
  217. items={items}
  218. />
  219. </Sider>
  220. </div>
  221. </Affix>
  222. );
  223. };
  224. export default LeftSiderWidget;