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

View File

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

View File

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