From 8fd891bae757f0377c4dc7a223d18c870f20492f Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Mon, 3 Apr 2023 16:13:53 +0800 Subject: [PATCH] Start to add a new modal for notes --- .../components/patterns/HighlightNotes.tsx | 115 ++++++++++++++++++ .../web/components/patterns/HighlightView.tsx | 2 +- .../templates/article/HighlightViewItem.tsx | 2 +- .../templates/article/HighlightsLayer.tsx | 1 + .../components/templates/article/Notebook.tsx | 2 +- .../templates/article/NotebookModal.tsx | 4 +- 6 files changed, 122 insertions(+), 4 deletions(-) diff --git a/packages/web/components/patterns/HighlightNotes.tsx b/packages/web/components/patterns/HighlightNotes.tsx index febd0979e..3ccf0f647 100644 --- a/packages/web/components/patterns/HighlightNotes.tsx +++ b/packages/web/components/patterns/HighlightNotes.tsx @@ -18,6 +18,13 @@ import throttle from 'lodash/throttle' import { updateHighlightMutation } from '../../lib/networking/mutations/updateHighlightMutation' import { Highlight } from '../../lib/networking/fragments/highlightFragment' import { Button } from '../elements/Button' +import { + ModalContent, + ModalOverlay, + ModalRoot, +} from '../elements/ModalPrimitives' +import { CloseButton } from '../elements/CloseButton' +import { StyledText } from '../elements/StyledText' const mdParser = new MarkdownIt() @@ -326,3 +333,111 @@ export function MarkdownNote(props: MarkdownNote): JSX.Element { ) } + +type MarkdownModalProps = { + placeHolder: string + mode: 'edit' | 'preview' + + sizeMode: 'normal' | 'maximized' + setEditMode: (set: 'edit' | 'preview') => void + + text: string | undefined + saveText: (text: string, completed: (success: boolean) => void) => void +} + +export function MarkdownModal(props: MarkdownModalProps): JSX.Element { + const [lastSaved, setLastSaved] = useState(undefined) + + const saveText = useCallback( + (text, updateTime) => { + props.saveText(text, (success) => { + if (success) { + setLastSaved(updateTime) + } + }) + }, + [props] + ) + + const handleClose = useCallback(() => { + console.log('onOpenChange') + }, []) + + return ( + + + + + + + Edit Note + + + {/* }> + { + exportHighlights() + }} + title="Export Notebook" + /> + { + setShowConfirmDeleteNote(true) + }} + title="Delete Document Note" + /> + */} + + + + + + + + + + ) +} diff --git a/packages/web/components/patterns/HighlightView.tsx b/packages/web/components/patterns/HighlightView.tsx index 79e295bf9..c85f47e4d 100644 --- a/packages/web/components/patterns/HighlightView.tsx +++ b/packages/web/components/patterns/HighlightView.tsx @@ -11,7 +11,7 @@ import { HStack, } from '../elements/LayoutPrimitives' import { styled } from '../tokens/stitches.config' -import { HighlightViewNote } from './HighlightNotes' +import { HighlightViewNote, MarkdownModal } from './HighlightNotes' import ReactMarkdown from 'react-markdown' type HighlightViewProps = { diff --git a/packages/web/components/templates/article/HighlightViewItem.tsx b/packages/web/components/templates/article/HighlightViewItem.tsx index 1fff15ce5..5b9effade 100644 --- a/packages/web/components/templates/article/HighlightViewItem.tsx +++ b/packages/web/components/templates/article/HighlightViewItem.tsx @@ -29,7 +29,7 @@ export function HighlightViewItem(props: HighlightViewItemProps): JSX.Element { return ( setHover(true)} onMouseLeave={() => setHover(false)} > diff --git a/packages/web/components/templates/article/HighlightsLayer.tsx b/packages/web/components/templates/article/HighlightsLayer.tsx index 1220c8793..9ede4f3c3 100644 --- a/packages/web/components/templates/article/HighlightsLayer.tsx +++ b/packages/web/components/templates/article/HighlightsLayer.tsx @@ -29,6 +29,7 @@ import { Label } from '../../../lib/networking/fragments/labelFragment' import { UserBasicData } from '../../../lib/networking/queries/useGetViewerQuery' import { ReadableItem } from '../../../lib/networking/queries/useGetLibraryItemsQuery' import { useRouter } from 'next/router' +import { MarkdownModal } from '../../patterns/HighlightNotes' type HighlightsLayerProps = { viewer: UserBasicData diff --git a/packages/web/components/templates/article/Notebook.tsx b/packages/web/components/templates/article/Notebook.tsx index 1d852c8cf..37ee8a531 100644 --- a/packages/web/components/templates/article/Notebook.tsx +++ b/packages/web/components/templates/article/Notebook.tsx @@ -16,7 +16,7 @@ import { createHighlightMutation } from '../../../lib/networking/mutations/creat import { v4 as uuidv4 } from 'uuid' import { nanoid } from 'nanoid' import { deleteHighlightMutation } from '../../../lib/networking/mutations/deleteHighlightMutation' -import { HighlightNoteBox } from '../../patterns/HighlightNotes' +import { HighlightNoteBox, MarkdownNote } from '../../patterns/HighlightNotes' import { HighlightViewItem } from './HighlightViewItem' import { ConfirmationModal } from '../../patterns/ConfirmationModal' import { TrashIcon } from '../../elements/images/TrashIcon' diff --git a/packages/web/components/templates/article/NotebookModal.tsx b/packages/web/components/templates/article/NotebookModal.tsx index 249b3001a..f7a272689 100644 --- a/packages/web/components/templates/article/NotebookModal.tsx +++ b/packages/web/components/templates/article/NotebookModal.tsx @@ -3,7 +3,7 @@ import { ModalOverlay, ModalContent, } from '../../elements/ModalPrimitives' -import { HStack } from '../../elements/LayoutPrimitives' +import { HStack, SpanBox } from '../../elements/LayoutPrimitives' import { Button } from '../../elements/Button' import { StyledText } from '../../elements/StyledText' import { theme } from '../../tokens/stitches.config' @@ -19,6 +19,7 @@ import 'react-markdown-editor-lite/lib/index.css' import { Notebook } from './Notebook' import { UserBasicData } from '../../../lib/networking/queries/useGetViewerQuery' import { ReadableItem } from '../../../lib/networking/queries/useGetLibraryItemsQuery' +import { MarkdownNote } from '../../patterns/HighlightNotes' type NotebookModalProps = { viewer: UserBasicData @@ -183,6 +184,7 @@ function CloseButton(props: { close: () => void }): JSX.Element { ) } + function SizeToggle(props: SizeToggleProps): JSX.Element { return (