SentEdit.tsx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. import { Card } from "antd";
  2. import { useEffect, useState } from "react";
  3. import { IStudio } from "../auth/StudioName";
  4. import type { IUser } from "../auth/User";
  5. import { IChannel } from "../channel/Channel";
  6. import { TContentType } from "../discussion/DiscussionCreate";
  7. import { ITocPathNode } from "../corpus/TocPath";
  8. import SentContent from "./SentEdit/SentContent";
  9. import SentTab from "./SentEdit/SentTab";
  10. import { IWbw } from "./Wbw/WbwWord";
  11. import { ArticleMode } from "../article/Article";
  12. import { TChannelType } from "../api/Channel";
  13. export interface IResNumber {
  14. translation?: number;
  15. nissaya?: number;
  16. commentary?: number;
  17. origin?: number;
  18. sim?: number;
  19. }
  20. export interface ISuggestionCount {
  21. suggestion?: number;
  22. discussion?: number;
  23. }
  24. export interface ISentence {
  25. id?: string;
  26. content: string | null;
  27. contentType?: TContentType;
  28. html: string;
  29. book: number;
  30. para: number;
  31. wordStart: number;
  32. wordEnd: number;
  33. editor: IUser;
  34. acceptor?: IUser;
  35. prEditAt?: string;
  36. channel: IChannel;
  37. studio?: IStudio;
  38. updateAt: string;
  39. createdAt?: string;
  40. suggestionCount?: ISuggestionCount;
  41. openInEditMode?: boolean;
  42. translationChannels?: string[];
  43. }
  44. export interface ISentenceId {
  45. book: number;
  46. para: number;
  47. wordStart: number;
  48. wordEnd: number;
  49. }
  50. export interface IWidgetSentEditInner {
  51. id: string;
  52. book: number;
  53. para: number;
  54. wordStart: number;
  55. wordEnd: number;
  56. channels?: string[];
  57. origin?: ISentence[];
  58. translation?: ISentence[];
  59. path?: ITocPathNode[];
  60. layout?: "row" | "column";
  61. tranNum?: number;
  62. nissayaNum?: number;
  63. commNum?: number;
  64. originNum: number;
  65. simNum?: number;
  66. compact?: boolean;
  67. mode?: ArticleMode;
  68. }
  69. export const SentEditInner = ({
  70. id,
  71. book,
  72. para,
  73. wordStart,
  74. wordEnd,
  75. channels,
  76. origin,
  77. translation,
  78. path,
  79. layout = "column",
  80. tranNum,
  81. nissayaNum,
  82. commNum,
  83. originNum,
  84. simNum,
  85. compact = false,
  86. mode,
  87. }: IWidgetSentEditInner) => {
  88. const [wbwData, setWbwData] = useState<IWbw[]>();
  89. const [magicDict, setMagicDict] = useState<string>();
  90. const [magicDictLoading, setMagicDictLoading] = useState(false);
  91. const [isCompact, setIsCompact] = useState(compact);
  92. const [articleMode, setArticleMode] = useState<ArticleMode | undefined>(mode);
  93. const [loadedRes, setLoadedRes] = useState<IResNumber>();
  94. useEffect(() => {
  95. const validRes = (value: ISentence, type: TChannelType) =>
  96. value.channel.type === type &&
  97. value.content &&
  98. value.content.trim().length > 0;
  99. if (translation) {
  100. const res = {
  101. translation: translation.filter((value) =>
  102. validRes(value, "translation")
  103. ).length,
  104. nissaya: translation.filter((value) => validRes(value, "nissaya"))
  105. .length,
  106. commentary: translation.filter((value) => validRes(value, "commentary"))
  107. .length,
  108. };
  109. setLoadedRes(res);
  110. }
  111. }, [translation]);
  112. useEffect(() => {
  113. const content = origin?.find(
  114. (value) => value.contentType === "json"
  115. )?.content;
  116. if (content) {
  117. setWbwData(JSON.parse(content));
  118. }
  119. }, []);
  120. const channelsId = translation?.map((item) => item.channel.id);
  121. return (
  122. <Card
  123. bodyStyle={{ paddingBottom: 0, paddingLeft: 0, paddingRight: 0 }}
  124. style={{
  125. border: "1px solid rgb(128 128 128 / 10%)",
  126. marginTop: 4,
  127. borderRadius: 6,
  128. backgroundColor: "rgb(255 255 255 / 8%)",
  129. }}
  130. size="small"
  131. >
  132. <SentContent
  133. sid={id}
  134. book={book}
  135. para={para}
  136. wordStart={wordStart}
  137. wordEnd={wordEnd}
  138. origin={origin}
  139. translation={translation}
  140. layout={layout}
  141. magicDict={magicDict}
  142. compact={isCompact}
  143. mode={articleMode}
  144. onWbwChange={(data: IWbw[]) => {
  145. setWbwData(data);
  146. }}
  147. onMagicDictDone={() => {
  148. setMagicDictLoading(false);
  149. setMagicDict(undefined);
  150. }}
  151. />
  152. <SentTab
  153. id={id}
  154. book={book}
  155. para={para}
  156. wordStart={wordStart}
  157. wordEnd={wordEnd}
  158. channelsId={channelsId}
  159. path={path}
  160. tranNum={tranNum}
  161. nissayaNum={nissayaNum}
  162. commNum={commNum}
  163. originNum={originNum}
  164. simNum={simNum}
  165. loadedRes={loadedRes}
  166. wbwData={wbwData}
  167. magicDictLoading={magicDictLoading}
  168. compact={isCompact}
  169. mode={articleMode}
  170. onMagicDict={(type: string) => {
  171. setMagicDict(type);
  172. setMagicDictLoading(true);
  173. }}
  174. onCompact={(value: boolean) => setIsCompact(value)}
  175. onModeChange={(value: ArticleMode | undefined) => setArticleMode(value)}
  176. />
  177. </Card>
  178. );
  179. };
  180. interface IWidgetSentEdit {
  181. props: string;
  182. }
  183. const Widget = ({ props }: IWidgetSentEdit) => {
  184. const prop = JSON.parse(atob(props)) as IWidgetSentEditInner;
  185. //console.log("sent data", prop);
  186. return <SentEditInner {...prop} />;
  187. };
  188. export default Widget;