-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(home): add options to collapse channels by default & display vid…
…eos count per channel
- Loading branch information
Showing
16 changed files
with
311 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* eslint-disable react-hooks/exhaustive-deps */ | ||
import { createContext, FC, memo, useContext, useMemo, useState } from 'react'; | ||
import { useAppSelector } from 'store'; | ||
import { selectViewChannelOption } from 'store/selectors/settings'; | ||
import { HomeView } from 'types'; | ||
|
||
type ChannelOptionsContextType = { | ||
collapseByDefault: boolean; | ||
collapsed: boolean; | ||
setCollapsed: (value: boolean) => void; | ||
}; | ||
|
||
const ChannelOptionsContext = createContext< | ||
ChannelOptionsContextType | undefined | ||
>(undefined); | ||
|
||
export const ChannelOptionsProvider: FC<{ view: HomeView }> = memo( | ||
({ view, children }) => { | ||
const collapseByDefault = useAppSelector( | ||
selectViewChannelOption(view, 'collapseByDefault'), | ||
); | ||
const [collapsed, setCollapsed] = useState(collapseByDefault); | ||
|
||
const value = useMemo( | ||
() => ({ | ||
collapseByDefault, | ||
collapsed: collapseByDefault && collapsed, | ||
setCollapsed, | ||
}), | ||
[collapseByDefault, collapsed], | ||
); | ||
|
||
return ( | ||
<ChannelOptionsContext.Provider value={value}> | ||
{children} | ||
</ChannelOptionsContext.Provider> | ||
); | ||
}, | ||
); | ||
|
||
export function useChannelOptions(): ChannelOptionsContextType { | ||
const context = useContext(ChannelOptionsContext); | ||
|
||
if (context === undefined) { | ||
throw new Error( | ||
'useChannelOptions must be used within a ChannelOptionsContext', | ||
); | ||
} | ||
|
||
return context; | ||
} |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './ChannelVideosProvider'; | ||
export * from './ChannelOptionsProvider'; |
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
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
34 changes: 34 additions & 0 deletions
34
src/ui/components/pages/Home/ChannelRenderer/ChannelTitle/ChannelAvatar.tsx
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,34 @@ | ||
import React from 'react'; | ||
import { Avatar, Badge } from '@mui/material'; | ||
import { Channel, HomeView } from 'types'; | ||
import { useAppSelector } from 'store'; | ||
import { selectViewChannelOption } from 'store/selectors/settings'; | ||
import { useChannelVideos } from 'providers'; | ||
|
||
interface ChannelAvatarProps { | ||
view: HomeView; | ||
channel: Channel; | ||
} | ||
|
||
function ChannelAvatar(props: ChannelAvatarProps) { | ||
const { view, channel } = props; | ||
const displayVideosCount = useAppSelector( | ||
selectViewChannelOption(view, 'displayVideosCount'), | ||
); | ||
const { getChannelVideosCount } = useChannelVideos(view); | ||
const videosCount = displayVideosCount | ||
? getChannelVideosCount(channel.id) | ||
: null; | ||
|
||
return ( | ||
<Badge | ||
color="primary" | ||
badgeContent={videosCount} | ||
title={`${videosCount || ''}`} | ||
> | ||
<Avatar alt={channel.title} src={channel.thumbnail} /> | ||
</Badge> | ||
); | ||
} | ||
|
||
export default ChannelAvatar; |
Oops, something went wrong.