Environment bugfixes

This commit is contained in:
Rainer Simon 2020-09-22 11:52:19 +02:00
parent 9d9b309eb9
commit 0898639db5
3 changed files with 8 additions and 9 deletions

View File

@ -1,6 +1,5 @@
import React from 'preact/compat'; import React from 'preact/compat';
import { useState, useRef, useEffect } from 'preact/hooks'; import { useState, useRef, useEffect } from 'preact/hooks';
import Environment from '../Environment';
import { getWidget, DEFAULT_WIDGETS } from './widgets'; import { getWidget, DEFAULT_WIDGETS } from './widgets';
import setPosition from './setPosition'; import setPosition from './setPosition';
import i18n from '../i18n'; import i18n from '../i18n';
@ -19,7 +18,7 @@ const bounds = elem => {
* with CTRL+Z. * with CTRL+Z.
*/ */
const Editor = props => { const Editor = props => {
// The current state of the edited annotation vs. original // The current state of the edited annotation vs. original
const [ currentAnnotation, setCurrentAnnotation ] = useState(); const [ currentAnnotation, setCurrentAnnotation ] = useState();
@ -75,7 +74,7 @@ const Editor = props => {
const creationMeta = body => { const creationMeta = body => {
const meta = {}; const meta = {};
const { user } = Environment; const { user } = props.env;
// Metadata is only added when a user is set, otherwise // Metadata is only added when a user is set, otherwise
// the Editor operates in 'anonymous mode'. Also, // the Editor operates in 'anonymous mode'. Also,
@ -86,9 +85,9 @@ const Editor = props => {
if (user.displayName) meta.creator.name = user.displayName; if (user.displayName) meta.creator.name = user.displayName;
if (body.created) if (body.created)
body.modified = Environment.getCurrentTimeAdjusted(); body.modified = props.env.getCurrentTimeAdjusted();
else else
body.created = Environment.getCurrentTimeAdjusted(); body.created = props.env.getCurrentTimeAdjusted();
} }
return meta; return meta;
@ -152,6 +151,7 @@ const Editor = props => {
annotation : currentAnnotation, annotation : currentAnnotation,
readOnly : props.readOnly, readOnly : props.readOnly,
config: props.config, config: props.config,
env: props.env,
onAppendBody, onAppendBody,
onUpdateBody, onUpdateBody,
onRemoveBody, onRemoveBody,

View File

@ -4,7 +4,6 @@ import TimeAgo from 'timeago-react';
import DropdownMenu from './DropdownMenu'; import DropdownMenu from './DropdownMenu';
import TextEntryField from './TextEntryField'; import TextEntryField from './TextEntryField';
import { ChevronDownIcon } from '../../../Icons'; import { ChevronDownIcon } from '../../../Icons';
import Environment from '../../../Environment';
/** A single comment inside the CommentWidget **/ /** A single comment inside the CommentWidget **/
const Comment = props => { const Comment = props => {
@ -32,7 +31,7 @@ const Comment = props => {
<span className="lastmodified-by">{props.body.creator.name || props.body.creator.id}</span> <span className="lastmodified-by">{props.body.creator.name || props.body.creator.id}</span>
{ props.body.created && { props.body.created &&
<span className="lastmodified-at"> <span className="lastmodified-at">
<TimeAgo datetime={Environment.toClientTime(props.body.created)} /> <TimeAgo datetime={props.env.toClientTime(props.body.created)} />
</span> </span>
} }
</div> </div>

View File

@ -2,7 +2,6 @@ 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 Environment from '../../../Environment';
/** /**
* Comments are TextualBodies where the purpose field is either * Comments are TextualBodies where the purpose field is either
@ -66,7 +65,7 @@ const CommentWidget = props => {
const creator = body.creator?.id; const creator = body.creator?.id;
// The current user // The current user
const me = Environment.user?.id; const me = props.env.user?.id;
return me !== creator; return me !== creator;
} }
@ -80,6 +79,7 @@ const CommentWidget = props => {
{ comments.map((body, idx) => { comments.map((body, idx) =>
<Comment <Comment
key={idx} key={idx}
env={props.env}
readOnly={isReadOnly(body)} readOnly={isReadOnly(body)}
body={body} body={body}
onUpdate={props.onUpdateBody} onUpdate={props.onUpdateBody}