From 424860bfc319621a7ea9987f70d2bef06b4211e3 Mon Sep 17 00:00:00 2001 From: Niqui O'Neill Date: Mon, 16 Nov 2020 14:07:14 -0500 Subject: [PATCH] stash changes --- src/editor/Editor.jsx | 4 +- src/editor/widgets/comment/Comment.jsx | 24 ++++++----- src/editor/widgets/comment/CommentWidget.jsx | 7 +++- src/editor/widgets/comment/TypeDropdown.jsx | 42 +++++++++++--------- 4 files changed, 46 insertions(+), 31 deletions(-) diff --git a/src/editor/Editor.jsx b/src/editor/Editor.jsx index e75bbb6..2644e8b 100644 --- a/src/editor/Editor.jsx +++ b/src/editor/Editor.jsx @@ -117,7 +117,8 @@ const Editor = props => { const onOk = _ => { // Removes the 'draft' flag from all bodies - const undraft = annotation => annotation.clone({ + const undraft = annotation => + annotation.clone({ body : annotation.bodies.map(({ draft, ...rest }) => draft ? { ...rest, ...creationMeta(rest) } : rest ) }); @@ -141,7 +142,6 @@ const Editor = props => { // Use default comment + tag widget unless host app overrides const widgets = props.config.widgets ? props.config.widgets.map(getWidget) : DEFAULT_WIDGETS; - return (
diff --git a/src/editor/widgets/comment/Comment.jsx b/src/editor/widgets/comment/Comment.jsx index 3ad5886..8ecbbc7 100644 --- a/src/editor/widgets/comment/Comment.jsx +++ b/src/editor/widgets/comment/Comment.jsx @@ -24,11 +24,17 @@ const Comment = props => { props.onDelete(props.body); setIsMenuVisible(false); } - const onUpdateComment = evt => { props.onUpdate(props.body, { ...props.body, value: evt.target.value }); } + const onUpdateDropdown = evt => { + console.log('update dropdown') + console.log(evt) + console.log(props.body) + props.onUpdate(props.body, { ...props.body, purpose: evt.target.value }); + } + const creatorInfo = props.body.creator &&
{props.body.creator.name || props.body.creator.id} @@ -53,15 +59,13 @@ const Comment = props => { onChange={onUpdateComment} onSaveAndClose={props.onSaveAndClose} /> - - - { creatorInfo } - + { props.purpose == true && + }
setIsMenuVisible(!isMenuVisible)}> diff --git a/src/editor/widgets/comment/CommentWidget.jsx b/src/editor/widgets/comment/CommentWidget.jsx index 6f34878..60e7569 100644 --- a/src/editor/widgets/comment/CommentWidget.jsx +++ b/src/editor/widgets/comment/CommentWidget.jsx @@ -2,8 +2,9 @@ import React from 'preact/compat'; import Comment from './Comment'; import TextEntryField from './TextEntryField'; import i18n from '../../../i18n'; +import TypeDropdown from './TypeDropdown'; + const purposes = ['assessing', 'bookmarking', 'classifying', 'commenting', 'describing', 'editing', 'highlighting', 'identifying', 'linking', 'moderating', 'questioning'] -console.log(purposes) /** * Comments are TextualBodies where the purpose field is either * blank or 'commenting' or 'replying' @@ -28,10 +29,12 @@ const getDraftReply = (existingDraft, isReply) => { */ const CommentWidget = props => { // All comments (draft + non-draft) + console.log(props.annotation) const all = props.annotation ? props.annotation.bodies.filter(isComment) : []; // Last draft comment without a creator field goes into the reply field + console.log(all) const draftReply = getDraftReply(all.slice().reverse().find(b => b.draft && !b.creator), all.length > 1); // All except draft reply @@ -80,6 +83,7 @@ const CommentWidget = props => { { 0 ? i18n.t('Add a reply...') : i18n.t('Add a comment...')} onChange={onEditReply} onSaveAndClose={() => props.onSaveAndClose()} diff --git a/src/editor/widgets/comment/TypeDropdown.jsx b/src/editor/widgets/comment/TypeDropdown.jsx index bf030b0..551b05a 100644 --- a/src/editor/widgets/comment/TypeDropdown.jsx +++ b/src/editor/widgets/comment/TypeDropdown.jsx @@ -1,23 +1,29 @@ -import React from 'preact/compat'; -import { useRef } from 'preact/hooks'; -import useClickOutside from '../../useClickOutside'; +import React, { Component } from 'preact/compat'; +import ContentEditable from 'react-contenteditable'; import i18n from '../../../i18n'; + const purposes = ['assessing', 'bookmarking', 'classifying', 'commenting', 'describing', 'editing', 'highlighting', 'identifying', 'linking', 'moderating', 'questioning'] -const DropdownMenu = props => { - const ref = useRef(); - // Custom hook that notifies when clicked outside this component - useClickOutside(ref, () => props.onClickOutside()); - return ( - - ) +export default class TypeDropdown extends Component { -} + // CTRL+Enter functions as Ok + onKeyDown = evt => { + if (evt.which === 13 && evt.ctrlKey) + this.props.onSaveAndClose(); + } -export default DropdownMenu; \ No newline at end of file + render() { + return ( +
+
{this.props.content}
+ +
+ ) + } +} \ No newline at end of file