Article.tsx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. import { IArticleDataResponse } from "../api/Article";
  2. import TypeArticle from "./TypeArticle";
  3. import TypeAnthology from "./TypeAnthology";
  4. import TypeTerm from "./TypeTerm";
  5. import TypePali from "./TypePali";
  6. import "./article.css";
  7. import TypePage from "./TypePage";
  8. import TypeCSPara from "./TypeCSPara";
  9. export type ArticleMode = "read" | "edit" | "wbw";
  10. export type ArticleType =
  11. | "anthology"
  12. | "article"
  13. | "series"
  14. | "chapter"
  15. | "para"
  16. | "cs-para"
  17. | "sent"
  18. | "sim"
  19. | "page"
  20. | "textbook"
  21. | "exercise"
  22. | "exercise-list"
  23. | "sent-original"
  24. | "sent-commentary"
  25. | "sent-nissaya"
  26. | "sent-translation"
  27. | "term";
  28. /**
  29. * 每种article type 对应的路由参数
  30. * article/id?anthology=id&channel=id1,id2&mode=ArticleMode
  31. * chapter/book-para?channel=id1,id2&mode=ArticleMode
  32. * para/book?par=para1,para2&channel=id1,id2&mode=ArticleMode
  33. * cs-para/book-para?channel=id1,id2&mode=ArticleMode
  34. * sent/id?channel=id1,id2&mode=ArticleMode
  35. * sim/id?channel=id1,id2&mode=ArticleMode
  36. * textbook/articleId?course=id&mode=ArticleMode
  37. * exercise/articleId?course=id&exercise=id&username=name&mode=ArticleMode
  38. * exercise-list/articleId?course=id&exercise=id&mode=ArticleMode
  39. * sent-original/id
  40. */
  41. interface IWidget {
  42. type?: ArticleType;
  43. articleId?: string;
  44. mode?: ArticleMode | null;
  45. channelId?: string | null;
  46. book?: string | null;
  47. para?: string | null;
  48. anthologyId?: string | null;
  49. courseId?: string;
  50. exerciseId?: string;
  51. userName?: string;
  52. active?: boolean;
  53. focus?: string | null;
  54. onArticleChange?: Function;
  55. onFinal?: Function;
  56. onLoad?: Function;
  57. onAnthologySelect?: Function;
  58. }
  59. const ArticleWidget = ({
  60. type,
  61. book,
  62. para,
  63. channelId,
  64. articleId,
  65. anthologyId,
  66. courseId,
  67. exerciseId,
  68. userName,
  69. mode = "read",
  70. active = false,
  71. focus,
  72. onArticleChange,
  73. onFinal,
  74. onLoad,
  75. onAnthologySelect,
  76. }: IWidget) => {
  77. return (
  78. <div>
  79. {type === "article" ? (
  80. <TypeArticle
  81. type={type}
  82. articleId={articleId}
  83. channelId={channelId}
  84. mode={mode}
  85. anthologyId={anthologyId}
  86. active={active}
  87. onArticleChange={(type: ArticleType, id: string, target: string) => {
  88. if (typeof onArticleChange !== "undefined") {
  89. onArticleChange(type, id, target);
  90. }
  91. }}
  92. onLoad={(data: IArticleDataResponse) => {
  93. if (typeof onLoad !== "undefined") {
  94. onLoad(data);
  95. }
  96. }}
  97. onAnthologySelect={(id: string) => {
  98. if (typeof onAnthologySelect !== "undefined") {
  99. onAnthologySelect(id);
  100. }
  101. }}
  102. />
  103. ) : type === "anthology" ? (
  104. <TypeAnthology
  105. articleId={articleId}
  106. channelId={channelId}
  107. mode={mode}
  108. onArticleChange={(type: ArticleType, id: string, target: string) => {
  109. if (typeof onArticleChange !== "undefined") {
  110. onArticleChange(type, id, target);
  111. }
  112. }}
  113. />
  114. ) : type === "term" ? (
  115. <TypeTerm
  116. articleId={articleId}
  117. channelId={channelId}
  118. mode={mode}
  119. onArticleChange={(type: ArticleType, id: string, target: string) => {
  120. if (typeof onArticleChange !== "undefined") {
  121. onArticleChange(type, id, target);
  122. }
  123. }}
  124. />
  125. ) : type === "chapter" || type === "para" ? (
  126. <TypePali
  127. type={type}
  128. articleId={articleId}
  129. channelId={channelId}
  130. mode={mode}
  131. book={book}
  132. para={para}
  133. focus={focus}
  134. onArticleChange={(type: ArticleType, id: string, target: string) => {
  135. if (typeof onArticleChange !== "undefined") {
  136. onArticleChange(type, id, target);
  137. }
  138. }}
  139. />
  140. ) : type === "page" ? (
  141. <TypePage
  142. articleId={articleId}
  143. channelId={channelId}
  144. focus={focus}
  145. mode={mode}
  146. onArticleChange={(type: ArticleType, id: string, target: string) => {
  147. if (typeof onArticleChange !== "undefined") {
  148. onArticleChange(type, id, target);
  149. }
  150. }}
  151. />
  152. ) : type === "cs-para" ? (
  153. <TypeCSPara
  154. articleId={articleId}
  155. channelId={channelId}
  156. mode={mode}
  157. onArticleChange={(type: ArticleType, id: string, target: string) => {
  158. if (typeof onArticleChange !== "undefined") {
  159. onArticleChange(type, id, target);
  160. }
  161. }}
  162. />
  163. ) : (
  164. <></>
  165. )}
  166. </div>
  167. );
  168. };
  169. export default ArticleWidget;