Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: persist expanded or collapsed state of sidebar sections #868

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions raven-app/src/components/feature/channels/ChannelList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import { ChannelListContext, ChannelListContextType, ChannelListItem, UnreadCoun
import { ChannelIcon } from "@/utils/layout/channelIcon"
import { Box, Flex, Text } from "@radix-ui/themes"
import { useLocation, useParams } from "react-router-dom"
import { useStickyState } from "@/hooks/useStickyState"

export const ChannelList = ({ unread_count }: { unread_count?: UnreadCountData }) => {

const { channels, mutate } = useContext(ChannelListContext) as ChannelListContextType

const [showData, setShowData] = useState(true)
const [showData, setShowData] = useStickyState(true, 'expandChannelList')

const toggle = () => setShowData(d => !d)

Expand All @@ -20,7 +21,7 @@ export const ChannelList = ({ unread_count }: { unread_count?: UnreadCountData }
return (
<SidebarGroup>
<SidebarGroupItem className={'pl-1.5 gap-1.5'}>
<SidebarViewMoreButton onClick={toggle} />
<SidebarViewMoreButton onClick={toggle} expanded={showData} />
<Flex width='100%' justify='between' align='center' gap='2'>
<Flex gap='2' align='center'>
<SidebarGroupLabel className='cal-sans'>Channels</SidebarGroupLabel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@ import { Box, Flex, Text } from "@radix-ui/themes"
import { UserAvatar } from "@/components/common/UserAvatar"
import { toast } from "sonner"
import { getErrorMessage } from "@/components/layout/AlertBanner/ErrorBanner"
import { useStickyState } from "@/hooks/useStickyState"

export const DirectMessageList = ({ unread_count }: { unread_count?: UnreadCountData }) => {

const { extra_users } = useContext(ChannelListContext) as ChannelListContextType

const [showData, setShowData] = useState(true)
const [showData, setShowData] = useStickyState(true, 'expandDirectMessageList')

const toggle = () => setShowData(d => !d)

return (
<SidebarGroup pb='4'>
<SidebarGroupItem className={'pl-1.5 gap-1.5'}>
<SidebarViewMoreButton onClick={toggle} />
<SidebarViewMoreButton onClick={toggle} expanded={showData} />
<Flex width='100%' justify='between' align='center' gap='2'>
<SidebarGroupLabel className='cal-sans'>Direct Messages</SidebarGroupLabel>
{!showData && unread_count && unread_count?.total_unread_count_in_dms > 0 &&
Expand Down
14 changes: 5 additions & 9 deletions raven-app/src/components/layout/Sidebar/SidebarComp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,11 @@ export const SidebarButtonItem = ({ children, subtle, onClick, isLoading, active
}

interface SidebarViewMoreButtonProps extends IconButtonProps {
onClick: () => void
onClick: () => void,
expanded: boolean
}

export const SidebarViewMoreButton = ({ onClick, ...props }: SidebarViewMoreButtonProps) => {

const [isViewMore, setIsViewMore] = useState(false)
export const SidebarViewMoreButton = ({ expanded, onClick, ...props }: SidebarViewMoreButtonProps) => {

return (
<IconButton
Expand All @@ -147,12 +146,9 @@ export const SidebarViewMoreButton = ({ onClick, ...props }: SidebarViewMoreButt
size='1'
className='cursor-pointer pb-[4px] text-slate-12 bg-transparent hover:text-gray-12'
highContrast
onClick={() => {
setIsViewMore(!isViewMore)
onClick()
}}
onClick={onClick}
{...props}>
{isViewMore ? <FaCaretRight size='18' /> : <FaCaretDown size='18' />}
{expanded ? <FaCaretDown size='18' /> : <FaCaretRight size='18' />}
</IconButton>
)
}
Expand Down
Loading