import { memo, useEffect, useMemo } from "react"; import { Button, Classes } from "@blueprintjs/core"; import AuxiliaryDialog from "Components/AuxiliaryDialog"; import CitekeyPopover from "Components/CitekeyPopover"; import { ErrorBoundary } from "Components/Errors"; import { useBool } from "@hooks"; import { sortElems } from "../helpers"; import { ShowPropertiesRelated, ShowTypeRelated } from "../types"; import { CustomClasses } from "../../../constants"; import { pluralize } from "../../../utils"; import { SCleanRelatedItem } from "Types/transforms"; import "./_index.sass"; const PANEL_LABEL_ID = "zr-related-panel-label"; type AbstractProps = { abstract: string, allAbstractsShown: boolean }; const Abstract = memo(function Abstract({ abstract, allAbstractsShown }) { const [isVisible, { set: setVisible, toggle: toggleAbstract }] = useBool(allAbstractsShown); useEffect(() => { setVisible(allAbstractsShown); }, [allAbstractsShown, setVisible]); if(!abstract){ return null; } else { return (
{isVisible ? {abstract} : null}
); } }); type TimestampProps = { timestamp: string, type: ShowTypeRelated }; const Timestamp = memo(function Timestamp({ timestamp, type }){ return type == "added_on" ? {timestamp} : null; }); type RelatedItemProps = { allAbstractsShown: boolean, closeDialog: () => void, item: SCleanRelatedItem, type: ShowTypeRelated }; const RelatedItem = memo(function RelatedItem(props) { const { allAbstractsShown, closeDialog, item, type } = props; const { children: { pdfs, notes }, raw } = item; return (
  • {item.title} {item.meta}
  • ); }); type RelatedListProps = { items: SCleanRelatedItem[] } & Omit; const RelatedList = memo(function RelatedList(props) { const { allAbstractsShown, closeDialog, items, type } = props; const sortedItems = useMemo(() => { const sort = type == ShowTypeRelated.ADDED_ON ? "added" : "meta"; return sortElems(items, sort); }, [items, type]); return (
      {sortedItems.map(it => ( ))}
    ); }); type RelatedPanelProps = { isOpen: boolean, items: SCleanRelatedItem[], onClose: () => void, show: ShowPropertiesRelated }; const RelatedPanel = memo(function RelatedPanel(props) { const { isOpen, items, onClose, show } = props; const [isShowingAllAbstracts, { toggle: toggleAbstracts }] = useBool(false); const relationship = useMemo(() => { const { title, type } = show; switch(type){ case ShowTypeRelated.ADDED_ON: return { string: "item", suffix: " added on " + title }; case ShowTypeRelated.WITH_ABSTRACT: return { string: "abstract", suffix: " containing " + title }; case ShowTypeRelated.WITH_TAG: default: return { string: "item", suffix: " tagged with " + title }; } }, [show]); const panelLabel = useMemo(() => { return
    {pluralize(items.length, relationship.string, relationship.suffix)}
    ; }, [items.length, relationship]); const headerRight = useMemo(() => { return (
    ); }, [onClose]); return (
    {panelLabel}
    {headerRight}
    ); }); export default RelatedPanel;