stash changes

This commit is contained in:
Niqui O'Neill 2020-11-16 14:07:14 -05:00
parent 522054590e
commit 424860bfc3
4 changed files with 46 additions and 31 deletions

View File

@ -117,7 +117,8 @@ const Editor = props => {
const onOk = _ => { const onOk = _ => {
// Removes the 'draft' flag from all bodies // Removes the 'draft' flag from all bodies
const undraft = annotation => annotation.clone({ const undraft = annotation =>
annotation.clone({
body : annotation.bodies.map(({ draft, ...rest }) => body : annotation.bodies.map(({ draft, ...rest }) =>
draft ? { ...rest, ...creationMeta(rest) } : rest ) draft ? { ...rest, ...creationMeta(rest) } : rest )
}); });
@ -141,7 +142,6 @@ const Editor = props => {
// Use default comment + tag widget unless host app overrides // Use default comment + tag widget unless host app overrides
const widgets = props.config.widgets ? const widgets = props.config.widgets ?
props.config.widgets.map(getWidget) : DEFAULT_WIDGETS; props.config.widgets.map(getWidget) : DEFAULT_WIDGETS;
return ( return (
<div ref={element} className="r6o-editor"> <div ref={element} className="r6o-editor">
<div className="r6o-arrow" /> <div className="r6o-arrow" />

View File

@ -24,11 +24,17 @@ const Comment = props => {
props.onDelete(props.body); props.onDelete(props.body);
setIsMenuVisible(false); setIsMenuVisible(false);
} }
const onUpdateComment = evt => { const onUpdateComment = evt => {
props.onUpdate(props.body, { ...props.body, value: evt.target.value }); 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 && const creatorInfo = props.body.creator &&
<div className="r6o-lastmodified"> <div className="r6o-lastmodified">
<span className="r6o-lastmodified-by">{props.body.creator.name || props.body.creator.id}</span> <span className="r6o-lastmodified-by">{props.body.creator.name || props.body.creator.id}</span>
@ -53,15 +59,13 @@ const Comment = props => {
onChange={onUpdateComment} onChange={onUpdateComment}
onSaveAndClose={props.onSaveAndClose} onSaveAndClose={props.onSaveAndClose}
/> />
{ props.purpose == true &&
<TypeDropdown <TypeDropdown
editable={isEditable} editable={isEditable}
content={props.body.purpose} content={props.body.purpose}
onChange={onUpdateComment} onChange={onUpdateDropdown}
onSaveAndClose={props.onSaveAndClose} onSaveAndClose={props.onSaveAndClose}
/> /> }
{ creatorInfo }
<div <div
className={isMenuVisible ? "r6o-icon r6o-arrow-down r6o-menu-open" : "r6o-icon r6o-arrow-down"} className={isMenuVisible ? "r6o-icon r6o-arrow-down r6o-menu-open" : "r6o-icon r6o-arrow-down"}
onClick={() => setIsMenuVisible(!isMenuVisible)}> onClick={() => setIsMenuVisible(!isMenuVisible)}>

View File

@ -2,8 +2,9 @@ import React from 'preact/compat';
import Comment from './Comment'; import Comment from './Comment';
import TextEntryField from './TextEntryField'; import TextEntryField from './TextEntryField';
import i18n from '../../../i18n'; import i18n from '../../../i18n';
import TypeDropdown from './TypeDropdown';
const purposes = ['assessing', 'bookmarking', 'classifying', 'commenting', 'describing', 'editing', 'highlighting', 'identifying', 'linking', 'moderating', 'questioning'] 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 * Comments are TextualBodies where the purpose field is either
* blank or 'commenting' or 'replying' * blank or 'commenting' or 'replying'
@ -28,10 +29,12 @@ const getDraftReply = (existingDraft, isReply) => {
*/ */
const CommentWidget = props => { const CommentWidget = props => {
// All comments (draft + non-draft) // All comments (draft + non-draft)
console.log(props.annotation)
const all = props.annotation ? const all = props.annotation ?
props.annotation.bodies.filter(isComment) : []; props.annotation.bodies.filter(isComment) : [];
// Last draft comment without a creator field goes into the reply field // 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); const draftReply = getDraftReply(all.slice().reverse().find(b => b.draft && !b.creator), all.length > 1);
// All except draft reply // All except draft reply
@ -80,6 +83,7 @@ const CommentWidget = props => {
<Comment <Comment
key={idx} key={idx}
env={props.env} env={props.env}
purpose={props.purpose}
readOnly={isReadOnly(body)} readOnly={isReadOnly(body)}
body={body} body={body}
onUpdate={props.onUpdateBody} onUpdate={props.onUpdateBody}
@ -92,6 +96,7 @@ const CommentWidget = props => {
<TextEntryField <TextEntryField
content={draftReply.value} content={draftReply.value}
editable={true} editable={true}
purpose={props.purpose}
placeholder={comments.length > 0 ? i18n.t('Add a reply...') : i18n.t('Add a comment...')} placeholder={comments.length > 0 ? i18n.t('Add a reply...') : i18n.t('Add a comment...')}
onChange={onEditReply} onChange={onEditReply}
onSaveAndClose={() => props.onSaveAndClose()} onSaveAndClose={() => props.onSaveAndClose()}

View File

@ -1,23 +1,29 @@
import React from 'preact/compat'; import React, { Component } from 'preact/compat';
import { useRef } from 'preact/hooks'; import ContentEditable from 'react-contenteditable';
import useClickOutside from '../../useClickOutside';
import i18n from '../../../i18n'; import i18n from '../../../i18n';
const purposes = ['assessing', 'bookmarking', 'classifying', 'commenting', 'describing', 'editing', 'highlighting', 'identifying', 'linking', 'moderating', 'questioning'] const purposes = ['assessing', 'bookmarking', 'classifying', 'commenting', 'describing', 'editing', 'highlighting', 'identifying', 'linking', 'moderating', 'questioning']
const DropdownMenu = props => { export default class TypeDropdown extends Component {
const ref = useRef();
// Custom hook that notifies when clicked outside this component
useClickOutside(ref, () => props.onClickOutside());
return (
<select name="purpose" id="purpose">
{purposes.map(purpose => (
<option value={purpose} selected={purpose == props.content}>
{purpose}
</option>
))}
</select>
)
// CTRL+Enter functions as Ok
onKeyDown = evt => {
if (evt.which === 13 && evt.ctrlKey)
this.props.onSaveAndClose();
}
render() {
return (
<div>
<div>{this.props.content}</div>
<select name="purpose" id="purpose" disabled={this.props.editable ? false : true }>
{purposes.map(purpose => (
<option value={purpose} selected={purpose == this.props.content}>
{purpose}
</option>
))}
</select>
</div>
)
}
} }
export default DropdownMenu;