import type { IArticleDataResponse } from "../../api/Article"; import TypeArticle from "./TypeArticle"; import TypeAnthology from "./TypeAnthology"; import TypeTerm from "./TypeTerm"; import TypePali from "./TypePali"; import "./article.css"; import TypePage from "./TypePage"; import TypeCSPara from "./TypeCSPara"; import type { ISearchParams } from "../../pages/library/article/show"; import TypeCourse from "./TypeCourse"; import { useEffect, useState } from "react"; import { fullUrl } from "../../utils"; import TypeSeries from "./TypeSeries"; import DiscussionCount from "../discussion/DiscussionCount"; import TypeTask from "./TypeTask"; interface IWidget { type?: ArticleType; articleId?: string; mode?: ArticleMode | null; channelId?: string | null; parentChannels?: string[]; book?: string | null; para?: string | null; anthologyId?: string | null; courseId?: string | null; active?: boolean; focus?: string | null; hideInteractive?: boolean; hideTitle?: boolean; isSubWindow?: boolean; onArticleChange?: ( type: ArticleType, id: string, target: string, param?: ISearchParams[] ) => void; onLoad?: Function; onAnthologySelect?: Function; onTitle?: Function; onArticleEdit?: Function; } const ArticleWidget = ({ type, book, para, channelId, parentChannels, articleId, anthologyId, courseId, mode = "read", active = false, focus, hideInteractive = false, hideTitle = false, isSubWindow = false, onArticleChange, onLoad, onAnthologySelect, onTitle, onArticleEdit, }: IWidget) => { const [currId, setCurrId] = useState(articleId); useEffect(() => setCurrId(articleId), [articleId]); return (
{type === "article" ? ( { if (typeof onArticleEdit !== "undefined") { onArticleEdit(value); } }} onArticleChange={onArticleChange} onLoad={(data: IArticleDataResponse) => { if (typeof onLoad !== "undefined") { onLoad(data); } if (typeof onTitle !== "undefined") { onTitle(data.title); } }} onAnthologySelect={(id: string) => { if (typeof onAnthologySelect !== "undefined") { onAnthologySelect(id); } }} /> ) : type === "anthology" ? ( { if (typeof onArticleChange !== "undefined") { onArticleChange(type, id, target); } }} onTitle={(value: string) => { if (typeof onTitle !== "undefined") { onTitle(value); } }} /> ) : type === "term" ? ( { if (typeof onArticleChange !== "undefined") { onArticleChange(type, id, target); } }} /> ) : type === "chapter" || type === "para" ? ( { if (typeof onArticleChange !== "undefined") { onArticleChange(type, id, target, param); } }} onLoad={(data: IArticleDataResponse) => { if (typeof onLoad !== "undefined") { onLoad(data); } }} onTitle={(value: string) => { if (typeof onTitle !== "undefined") { onTitle(value); } }} /> ) : type === "series" ? ( { if (typeof onArticleChange !== "undefined") { onArticleChange(type, id, target, param); } }} /> ) : type === "page" ? ( { if (typeof onArticleChange !== "undefined") { onArticleChange(type, id, target); } else { if (target === "_blank") { let url = `/article/page/${id}?mode=${mode}`; if (channelId) { url += `&channel=${channelId}`; } window.open(fullUrl(url), "_blank"); } else { setCurrId(id); } } }} /> ) : type === "cs-para" ? ( { if (typeof onArticleChange !== "undefined") { onArticleChange(type, id, target); } }} /> ) : type === "textbook" ? ( ) : type === "task" ? ( ) : ( <> )}
); }; export default ArticleWidget;