-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change pinned and starred message windows to sidebars (#501)
- Loading branch information
1 parent
166f36e
commit 63e0523
Showing
9 changed files
with
342 additions
and
10 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
129 changes: 129 additions & 0 deletions
129
packages/react/src/components/PinnedMessages/PinnedMessages.js
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,129 @@ | ||
import React, { useState, useContext, useMemo, useEffect } from 'react'; | ||
import { isSameDay, format } from 'date-fns'; | ||
import RCContext from '../../context/RCInstance'; | ||
import classes from './PinnedMessages.module.css'; | ||
import { usePinnedMessageStore } from '../../store'; | ||
import { Box } from '../Box'; | ||
import { Icon } from '../Icon'; | ||
import { ActionButton } from '../ActionButton'; | ||
import { MessageDivider } from '../Message/MessageDivider'; | ||
import { Message } from '../Message'; | ||
import isMessageSequential from '../../lib/isMessageSequential'; | ||
import { Throbber } from '../Throbber'; | ||
|
||
const PinnedMessages = () => { | ||
const { RCInstance } = useContext(RCContext); | ||
const setShowPinned = usePinnedMessageStore((state) => state.setShowPinned); | ||
|
||
const [messageList, setMessageList] = useState([]); | ||
const [loading, setLoading] = useState(true); | ||
|
||
const toggleShowPinned = () => { | ||
setShowPinned(false); | ||
}; | ||
|
||
const getPinnedMessages = async () => { | ||
const { messages } = await RCInstance.getPinnedMessages(); | ||
setMessageList(messages); | ||
setLoading(false); | ||
}; | ||
|
||
useEffect(() => { | ||
if (messageList.length === 0) { | ||
getPinnedMessages(); | ||
} | ||
}, [messageList, getPinnedMessages]); | ||
|
||
const isMessageNewDay = (current, previous) => | ||
!previous || !isSameDay(new Date(current.ts), new Date(previous.ts)); | ||
|
||
return ( | ||
<Box className={classes.sidebar} style={{ padding: '1rem' }}> | ||
<Box className={classes.wrapContainer}> | ||
<Box | ||
style={{ | ||
display: 'flex', | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
gap: '0.5rem', | ||
marginBottom: '1rem', | ||
}} | ||
> | ||
<h3 style={{ display: 'contents' }}> | ||
<Icon name="pin" size="1.25rem" /> | ||
<Box style={{ color: '#4a4a4a', width: '80%' }}> | ||
Pinned Messages | ||
</Box> | ||
<ActionButton onClick={toggleShowPinned} ghost size="small"> | ||
<Icon name="cross" size="x20" /> | ||
</ActionButton> | ||
</h3> | ||
</Box> | ||
<Box | ||
style={{ | ||
flex: '1', | ||
overflow: 'auto', | ||
display: 'flex', | ||
flexDirection: 'column', | ||
justifyContent: messageList.length === 0 ? 'center' : 'initial', | ||
alignItems: messageList.length === 0 ? 'center' : 'initial', | ||
}} | ||
> | ||
{loading ? ( | ||
<Box | ||
style={{ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
alignItems: 'center', | ||
color: '#4a4a4a', | ||
}} | ||
> | ||
<Throbber /> | ||
</Box> | ||
) : messageList.length === 0 ? ( | ||
<Box | ||
style={{ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
alignItems: 'center', | ||
color: '#4a4a4a', | ||
}} | ||
> | ||
<Icon name="pin" size="3rem" style={{ padding: '0.5rem' }} /> | ||
<span style={{ fontSize: '1.2rem', fontWeight: 'bold' }}> | ||
No pinned messages | ||
</span> | ||
</Box> | ||
) : ( | ||
messageList.map((msg, index, arr) => { | ||
const prev = arr[index + 1]; | ||
const newDay = isMessageNewDay(msg, prev); | ||
const sequential = isMessageSequential(msg, prev, 300); | ||
return ( | ||
<Box key={msg._id}> | ||
{newDay && ( | ||
<Box style={{ paddingTop: '0.5rem' }}> | ||
<MessageDivider> | ||
{format(new Date(msg.ts), 'MMMM d, yyyy')} | ||
</MessageDivider> | ||
</Box> | ||
)} | ||
<Message | ||
key={msg._id} | ||
message={msg} | ||
newDay={false} | ||
sequential={sequential} | ||
variant="default" | ||
showAvatar | ||
showToolbox={false} | ||
/> | ||
</Box> | ||
); | ||
}) | ||
)} | ||
</Box> | ||
</Box> | ||
</Box> | ||
); | ||
}; | ||
export default PinnedMessages; |
23 changes: 23 additions & 0 deletions
23
packages/react/src/components/PinnedMessages/PinnedMessages.module.css
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,23 @@ | ||
.sidebar { | ||
position: fixed; | ||
right: 0; | ||
top: 0; | ||
width: 350px; | ||
height: 100%; | ||
overflow-x: scroll; | ||
overflow-y: scroll; | ||
background-color: white; | ||
box-shadow: -1px 0px 5px rgb(0 0 0 / 25%); | ||
z-index: 100; | ||
} | ||
|
||
.wrapContainer { | ||
height: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
@media (max-width: 550px) { | ||
.sidebar { | ||
width: 100vw; | ||
} | ||
} |
131 changes: 131 additions & 0 deletions
131
packages/react/src/components/StarredMessages/StarredMessages.js
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,131 @@ | ||
import React, { useState, useContext, useMemo, useEffect } from 'react'; | ||
import { isSameDay, format } from 'date-fns'; | ||
import RCContext from '../../context/RCInstance'; | ||
import classes from './StarredMessages.module.css'; | ||
import { useStarredMessageStore } from '../../store'; | ||
import { Box } from '../Box'; | ||
import { Icon } from '../Icon'; | ||
import { ActionButton } from '../ActionButton'; | ||
import { MessageDivider } from '../Message/MessageDivider'; | ||
import { Message } from '../Message'; | ||
import isMessageSequential from '../../lib/isMessageSequential'; | ||
import { Throbber } from '../Throbber'; | ||
|
||
const StarredMessages = () => { | ||
const { RCInstance } = useContext(RCContext); | ||
const setShowStarred = useStarredMessageStore( | ||
(state) => state.setShowStarred | ||
); | ||
|
||
const [messageList, setMessageList] = useState([]); | ||
const [loading, setLoading] = useState(true); | ||
|
||
const toggleShowStarred = () => { | ||
setShowStarred(false); | ||
}; | ||
|
||
const getStarredMessages = async () => { | ||
const { messages } = await RCInstance.getStarredMessages(); | ||
setMessageList(messages); | ||
setLoading(false); | ||
}; | ||
|
||
useEffect(() => { | ||
if (messageList.length === 0) { | ||
getStarredMessages(); | ||
} | ||
}, [messageList, getStarredMessages]); | ||
|
||
const isMessageNewDay = (current, previous) => | ||
!previous || !isSameDay(new Date(current.ts), new Date(previous.ts)); | ||
|
||
return ( | ||
<Box className={classes.sidebar} style={{ padding: '1rem' }}> | ||
<Box className={classes.wrapContainer}> | ||
<Box | ||
style={{ | ||
display: 'flex', | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
gap: '0.5rem', | ||
marginBottom: '1rem', | ||
}} | ||
> | ||
<h3 style={{ display: 'contents' }}> | ||
<Icon name="star" size="1.25rem" /> | ||
<Box style={{ color: '#4a4a4a', width: '80%' }}> | ||
Starred Messages | ||
</Box> | ||
<ActionButton onClick={toggleShowStarred} ghost size="small"> | ||
<Icon name="cross" size="x20" /> | ||
</ActionButton> | ||
</h3> | ||
</Box> | ||
<Box | ||
style={{ | ||
flex: '1', | ||
overflow: 'auto', | ||
display: 'flex', | ||
flexDirection: 'column', | ||
justifyContent: messageList.length === 0 ? 'center' : 'initial', | ||
alignItems: messageList.length === 0 ? 'center' : 'initial', | ||
}} | ||
> | ||
{loading ? ( | ||
<Box | ||
style={{ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
alignItems: 'center', | ||
color: '#4a4a4a', | ||
}} | ||
> | ||
<Throbber /> | ||
</Box> | ||
) : messageList.length === 0 ? ( | ||
<Box | ||
style={{ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
alignItems: 'center', | ||
color: '#4a4a4a', | ||
}} | ||
> | ||
<Icon name="star" size="3rem" style={{ padding: '0.5rem' }} /> | ||
<span style={{ fontSize: '1.2rem', fontWeight: 'bold' }}> | ||
No starred messages | ||
</span> | ||
</Box> | ||
) : ( | ||
messageList.map((msg, index, arr) => { | ||
const prev = arr[index + 1]; | ||
const newDay = isMessageNewDay(msg, prev); | ||
const sequential = isMessageSequential(msg, prev, 300); | ||
return ( | ||
<Box key={msg._id}> | ||
{newDay && ( | ||
<Box style={{ paddingTop: '0.5rem' }}> | ||
<MessageDivider> | ||
{format(new Date(msg.ts), 'MMMM d, yyyy')} | ||
</MessageDivider> | ||
</Box> | ||
)} | ||
<Message | ||
key={msg._id} | ||
message={msg} | ||
newDay={false} | ||
sequential={sequential} | ||
variant="default" | ||
showAvatar | ||
showToolbox={false} | ||
/> | ||
</Box> | ||
); | ||
}) | ||
)} | ||
</Box> | ||
</Box> | ||
</Box> | ||
); | ||
}; | ||
export default StarredMessages; |
23 changes: 23 additions & 0 deletions
23
packages/react/src/components/StarredMessages/StarredMessages.module.css
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,23 @@ | ||
.sidebar { | ||
position: fixed; | ||
right: 0; | ||
top: 0; | ||
width: 350px; | ||
height: 100%; | ||
overflow-x: scroll; | ||
overflow-y: scroll; | ||
background-color: white; | ||
box-shadow: -1px 0px 5px rgb(0 0 0 / 25%); | ||
z-index: 100; | ||
} | ||
|
||
.wrapContainer { | ||
height: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
@media (max-width: 550px) { | ||
.sidebar { | ||
width: 100vw; | ||
} | ||
} |
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.