show.tsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { useNavigate, useParams, useSearchParams } from "react-router";
  2. import TypeArticle from "../../../components/article/TypeArticle";
  3. import SplitLayout from "../../../components/general/SplitLayout";
  4. import type { ArticleMode } from "../../../api/Article";
  5. import AnthologyTocTree from "../../../components/anthology/AnthologyTocTree";
  6. const Widget = () => {
  7. const { articleId, anthologyId } = useParams();
  8. const [searchParams] = useSearchParams();
  9. const navigate = useNavigate();
  10. const mode = searchParams.get("mode") ?? "read";
  11. const channelId = searchParams.get("channel");
  12. const anthology = searchParams.get("anthology");
  13. return (
  14. <SplitLayout
  15. key="mode-a"
  16. sidebarTitle="table of content"
  17. sidebar={
  18. anthologyId ? (
  19. <AnthologyTocTree
  20. anthologyId={anthologyId}
  21. channels={channelId ? channelId.split("_") : undefined}
  22. onClick={(anthology, article, target) => {
  23. if (target && target === "_blank") {
  24. window.open(
  25. `${window.location.origin}${import.meta.env.BASE_URL}workspace/anthology/${anthology}/${article}`,
  26. "_blank"
  27. );
  28. } else {
  29. navigate(`/workspace/anthology/${anthology}/${article}`);
  30. }
  31. }}
  32. />
  33. ) : (
  34. <></>
  35. )
  36. }
  37. >
  38. {({ expandButton }) => (
  39. <TypeArticle
  40. articleId={articleId}
  41. mode={mode as ArticleMode}
  42. anthologyId={anthologyId ?? anthology}
  43. channelId={channelId}
  44. headerExtra={expandButton}
  45. onAnthologySelect={(id) => {
  46. navigate(`/workspace/anthology/${id}/${articleId}`);
  47. }}
  48. onArticleChange={(type, id) => {
  49. if (anthologyId) {
  50. if (type === "article") {
  51. navigate(`/workspace/anthology/${anthologyId}/${id}`);
  52. } else {
  53. navigate(`/workspace/${type}/${id}`);
  54. }
  55. } else {
  56. navigate(`/workspace/${type}/${id}`);
  57. }
  58. }}
  59. />
  60. )}
  61. </SplitLayout>
  62. );
  63. };
  64. export default Widget;