| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- import { Card } from "antd";
- import { useEffect, useRef, useState } from "react";
- import { IStudio } from "../auth/StudioName";
- import type { IUser } from "../auth/User";
- import { IChannel } from "../channel/Channel";
- import { TContentType } from "../discussion/DiscussionCreate";
- import { ITocPathNode } from "../corpus/TocPath";
- import SentContent from "./SentEdit/SentContent";
- import SentTab from "./SentEdit/SentTab";
- import { IWbw } from "./Wbw/WbwWord";
- import { ArticleMode } from "../article/Article";
- import { TChannelType } from "../api/Channel";
- import { useAppSelector } from "../../hooks";
- import { currFocus } from "../../reducers/focus";
- export interface IResNumber {
- translation?: number;
- nissaya?: number;
- commentary?: number;
- origin?: number;
- sim?: number;
- }
- export interface ISuggestionCount {
- suggestion?: number;
- discussion?: number;
- }
- export interface ISentence {
- id?: string;
- content: string | null;
- contentType?: TContentType;
- html: string;
- book: number;
- para: number;
- wordStart: number;
- wordEnd: number;
- editor: IUser;
- acceptor?: IUser;
- prEditAt?: string;
- channel: IChannel;
- studio?: IStudio;
- updateAt: string;
- createdAt?: string;
- suggestionCount?: ISuggestionCount;
- openInEditMode?: boolean;
- translationChannels?: string[];
- }
- export interface ISentenceId {
- book: number;
- para: number;
- wordStart: number;
- wordEnd: number;
- }
- export interface IWidgetSentEditInner {
- id: string;
- book: number;
- para: number;
- wordStart: number;
- wordEnd: number;
- channels?: string[];
- origin?: ISentence[];
- translation?: ISentence[];
- path?: ITocPathNode[];
- layout?: "row" | "column";
- tranNum?: number;
- nissayaNum?: number;
- commNum?: number;
- originNum: number;
- simNum?: number;
- compact?: boolean;
- mode?: ArticleMode;
- wbwProgress?: boolean;
- }
- export const SentEditInner = ({
- id,
- book,
- para,
- wordStart,
- wordEnd,
- channels,
- origin,
- translation,
- path,
- layout = "column",
- tranNum,
- nissayaNum,
- commNum,
- originNum,
- simNum,
- compact = false,
- mode,
- wbwProgress = false,
- }: IWidgetSentEditInner) => {
- const [wbwData, setWbwData] = useState<IWbw[]>();
- const [magicDict, setMagicDict] = useState<string>();
- const [magicDictLoading, setMagicDictLoading] = useState(false);
- const [isCompact, setIsCompact] = useState(compact);
- const [articleMode, setArticleMode] = useState<ArticleMode | undefined>(mode);
- const [loadedRes, setLoadedRes] = useState<IResNumber>();
- const [isFocus, setIsFocus] = useState(false);
- const focus = useAppSelector(currFocus);
- const divRef = useRef<HTMLDivElement>(null);
- useEffect(() => {
- if (focus) {
- if (focus.focus?.type === "sentence") {
- if (focus.focus.id === id) {
- setIsFocus(true);
- divRef.current?.scrollIntoView({
- behavior: "smooth",
- block: "nearest",
- inline: "nearest",
- });
- } else {
- setIsFocus(false);
- }
- }
- } else {
- setIsFocus(false);
- }
- }, [focus, id]);
- useEffect(() => {
- const validRes = (value: ISentence, type: TChannelType) =>
- value.channel.type === type &&
- value.content &&
- value.content.trim().length > 0;
- if (translation) {
- const res = {
- translation: translation.filter((value) =>
- validRes(value, "translation")
- ).length,
- nissaya: translation.filter((value) => validRes(value, "nissaya"))
- .length,
- commentary: translation.filter((value) => validRes(value, "commentary"))
- .length,
- };
- setLoadedRes(res);
- }
- }, [translation]);
- useEffect(() => {
- const content = origin?.find(
- (value) => value.contentType === "json"
- )?.content;
- if (content) {
- setWbwData(JSON.parse(content));
- }
- }, []);
- const channelsId = translation?.map((item) => item.channel.id);
- return (
- <Card
- ref={divRef}
- bodyStyle={{ paddingBottom: 0, paddingLeft: 0, paddingRight: 0 }}
- style={{
- border: isFocus
- ? "2px solid rgb(0 0 200 / 50%)"
- : "1px solid rgb(128 128 128 / 10%)",
- marginTop: 4,
- borderRadius: 6,
- backgroundColor: "rgb(255 255 255 / 8%)",
- }}
- size="small"
- >
- <SentContent
- sid={id}
- book={book}
- para={para}
- wordStart={wordStart}
- wordEnd={wordEnd}
- origin={origin}
- translation={translation}
- layout={layout}
- magicDict={magicDict}
- compact={isCompact}
- mode={articleMode}
- wbwProgress={wbwProgress}
- onWbwChange={(data: IWbw[]) => {
- setWbwData(data);
- }}
- onMagicDictDone={() => {
- setMagicDictLoading(false);
- setMagicDict(undefined);
- }}
- />
- <SentTab
- id={id}
- book={book}
- para={para}
- wordStart={wordStart}
- wordEnd={wordEnd}
- channelsId={channelsId}
- path={path}
- tranNum={tranNum}
- nissayaNum={nissayaNum}
- commNum={commNum}
- originNum={originNum}
- simNum={simNum}
- loadedRes={loadedRes}
- wbwData={wbwData}
- magicDictLoading={magicDictLoading}
- compact={isCompact}
- mode={articleMode}
- onMagicDict={(type: string) => {
- setMagicDict(type);
- setMagicDictLoading(true);
- }}
- onCompact={(value: boolean) => setIsCompact(value)}
- onModeChange={(value: ArticleMode | undefined) => setArticleMode(value)}
- />
- </Card>
- );
- };
- interface IWidgetSentEdit {
- props: string;
- }
- const Widget = ({ props }: IWidgetSentEdit) => {
- const prop = JSON.parse(atob(props)) as IWidgetSentEditInner;
- //console.log("sent data", prop);
- return <SentEditInner {...prop} />;
- };
- export default Widget;
|