-
Notifications
You must be signed in to change notification settings - Fork 9
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
29 changed files
with
987 additions
and
59 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
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,14 @@ | ||
import { fromJS } from 'immutable'; | ||
|
||
const initialState = fromJS({ | ||
chatWidth: 0, | ||
}); | ||
|
||
function chatReducer(state = initialState, action) { | ||
switch (action.type) { | ||
default: | ||
return state; | ||
} | ||
} | ||
|
||
export default chatReducer; |
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,74 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { FormattedMessage } from 'react-intl'; | ||
import { Flex } from 'rebass'; | ||
import { ButtonOutline, Input } from 'style-store'; | ||
import { PublicChannels } from './constants'; | ||
import messages from './messages'; | ||
|
||
const StyledButton = ButtonOutline.extend` | ||
border-radius: 5px; | ||
padding: 10px; | ||
`; | ||
|
||
class Channels extends React.PureComponent { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { content: '' }; | ||
this.handleChange = (e) => this.setState({ content: e.target.value }); | ||
this.handleKeyDown = (e) => { | ||
if (e.key === 'Enter') this.props.tune(this.state.content); | ||
}; | ||
} | ||
render() { | ||
return ( | ||
<Flex wrap> | ||
<StyledButton | ||
w={1} | ||
py={20} | ||
my={5} | ||
onClick={() => this.props.tune(null)} | ||
> | ||
<FormattedMessage {...messages.defaultChannel} /> | ||
</StyledButton> | ||
{PublicChannels.map((c) => ( | ||
<StyledButton | ||
w={1} | ||
py={20} | ||
my={5} | ||
onClick={() => this.props.tune(c)} | ||
key={c} | ||
> | ||
{c} | ||
</StyledButton> | ||
))} | ||
<Flex mx={1} w={1}> | ||
<FormattedMessage {...messages.channelName}> | ||
{(msg) => ( | ||
<Input | ||
value={this.state.content} | ||
placeholder={msg} | ||
onChange={this.handleChange} | ||
onKeyDown={this.handleKeyDown} | ||
/> | ||
)} | ||
</FormattedMessage> | ||
<ButtonOutline | ||
onClick={this.handleSubmit} | ||
p={10} | ||
style={{ wordBreak: 'keep-all' }} | ||
> | ||
<FormattedMessage {...messages.change} /> | ||
</ButtonOutline> | ||
</Flex> | ||
</Flex> | ||
); | ||
} | ||
} | ||
|
||
Channels.propTypes = { | ||
tune: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default Channels; |
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 @@ | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
import { DarkNicknameLink as NicknameLink } from 'style-store'; | ||
import UserAwardPopover from 'components/UserAwardPopover'; | ||
import PropTypes from 'prop-types'; | ||
|
||
const MessageWrapper = styled.div` | ||
border-radius: 5px; | ||
border: 1px solid #006388; | ||
padding: 3px; | ||
margin: 5px 0; | ||
background-color: rgba(255, 255, 255, 0.382); | ||
font-size: 1.1em; | ||
`; | ||
|
||
function ChatMessage(props) { | ||
return ( | ||
<MessageWrapper> | ||
<NicknameLink to={`/profile/${props.user.rowid}`}> | ||
{props.user.nickname} | ||
</NicknameLink> | ||
<UserAwardPopover | ||
userAward={props.user.currentAward} | ||
style={{ color: '#23527c', fontSize: '0.9em' }} | ||
/> | ||
{' '} | ||
{props.content} | ||
</MessageWrapper> | ||
); | ||
} | ||
|
||
ChatMessage.propTypes = { | ||
user: PropTypes.object.isRequired, | ||
content: PropTypes.string.isRequired, | ||
}; | ||
|
||
export default ChatMessage; |
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,113 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import bootbox from 'bootbox'; | ||
import { connect } from 'react-redux'; | ||
import { compose } from 'redux'; | ||
import { commitMutation } from 'react-relay'; | ||
import environment from 'Environment'; | ||
import { FormattedMessage } from 'react-intl'; | ||
import { Flex } from 'rebass'; | ||
import { Input, ButtonOutline } from 'style-store'; | ||
import { CreateMinichatMutation } from 'graphql/CreateMinichatMutation'; | ||
import ChatMessage from './ChatMessage'; | ||
import Wrapper from './Wrapper'; | ||
import { loadMore } from './actions'; | ||
import messages from './messages'; | ||
|
||
const LoadMoreBtn = ButtonOutline.extend` | ||
border-radius: 10px; | ||
padding: 5px; | ||
width: 100%; | ||
`; | ||
|
||
const MessageWrapper = Wrapper.extend` | ||
overflow-y: auto; | ||
height: ${(props) => props.height}px; | ||
width: 100%; | ||
margin-bottom: 5px; | ||
border-radius: 0 0 10px 10px; | ||
`; | ||
|
||
class ChatRoom extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { content: '' }; | ||
this.handleChange = (e) => this.setState({ content: e.target.value }); | ||
this.handleKeyDown = (e) => { | ||
if (e.key === 'Enter') this.handleSubmit(); | ||
}; | ||
this.handleSubmit = this.handleSubmit.bind(this); | ||
} | ||
|
||
handleSubmit() { | ||
commitMutation(environment, { | ||
mutation: CreateMinichatMutation, | ||
variables: { | ||
input: { | ||
content: this.state.content, | ||
channel: this.props.channel, | ||
}, | ||
}, | ||
onCompleted: (response, errors) => { | ||
if (errors) { | ||
bootbox.alert(errors.map((e) => e.message).join(',')); | ||
} | ||
this.setState({ content: '' }); | ||
}, | ||
}); | ||
} | ||
|
||
render() { | ||
return ( | ||
<Flex wrap justify="center"> | ||
<MessageWrapper height={this.props.height - 50}> | ||
<LoadMoreBtn | ||
onClick={() => this.props.dispatch(loadMore())} | ||
hidden={!this.props.hasPreviousPage} | ||
> | ||
<FormattedMessage {...messages.loadMore} /> | ||
</LoadMoreBtn> | ||
{this.props.chatMessages.map((msg) => ( | ||
<ChatMessage | ||
user={msg.node.user} | ||
key={msg.node.id} | ||
content={msg.node.content} | ||
/> | ||
))} | ||
</MessageWrapper> | ||
<Flex mx={1} w={1} hidden={this.props.currentUserId === null}> | ||
<Input | ||
value={this.state.content} | ||
onChange={this.handleChange} | ||
onKeyDown={this.handleKeyDown} | ||
/> | ||
<ButtonOutline | ||
onClick={this.handleSubmit} | ||
p={10} | ||
style={{ wordBreak: 'keep-all' }} | ||
> | ||
<FormattedMessage {...messages.send} /> | ||
</ButtonOutline> | ||
</Flex> | ||
</Flex> | ||
); | ||
} | ||
} | ||
|
||
ChatRoom.propTypes = { | ||
dispatch: PropTypes.func.isRequired, | ||
chatMessages: PropTypes.array.isRequired, | ||
hasPreviousPage: PropTypes.bool, | ||
channel: PropTypes.string, | ||
height: PropTypes.number.isRequired, | ||
currentUserId: PropTypes.number, | ||
}; | ||
|
||
const mapDispatchToProps = (dispatch) => ({ | ||
dispatch, | ||
}); | ||
|
||
const withConnect = connect(null, mapDispatchToProps); | ||
|
||
export default compose(withConnect)(ChatRoom); |
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,9 @@ | ||
import styled from 'styled-components'; | ||
|
||
export const Wrapper = styled.div` | ||
border: 2px solid sienna; | ||
border-radius: 10px; | ||
padding: 5px; | ||
`; | ||
|
||
export default Wrapper; |
Oops, something went wrong.