diff --git a/packages/web/components/patterns/HighlightNotes.tsx b/packages/web/components/patterns/HighlightNotes.tsx index e5a78f425..be51b17b8 100644 --- a/packages/web/components/patterns/HighlightNotes.tsx +++ b/packages/web/components/patterns/HighlightNotes.tsx @@ -17,6 +17,7 @@ import ReactMarkdown from 'react-markdown' import throttle from 'lodash/throttle' import { updateHighlightMutation } from '../../lib/networking/mutations/updateHighlightMutation' import { Highlight } from '../../lib/networking/fragments/highlightFragment' +import { Button } from '../elements/Button' const mdParser = new MarkdownIt() @@ -118,6 +119,7 @@ type MarkdownNote = { } export function MarkdownNote(props: MarkdownNote): JSX.Element { + const editorRef = useRef(null) const [lastChanged, setLastChanged] = useState(undefined) const [errorSaving, setErrorSaving] = useState(undefined) @@ -183,6 +185,7 @@ export function MarkdownNote(props: MarkdownNote): JSX.Element { }} > ) : null} - - Save - + {lastChanged !== props.lastSaved && ( + + + + )} ) : ( diff --git a/packages/web/components/patterns/HighlightView.tsx b/packages/web/components/patterns/HighlightView.tsx index 6fea3acc7..385da5ffd 100644 --- a/packages/web/components/patterns/HighlightView.tsx +++ b/packages/web/components/patterns/HighlightView.tsx @@ -1,3 +1,4 @@ +import { BookOpen, PencilLine } from 'phosphor-react' import { Fragment, useMemo, useState } from 'react' import type { Highlight } from '../../lib/networking/fragments/highlightFragment' import { LabelChip } from '../elements/LabelChip' @@ -63,7 +64,7 @@ export function HighlightView(props: HighlightViewProps): JSX.Element { }} /> - + { if (props.scrollToHighlight) { @@ -95,15 +96,43 @@ export function HighlightView(props: HighlightViewProps): JSX.Element { ))} - + + + { + setNoteMode(noteMode == 'preview' ? 'edit' : 'preview') + event.preventDefault() + }} + > + {noteMode === 'edit' ? ( + + ) : ( + + )} + + ) diff --git a/packages/web/components/templates/article/NotebookModal.tsx b/packages/web/components/templates/article/NotebookModal.tsx index 6cc35eed1..5a5d1ef92 100644 --- a/packages/web/components/templates/article/NotebookModal.tsx +++ b/packages/web/components/templates/article/NotebookModal.tsx @@ -29,6 +29,7 @@ import { nanoid } from 'nanoid' import { deleteHighlightMutation } from '../../../lib/networking/mutations/deleteHighlightMutation' import { HighlightNoteBox } from '../../patterns/HighlightNotes' import { HighlightViewItem } from './HighlightViewItem' +import { Notebook } from './Notebook' type NotebookModalProps = { pageId: string @@ -351,196 +352,12 @@ export function NotebookModal(props: NotebookModalProps): JSX.Element { - - setNotesEditMode(edit ? 'edit' : 'preview')} - /> - - - {/* {annotations.allAnnotations.map((highlight) => ( - - {highlight.annotation} - - - ))} */} - - - - {sortedHighlights.map((highlight) => ( - { - dispatchAnnotations({ - type: 'DELETE_HIGHLIGHT', - deleteHighlightId: highlight.id, - }) - }} - updateHighlight={() => { - dispatchAnnotations({ - type: 'UPDATE_HIGHLIGHT', - updateHighlight: highlight, - }) - }} - /> - ))} - {sortedHighlights.length === 0 && ( - - You have not added any highlights to this document. - - )} - - + - {showConfirmDeleteHighlightId && ( - { - ;(async () => { - const success = await deleteHighlightMutation( - showConfirmDeleteHighlightId - ) - if (success) { - dispatchAnnotations({ - type: 'DELETE_HIGHLIGHT', - deleteHighlightId: showConfirmDeleteHighlightId, - }) - showSuccessToast('Highlight deleted.') - } else { - showErrorToast('Error deleting highlight') - } - })() - setShowConfirmDeleteHighlightId(undefined) - }} - onOpenChange={() => setShowConfirmDeleteHighlightId(undefined)} - icon={ - - } - /> - )} - {labelsTarget && ( - { - const result = setLabelsForHighlight( - labelsTarget.id, - labels.map((label) => label.id) - ) - return result - }} - /> - )} - {showConfirmDeleteNote && ( - { - deleteDocumentNote() - setShowConfirmDeleteNote(false) - }} - onOpenChange={() => setShowConfirmDeleteNote(false)} - /> - )} ) } -type TitledSectionProps = { - title: string - editMode?: boolean - setEditMode?: (set: boolean) => void -} - -function TitledSection(props: TitledSectionProps): JSX.Element { - return ( - <> - - - {props.title} - - {props.setEditMode && ( - { - if (props.setEditMode) { - props.setEditMode(!props.editMode) - } - event.preventDefault() - }} - > - {props.editMode ? ( - - ) : ( - - )} - - )} - - - - ) -} - type SizeToggleProps = { mode: 'normal' | 'maximized' setMode: (mode: 'normal' | 'maximized') => void diff --git a/packages/web/components/templates/homeFeed/HighlightsLayout.tsx b/packages/web/components/templates/homeFeed/HighlightsLayout.tsx index 99a9f7ea1..6e95867c9 100644 --- a/packages/web/components/templates/homeFeed/HighlightsLayout.tsx +++ b/packages/web/components/templates/homeFeed/HighlightsLayout.tsx @@ -21,6 +21,7 @@ import { } from '../../patterns/LibraryCards/LibraryCardStyles' import { LibraryHighlightGridCard } from '../../patterns/LibraryCards/LibraryHighlightGridCard' import { HighlightViewItem } from '../article/HighlightViewItem' +import { Notebook } from '../article/Notebook' import { EmptyHighlights } from './EmptyHighlights' import { HEADER_HEIGHT, MOBILE_HEADER_HEIGHT } from './HeaderSpacer' import { highlightsAsMarkdown } from './HighlightItem' @@ -188,28 +189,19 @@ export function HighlightItemsLayout( height: '100%', width: '100%', flexGrow: '1', + justifyContent: 'center', + overflowY: 'scroll', '@lgDown': { display: 'none', flexGrow: 'unset', }, }} > - - - + )} @@ -369,9 +361,6 @@ type HighlightListProps = { } function HighlightList(props: HighlightListProps): JSX.Element { - const [notesEditMode, setNotesEditMode] = useState<'preview' | 'edit'>( - 'preview' - ) const exportHighlights = useCallback(() => { ;(async () => { if (!props.item.node.highlights) { @@ -384,149 +373,201 @@ function HighlightList(props: HighlightListProps): JSX.Element { })() }, [props.item.node.highlights]) - const note = useMemo(() => { - const note = (props.item.node.highlights ?? []).find( - (h) => h.type === 'NOTE' - ) - console.log('NOTE: ', note) - return note - }, [props.item]) - - const sortedHighlights = useMemo(() => { - return (props.item.node.highlights ?? []).filter( - (h) => h.type === 'HIGHLIGHT' - ) - }, [props.item]) - return ( - - - - + }> + { + exportHighlights() }} - > - NOTEBOOK - - }> - { - exportHighlights() - }} - title="Export" - /> - - - - - - NOTE - - - { - console.log('saving text', highlight) + title="Export" + /> + + + + { + console.log('closing notebook: ', highlights, deletedAnnotations) }} /> - - - {sortedHighlights && ( - <> - - - HIGHLIGHTS - - - - {sortedHighlights.map((highlight) => ( - <> - { - console.log('updated highlight: ', highlight) - }} - /> - - - ))} - - - - - )} - - + + ) + + // return ( + // + // + // + // + // NOTEBOOK + // + // }> + // { + // exportHighlights() + // }} + // title="Export" + // /> + // + // + + // + // + // NOTE + // + // + // { + // console.log('saving text', highlight) + // }} + // /> + // + + // {sortedHighlights && ( + // <> + // + // + // HIGHLIGHTS + // + // + // + // {sortedHighlights.map((highlight) => ( + // <> + // { + // console.log('updated highlight: ', highlight) + // }} + + // deleteHighlightAction={(highlight) => { + // console.log('deleting: ', highlight) + // }} + + // setSetLabelsTarget: (highlight: Highlight) => void + // setShowConfirmDeleteHighlightId: (id: string | undefined) => void + + // /> + // + // + // ))} + // + // + // + // + // )} + // + // + // ) } type HighlightCountChipProps = {