| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- 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 (
- <div>
- <DiscussionCount courseId={type === "textbook" ? courseId : undefined} />
- {type === "article" ? (
- <TypeArticle
- isSubWindow={isSubWindow}
- type={type}
- articleId={onArticleChange ? articleId : currId}
- channelId={channelId}
- parentChannels={parentChannels}
- mode={mode}
- anthologyId={anthologyId}
- active={active}
- hideInteractive={hideInteractive}
- hideTitle={hideTitle}
- onArticleEdit={(value: IArticleDataResponse) => {
- 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" ? (
- <TypeAnthology
- type={type}
- articleId={onArticleChange ? articleId : currId}
- channelId={channelId}
- mode={mode}
- onArticleChange={(type: ArticleType, id: string, target: string) => {
- if (typeof onArticleChange !== "undefined") {
- onArticleChange(type, id, target);
- }
- }}
- onTitle={(value: string) => {
- if (typeof onTitle !== "undefined") {
- onTitle(value);
- }
- }}
- />
- ) : type === "term" ? (
- <TypeTerm
- articleId={onArticleChange ? articleId : currId}
- channelId={channelId}
- mode={mode}
- onArticleChange={(type: ArticleType, id: string, target: string) => {
- if (typeof onArticleChange !== "undefined") {
- onArticleChange(type, id, target);
- }
- }}
- />
- ) : type === "chapter" || type === "para" ? (
- <TypePali
- type={type}
- articleId={onArticleChange ? articleId : currId}
- channelId={channelId}
- mode={mode}
- book={book}
- para={para}
- focus={focus}
- onArticleChange={(
- type: ArticleType,
- id: string,
- target: string,
- param?: ISearchParams[]
- ) => {
- 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" ? (
- <TypeSeries
- articleId={onArticleChange ? articleId : currId}
- channelId={channelId}
- onArticleChange={(
- type: ArticleType,
- id: string,
- target: string,
- param: ISearchParams[]
- ) => {
- if (typeof onArticleChange !== "undefined") {
- onArticleChange(type, id, target, param);
- }
- }}
- />
- ) : type === "page" ? (
- <TypePage
- articleId={onArticleChange ? articleId : currId}
- channelId={channelId}
- focus={focus}
- mode={mode}
- onArticleChange={(type: ArticleType, id: string, target: string) => {
- 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" ? (
- <TypeCSPara
- articleId={onArticleChange ? articleId : currId}
- channelId={channelId}
- mode={mode}
- onArticleChange={(type: ArticleType, id: string, target: string) => {
- if (typeof onArticleChange !== "undefined") {
- onArticleChange(type, id, target);
- }
- }}
- />
- ) : type === "textbook" ? (
- <TypeCourse
- type={type}
- articleId={onArticleChange ? articleId : currId}
- channelId={channelId}
- courseId={courseId}
- mode={mode}
- onArticleChange={onArticleChange}
- />
- ) : type === "task" ? (
- <TypeTask articleId={articleId} />
- ) : (
- <></>
- )}
- </div>
- );
- };
- export default ArticleWidget;
|