Skip to content

Commit

Permalink
feat(home): add an option to disable/enable opening channels on name …
Browse files Browse the repository at this point in the history
…click
  • Loading branch information
AXeL-dev committed Nov 7, 2022
1 parent 39d7dfd commit 1474b68
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/store/reducers/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const defaultSettings = {
channels: {
collapseByDefault: false,
displayVideosCount: false,
openChannelOnNameClick: false,
},
videosSeniority: VideosSeniority.Any,
},
Expand All @@ -50,6 +51,7 @@ export const defaultSettings = {
channels: {
collapseByDefault: false,
displayVideosCount: false,
openChannelOnNameClick: false,
},
videosSeniority: VideosSeniority.Any,
},
Expand All @@ -65,6 +67,7 @@ export const defaultSettings = {
channels: {
collapseByDefault: false,
displayVideosCount: false,
openChannelOnNameClick: false,
},
videosSeniority: VideosSeniority.Any,
},
Expand Down
1 change: 1 addition & 0 deletions src/types/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface Settings {
export interface ChannelOptions {
collapseByDefault: boolean;
displayVideosCount: boolean;
openChannelOnNameClick: boolean;
}

export enum ExtraVideoAction {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from 'react';
import { SxProps, Typography } from '@mui/material';
import { Channel, HomeView } from 'types';
import { useAppSelector } from 'store';
import { selectViewChannelOption } from 'store/selectors/settings';
import ChannelLink from './ChannelLink';

interface ChannelNameProps {
view: HomeView;
channel: Channel;
}

function ChannelName(props: ChannelNameProps) {
const { view, channel } = props;
const openChannelOnNameClick = useAppSelector(
selectViewChannelOption(view, 'openChannelOnNameClick'),
);

const renderName = (sx?: SxProps) => (
<Typography sx={sx} variant="subtitle1" color="text.primary">
{channel.title}
</Typography>
);

return openChannelOnNameClick ? (
<ChannelLink channel={channel}>{renderName()}</ChannelLink>
) : (
renderName({ cursor: 'default' })
);
}

export default ChannelName;
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from 'react';
import { Box, Typography } from '@mui/material';
import { Box } from '@mui/material';
import { Channel, HomeView } from 'types';
import ChannelLink from './ChannelLink';
import ChannelAvatar from './ChannelAvatar';
import ChannelName from './ChannelName';
import ChannelExpandToggle from './ChannelExpandToggle';

interface ChannelTitleProps {
Expand All @@ -25,11 +26,7 @@ function ChannelTitle(props: ChannelTitleProps) {
<ChannelLink channel={channel}>
<ChannelAvatar view={view} channel={channel} />
</ChannelLink>
<ChannelLink channel={channel}>
<Typography variant="subtitle1" color="text.primary">
{channel.title}
</Typography>
</ChannelLink>
<ChannelName view={view} channel={channel} />
<ChannelExpandToggle />
</Box>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ const options: ViewChannelOption[] = [
label: 'Display videos count per channel',
value: 'displayVideosCount',
},
{
label: 'Open channel on name click',
value: 'openChannelOnNameClick',
},
];

interface ViewChannelOptionsProps extends Omit<NestedMenuItemProps, 'label'> {
Expand Down

0 comments on commit 1474b68

Please sign in to comment.