This repository has been archived by the owner on Oct 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
393 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
This file is a part of libertysoil.org website | ||
Copyright (C) 2016 Loki Education (Social Enterprise) | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
You should have received a copy of the GNU Affero General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
// When updating the whole message chain. | ||
export const SET_USER_MESSAGES = 'SET_USER_MESSAGES'; | ||
// When sending a new message. | ||
export const ADD_USER_MESSAGE = 'ADD_USER_MESSAGE'; | ||
|
||
export function setUserMessages(userId, messages) { | ||
return { | ||
type: SET_USER_MESSAGES, | ||
messages, | ||
userId | ||
}; | ||
} | ||
|
||
export function addUserMessage(userId, message) { | ||
return { | ||
type: ADD_USER_MESSAGE, | ||
message, | ||
userId | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
This file is a part of libertysoil.org website | ||
Copyright (C) 2016 Loki Education (Social Enterprise) | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
You should have received a copy of the GNU Affero General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
import React, { PropTypes } from 'react'; | ||
|
||
import Avatar from '../user/avatar'; | ||
import Time from '../time'; | ||
import { Immutable as ImmutablePropType } from '../../prop-types/common'; | ||
import { User as UserPropType } from '../../prop-types/users'; | ||
|
||
|
||
function Message({ currentUser, selectedUser, message, hideAvatar = false }) { | ||
const isMyMessage = message.get('sender_id') === currentUser.get('id'); | ||
let className = 'conversations_tool__message'; | ||
if (isMyMessage) { | ||
className += ' conversations_tool__message-my'; | ||
} else { | ||
className += ' conversations_tool__message-their'; | ||
} | ||
|
||
let user = currentUser; | ||
if (!isMyMessage) { | ||
user = selectedUser; | ||
} | ||
|
||
return ( | ||
<div className={className}> | ||
<Time className="conversations_tool__time" timestamp={message.get('created_at')} /> | ||
{!hideAvatar && | ||
<Avatar className="conversations_tool__avatar" size={32} user={user} /> | ||
} | ||
{message.get('text')} | ||
</div> | ||
); | ||
} | ||
|
||
export default class Conversation extends React.Component<void, Props, void> { | ||
static propTypes = { | ||
currentUser: ImmutablePropType(UserPropType.isRequired), | ||
messages: ImmutablePropType(PropTypes.shape({})), | ||
selectedUser: ImmutablePropType(UserPropType) | ||
}; | ||
|
||
handleSubmit = (e) => { | ||
e.preventDefault(); | ||
this.props.onSend(this.props.selectedUser.get('id'), this.form.text.value); | ||
this.form.text.value = ''; | ||
}; | ||
|
||
render() { | ||
const { | ||
currentUser, | ||
messages, | ||
selectedUser, | ||
} = this.props; | ||
|
||
if (!selectedUser) { | ||
return null; | ||
} | ||
|
||
const messageElements = messages.map((message, index) => { | ||
const hideAvatar = index > 0 && messages.getIn([index - 1, 'sender_id']) === message.get('sender_id'); | ||
|
||
return ( | ||
<Message | ||
currentUser={currentUser} | ||
hideAvatar={hideAvatar} | ||
key={message.get('id')} | ||
message={message} | ||
selectedUser={selectedUser} | ||
/> | ||
); | ||
}); | ||
|
||
return ( | ||
<div> | ||
<div className="conversations_tool__messages"> | ||
{messageElements} | ||
</div> | ||
<form ref={c => this.form = c} onSubmit={this.handleSubmit}> | ||
<textarea | ||
className="conversations_tool__input" | ||
name="text" | ||
placeholder={'Type your message here, hit "enter" or "Send" button'} | ||
/> | ||
<input className="button button-red" type="submit" value="Send" /> | ||
</form> | ||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
This file is a part of libertysoil.org website | ||
Copyright (C) 2016 Loki Education (Social Enterprise) | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
You should have received a copy of the GNU Affero General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
.conversations_tool { | ||
&__messages { | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
|
||
&__message { | ||
position: relative; | ||
display: flex; | ||
margin-bottom: 20px; | ||
padding: 20px 20px 30px 20px; | ||
align-items: center; | ||
background-color: white; | ||
border: 1px solid @color__gray; | ||
max-width: 60%; | ||
min-width: 170px; // to fit the time | ||
|
||
&-my { | ||
align-self: flex-end; | ||
flex-flow: row-reverse; | ||
|
||
> .conversations_tool__avatar { | ||
margin-left: 10px; | ||
} | ||
|
||
> .conversations_tool__time { | ||
right: 20px; | ||
} | ||
} | ||
|
||
&-their { | ||
align-self: flex-start; | ||
|
||
> .conversations_tool__avatar { | ||
margin-right: 10px; | ||
} | ||
|
||
> .conversations_tool__time { | ||
left: 20px; | ||
} | ||
} | ||
} | ||
|
||
&__avatar { | ||
align-self: flex-start; | ||
} | ||
|
||
&__input { | ||
display: block; | ||
width: 100%; | ||
margin-bottom: 10px; | ||
} | ||
|
||
&__time { | ||
position: absolute; | ||
bottom: 2px; | ||
color: @color__gray; | ||
font-size: 13px; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.