Skip to content
This repository has been archived by the owner on Sep 7, 2020. It is now read-only.

Commit

Permalink
feat: allow to close current chat
Browse files Browse the repository at this point in the history
  • Loading branch information
coderbyheart committed Jan 22, 2020
1 parent 74a557e commit 711065f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 18 deletions.
62 changes: 44 additions & 18 deletions src/Chat/Twilio/ChannelView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,15 @@ export const ChannelView = ({
})
})

const [initialLoad, setInitialLoad] = useState<boolean>(true)
const loadOlderMessages = (channel: Channel, scrollToBeginning = true) => {
if (scrollToBeginning) {
setScrollTo('beginning')
}
channel
.getMessages(10, messages.lastIndex && messages.lastIndex - 1)
.then(messages => {
setInitialLoad(false)
updateMessages(prevMessages => ({
...prevMessages,
messages: [
Expand All @@ -212,6 +214,7 @@ export const ChannelView = ({
})
.catch(err => {
console.error(err)
setInitialLoad(false)
})
}

Expand Down Expand Up @@ -252,24 +255,39 @@ export const ChannelView = ({
<Title>
Chat: <strong>#{selectedChannel}</strong>
</Title>
{!isMinimized && (
<MinimizeButton
onClick={() => {
memoMinimized(true)
}}
>
_
</MinimizeButton>
)}
{isMinimized && (
<MinimizeButton
onClick={() => {
memoMinimized(false)
}}
>
+
</MinimizeButton>
)}
<span>
{joinedChannels.length > 1 && (
<MinimizeButton
onClick={e => {
e.stopPropagation()
onSwitchChannel(
joinedChannels.find(c => c !== selectedChannel) as string,
)
onCloseChannel(selectedChannel)
}}
>
X
</MinimizeButton>
)}
{!isMinimized && (
<MinimizeButton
onClick={() => {
memoMinimized(true)
}}
>
_
</MinimizeButton>
)}
{isMinimized && (
<MinimizeButton
onClick={() => {
memoMinimized(false)
}}
>
+
</MinimizeButton>
)}
</span>
</Header>
{!isMinimized && (
<>
Expand All @@ -282,6 +300,14 @@ export const ChannelView = ({
Load older messages
</TextButton>
)}
{initialLoad && (
<StatusItem
status={{
message: 'Loading messages...',
timestamp: new Date(),
}}
/>
)}
{messages.messages.map(m =>
'status' in m ? (
<StatusItem key={m.sid} status={m.status} />
Expand Down
2 changes: 2 additions & 0 deletions src/Chat/components/ChannelView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ export const MinimizeButton = styled(Button)`
${Header} & {
color: inherit;
}
cursor: pointer;
`

export const SendButton = styled(Button)`
background-color: #fff;
margin-left: 0.5rem;
cursor: pointer;
`

export const MessageInput = styled.input`
Expand Down

0 comments on commit 711065f

Please sign in to comment.