import { ModalRoot, ModalOverlay, ModalContent, } from '../../elements/ModalPrimitives' import { HStack } from '../../elements/LayoutPrimitives' import { Button } from '../../elements/Button' import { StyledText } from '../../elements/StyledText' import { theme } from '../../tokens/stitches.config' import type { Highlight } from '../../../lib/networking/fragments/highlightFragment' import { useCallback, useState } from 'react' import { ArrowsIn, ArrowsOut, X } from 'phosphor-react' import { Dropdown, DropdownOption } from '../../elements/DropdownElements' import { showErrorToast, showSuccessToast } from '../../../lib/toastHelpers' import { diff_match_patch } from 'diff-match-patch' import { MenuTrigger } from '../../elements/MenuTrigger' import { highlightsAsMarkdown } from '../homeFeed/HighlightItem' import 'react-markdown-editor-lite/lib/index.css' import { NotebookContent } from './Notebook' import { UserBasicData } from '../../../lib/networking/queries/useGetViewerQuery' import { ReadableItem } from '../../../lib/networking/queries/useGetLibraryItemsQuery' type NotebookModalProps = { viewer: UserBasicData item: ReadableItem viewHighlightInReader: (arg: string) => void onClose: (highlights: Highlight[], deletedHighlights: Highlight[]) => void } export const getHighlightLocation = (patch: string): number | undefined => { const dmp = new diff_match_patch() const patches = dmp.patch_fromText(patch) return patches[0].start1 || undefined } export function NotebookModal(props: NotebookModalProps): JSX.Element { const [showConfirmDeleteNote, setShowConfirmDeleteNote] = useState(false) const [allAnnotations, setAllAnnotations] = useState( undefined ) const [deletedHighlights, setDeletedAnnotations] = useState< Highlight[] | undefined >(undefined) const handleClose = useCallback(() => { props.onClose(allAnnotations ?? [], deletedHighlights ?? []) }, [props, allAnnotations]) const handleAnnotationsChange = useCallback((allAnnotations) => { setAllAnnotations(allAnnotations) }, []) const exportHighlights = useCallback(() => { ;(async () => { if (!allAnnotations) { showErrorToast('No highlights to export') return } const markdown = highlightsAsMarkdown(allAnnotations) await navigator.clipboard.writeText(markdown) showSuccessToast('Highlight copied') })() }, [allAnnotations]) const viewInReader = useCallback( (highlightId) => { props.viewHighlightInReader(highlightId) handleClose() }, [props, handleClose] ) return ( { event.preventDefault() }} css={{ overflow: 'auto', bg: '$thLibraryBackground', width: '100%', height: 'unset', maxWidth: '748px', minHeight: '525px', '@mdDown': { top: '20px', width: '100%', height: '100%', maxHeight: 'unset', transform: 'translate(-50%)', }, }} onKeyUp={(event) => { switch (event.key) { case 'Escape': handleClose() event.preventDefault() event.stopPropagation() break } }} > Notebook }> { exportHighlights() }} title="Export Notebook" /> { setShowConfirmDeleteNote(true) }} title="Delete Article Note" /> ) } type SizeToggleProps = { mode: 'normal' | 'maximized' setMode: (mode: 'normal' | 'maximized') => void } function CloseButton(props: { close: () => void }): JSX.Element { return ( ) }