From 7470e9fff72aa560d831785664591bf2ee05b41c Mon Sep 17 00:00:00 2001 From: Hoang <42971570+wardetu@users.noreply.github.com> Date: Sat, 22 Jun 2019 18:16:07 +0800 Subject: [PATCH 01/52] Create ChatApp.js --- src/components/chat/ChatApp.js | 87 ++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 src/components/chat/ChatApp.js diff --git a/src/components/chat/ChatApp.js b/src/components/chat/ChatApp.js new file mode 100644 index 0000000000..803ffdb042 --- /dev/null +++ b/src/components/chat/ChatApp.js @@ -0,0 +1,87 @@ +import * as React from 'react'; +import { ChatManager, TokenProvider } from '@pusher/chatkit-client'; +import MessageList from './MessageList'; +import Input from './Input'; + +export default class ChatApp extends React.Component { + constructor(props) { + super(props); + this.state = { + currentRoom: {}, + currentUser: {}, + messages: [] + }; + this.addMessage = this.addMessage.bind(this); + } + /* + To keep the chat view at its bottom (and also where the input field is) we create a dummy div at the bottom. + It will be automatically rendered and scrolled to everytime the chat is updated. + */ + messagesEndRef = React.createRef(); // for scrolling + + componentDidUpdate() { + this.scrollToBottom(); + } // for scrolling + + scrollToBottom = () => { + this.messagesEndRef.current.scrollIntoView({ behavior: 'smooth' }) + } + componentDidMount() { + // tslint:disable-next-line:no-console + /* + TO MOVE instanceLocator and tokenProvider to backend + + */ + const chatManager = new ChatManager({ + instanceLocator: 'v1:us1:6fac6431-d3f3-4a32-b4e6-56a20bf6e500', + tokenProvider: new TokenProvider({ + url: + 'https://us1.pusherplatform.io/services/chatkit_token_provider/v1/6fac6431-d3f3-4a32-b4e6-56a20bf6e500/token' + }), + userId: this.props.currentUserId + }); + + chatManager + .connect() + .then(currentUser => { + this.setState({ currentUser }); + return currentUser.subscribeToRoom({ + hooks: { + onMessage: message => { + this.setState({ + messages: [...this.state.messages, message] + }); + } + }, + messageLimit: 100, + roomId: this.props.currentRoomId + + }); + }) + .then(currentRoom => { + this.setState({ + currentRoom + }); + }); + this.scrollToBottom(); //for scrolling + } + + addMessage(text) { + this.state.currentUser.sendMessage({ + roomId: this.state.currentRoom.id, + text + }); + + } + + render() { + return ( + +
++{message.userStore.users[message.senderId].name}
++
Connected! Loading chat ...
+ } + +
+
+ Trying to connect to the chat service..
+
+ If this is taking too long, check your Internet connection and reload.
+
- Trying to connect to the chat service..
+ Trying to connect to the chat service ...
If this is taking too long, check your Internet connection and reload.
Connected! Loading chat ...
- } +
-
- Trying to connect to the chat service ...
-
+
+ Trying to connect to the chat service..
+
If this is taking too long, check your Internet connection and reload.
-
- Trying to connect to the chat service..
-
- If this is taking too long, check your Internet connection and reload.
-
+
+ Trying to connect to the chat service..
+
+ If this is taking too long, check your Internet connection and reload.
+
--{message.userStore.users[message.senderId].name}
--
++{message.userStore.users[message.senderId].name}
++
-{message.userStore.users[message.senderId].name}
+ + {message.userStore.users[message.senderId].name} + + {getPrettyDate(message.createdAt)} +
-
- Trying to connect to the chat service..
+
+ Connecting to ChatKit...
- If this is taking too long, check your Internet connection and reload.
-
+
- {message.userStore.users[message.senderId].name}
+ {message.userStore.users[message.senderId].name}
- {getPrettyDate(message.createdAt)}
+ {getPrettyDateChat(message.createdAt)}
From fd9b0094860b43d3f16f81a0fbb9028d063c022c Mon Sep 17 00:00:00 2001
From: Hoang <42971570+wardetu@users.noreply.github.com>
Date: Mon, 1 Jul 2019 23:16:14 +0700
Subject: [PATCH 22/52] Move styling to scss file
---
src/components/chat/Input.tsx | 24 ++++++++----------------
1 file changed, 8 insertions(+), 16 deletions(-)
diff --git a/src/components/chat/Input.tsx b/src/components/chat/Input.tsx
index a721438049..8a7f37bd08 100644
--- a/src/components/chat/Input.tsx
+++ b/src/components/chat/Input.tsx
@@ -27,29 +27,21 @@ class Input extends React.Component+- {message.userStore.users[message.senderId].name} + + {message.userStore.users[message.senderId].name} + - {getPrettyDateChat(message.createdAt)} + {getPrettyDate(message.createdAt)}diff --git a/src/utils/dateHelpers.ts b/src/utils/dateHelpers.ts index b0c11e9646..20787fa19d 100644 --- a/src/utils/dateHelpers.ts +++ b/src/utils/dateHelpers.ts @@ -29,11 +29,3 @@ export const getPrettyDate = (dateString: string): string => { const prettyDate = date.format('Do MMMM, HH:mm'); return prettyDate; }; -/** - * A format that fits into the message frame's limited space - */ -export const getPrettyDateChat = (dateString: string): string => { - const date = moment(dateString); - const prettyDate = date.format('DD/MM/YY, HH:mm'); - return prettyDate; -}; From 2264a4899d5f9f8a5af31539d9b5b2ee5b518b30 Mon Sep 17 00:00:00 2001 From: flxffyDate: Tue, 2 Jul 2019 13:10:33 +0800 Subject: [PATCH 24/52] remove grading result view mde --- src/components/assessment/GradingResult.tsx | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/components/assessment/GradingResult.tsx b/src/components/assessment/GradingResult.tsx index 79876bc575..07c5c72155 100644 --- a/src/components/assessment/GradingResult.tsx +++ b/src/components/assessment/GradingResult.tsx @@ -1,7 +1,6 @@ import { Text } from '@blueprintjs/core'; import * as React from 'react'; import { getPrettyDate } from '../../utils/dateHelpers'; -import Markdown from '../commons/Markdown'; type GradingResultProps = OwnProps; @@ -46,18 +45,6 @@ class GradingResult extends React.Component { - {this.props.comment !== null ? ( - -- ) : null} -
-Comment: --
-- --
From 45b491d403f4aec6ab621acbfc401702a2b9727b Mon Sep 17 00:00:00 2001 From: Hoang <42971570+wardetu@users.noreply.github.com> Date: Mon, 1 Jul 2019 23:34:16 +0700 Subject: [PATCH 25/52] Remove MDE and replace comment field --- .../academy/grading/GradingEditor.tsx | 74 +------------------ 1 file changed, 4 insertions(+), 70 deletions(-) diff --git a/src/components/academy/grading/GradingEditor.tsx b/src/components/academy/grading/GradingEditor.tsx index 805f515710..5de271cd49 100644 --- a/src/components/academy/grading/GradingEditor.tsx +++ b/src/components/academy/grading/GradingEditor.tsx @@ -1,9 +1,7 @@ -import { Icon, Intent, NumericInput, Position, Text } from '@blueprintjs/core'; +import { Intent, NumericInput, Position, Text } from '@blueprintjs/core'; import { IconNames } from '@blueprintjs/icons'; import * as React from 'react'; -import ReactMde, { ReactMdeTypes } from 'react-mde'; import { Prompt } from 'react-router'; -import * as Showdown from 'showdown'; import { showWarningMessage } from '../../../utils/notification'; import { stringParamToInt } from '../../../utils/paramParseHelpers'; @@ -15,7 +13,6 @@ export type DispatchProps = { handleGradingSave: ( submissionId: number, questionId: number, - comment: string, gradeAdjustment: number | undefined, xpAdjustment: number | undefined ) => void; @@ -49,33 +46,22 @@ export type OwnProps = { * so as to allow input such as the '-' character. */ type State = { - mdeState: ReactMdeTypes.MdeState; gradeAdjustmentInput: string | null; xpAdjustmentInput: string | null; }; class GradingEditor extends React.Component-{ - private converter: Showdown.Converter; constructor(props: GradingEditorProps) { super(props); this.state = { - mdeState: { - markdown: props.comment - }, gradeAdjustmentInput: props.gradeAdjustment.toString(), xpAdjustmentInput: props.xpAdjustment.toString() }; /** * The markdown-to-html converter for the editor. */ - this.converter = new Showdown.Converter({ - tables: true, - simplifiedAutoLink: true, - strikethrough: true, - tasklists: true, - openLinksInNewWindow: true - }); + // Converter now gone for there is no need for an MDE } public render() { @@ -176,32 +162,17 @@ class GradingEditor extends React.Component { -{controlButton('Save', IconNames.FLOPPY_DISK, this.onClickSaveButton, saveButtonOpts)}-