Skip to content

Commit

Permalink
Take into account the current user for message displaying (#61)
Browse files Browse the repository at this point in the history
* Take into account the current user for message displaying

* Review comment

* Linter
  • Loading branch information
martinRenou authored Dec 15, 2022
1 parent 82d32f1 commit 61ebb96
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
17 changes: 14 additions & 3 deletions src/annotation/message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,32 @@ import { User } from '@jupyterlab/services';
import * as React from 'react';

interface IProps {
/*
* The message content.
**/
message: string;
index: number;

/*
* Whether the message was originated from the current user.
**/
self: boolean;

/*
* The user who originated the message.
**/
user?: User.IIdentity;
}

export const Message = (props: IProps): JSX.Element => {
const { index, message, user } = props;
const { self, message, user } = props;
const color = user?.color ?? 'black';
const author = user?.display_name ?? '';
const initials = user?.initials ?? '';
return (
<div
className="jcad-Annotation-Message"
style={{
flexFlow: index % 2 === 0 ? 'row' : 'row-reverse'
flexFlow: self ? 'row' : 'row-reverse'
}}
>
<div
Expand Down
6 changes: 6 additions & 0 deletions src/annotation/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface IAnnotation {
position: [number, number, number];
contents: IAnnotationContent[];
}

export class AnnotationModel {
constructor(options: AnnotationModel.IOptions) {
this._getCoordinate = options.getCoordinate;
Expand All @@ -25,9 +26,14 @@ export class AnnotationModel {
return this._updateSignal;
}

get user(): User.IIdentity | undefined {
return this._user;
}

update(): void {
this._updateSignal.emit(null);
}

getAnnotation(id: string): IAnnotation | undefined {
const rawData = this._sharedModel.metadata.get(id);
if (rawData) {
Expand Down
4 changes: 2 additions & 2 deletions src/annotation/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ export const Annotation = (props: IProps): JSX.Element => {
}}
/>
<div style={{ paddingBottom: 10, maxHeight: 400, overflow: 'auto' }}>
{contents.map((content, index) => {
{contents.map(content => {
return (
<Message
user={content.user}
message={content.value}
index={index}
self={model.user?.username === content.user?.username}
/>
);
})}
Expand Down

0 comments on commit 61ebb96

Please sign in to comment.