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

Replaced older tab implementation in trending channels with the new tab block component #1800

Merged
merged 6 commits into from
Aug 12, 2024
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
10 changes: 1 addition & 9 deletions src/modules/dashboard/Dashboard.constants.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
//Components
import { PushAlpha, PushBot, PushDev } from 'blocks';

//Types
import { ChatType, DashboardChannelTabsType, EnvKeys, SourceKeys } from './Dashboard.types';

export const dahboardChannelTabs: DashboardChannelTabsType = [
{ label: 'Trending Channels', value: 'trending' },
{ label: 'Hottest Channels', value: 'hottest' },
{ label: 'Subscribed', value: 'subscribed' },
];
import { ChatType, EnvKeys, SourceKeys } from './Dashboard.types';

export const recommendedChatList: ChatType[] = [
{
Expand Down
2 changes: 1 addition & 1 deletion src/modules/dashboard/Dashboard.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FC } from 'react';
export type ChannelTabs = 'subscribed' | 'trending' | 'hottest';
export type DashboardChannelTabType = {
label: string;
value: ChannelTabs;
key: ChannelTabs;
};
export type DashboardChannelTabsType = Array<DashboardChannelTabType>;
export type TrendingChannelsType = {
Expand Down
3 changes: 2 additions & 1 deletion src/modules/dashboard/Dashboard.utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { TrendingChannelsResponse } from 'queries/types';
import { TrendingChannelsType } from './Dashboard.types';


/**
* @param weekData
* @param currentData
Expand Down Expand Up @@ -54,7 +55,7 @@ export const getTrendingChannelsData = (
subscriber: currentSubscriberData[key],
name: channelDetails[key]?.name || '',
icon: channelDetails[key]?.icon || '',
trend: trend
trend: trend,
});
}

Expand Down
143 changes: 75 additions & 68 deletions src/modules/dashboard/components/ChannelTabsSection.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,73 @@
import { useEffect, useState } from 'react';
import { css } from 'styled-components';

import { Box, Text } from 'blocks';
import { Box, TabItem, Tabs } from 'blocks';

import { useAccount } from 'hooks';

import { ChannelTabs } from '../Dashboard.types';

import { HottestChannelsList } from './HottestChannelsList';
import { TrendingChannelsList } from './TrendingChannelsList';
import { SubscribedChannelsList } from './SubscribedChannelsList';
import { dahboardChannelTabs } from '../Dashboard.constants';
import { HottestChannelsList } from './HottestChannelsList';

const ChannelTabsSection = () => {
const [selectedChannelTab, setSelectedChannelTab] = useState<ChannelTabs>(dahboardChannelTabs[0].value);
const dashboardChannelTabs: TabItem[] = [
{
label: 'Trending Channels',
key: 'trending',
children: (
<Box
display="flex"
flexDirection="column"
overflow="hidden auto"
borderRadius="radius-md"
minHeight="285px"
maxHeight="285px"
border="border-sm solid stroke-secondary"
padding="spacing-xxs spacing-sm"
>
<TrendingChannelsList />
</Box>
),
},
{
label: 'Hottest Channels',
key: 'hottest',
children: (
<Box
display="flex"
flexDirection="column"
overflow="hidden auto"
borderRadius="radius-md"
minHeight="285px"
maxHeight="285px"
border="border-sm solid stroke-secondary"
padding="spacing-xxs spacing-sm"
>
<HottestChannelsList />
</Box>
),
},
{
label: 'Subscribed',
key: 'subscribed',
children: (
<Box
display="flex"
flexDirection="column"
overflow="hidden auto"
borderRadius="radius-md"
minHeight="285px"
maxHeight="285px"
border="border-sm solid stroke-secondary"
padding="spacing-xxs spacing-sm"
>
<SubscribedChannelsList />
</Box>
),
},
];
const [selectedChannelTab, setSelectedChannelTab] = useState<ChannelTabs>(dashboardChannelTabs[0].key as ChannelTabs);
const { wallet } = useAccount();

const isWalletConnected = !!wallet?.accounts?.length;
Expand All @@ -25,75 +82,25 @@ const ChannelTabsSection = () => {
}
}, [isWalletConnected]);

const getUpdatedDashboardTabs = (dashboardChannelTabs: TabItem[], isWalletConnected: boolean): TabItem[] => {
if (!isWalletConnected) return dashboardChannelTabs.filter((tabs) => tabs.key !== 'subscribed');

if (isWalletConnected) return dashboardChannelTabs.filter((tabs) => tabs.key !== 'hottest');
return dashboardChannelTabs;
};

return (
<Box
display="flex"
flexDirection="column"
width={{ ml: '100%', initial: '50%' }}
gap="spacing-sm"
>
<Box width="100%">
{/* TODO: Use Tabs component here */}
<Box
backgroundColor="surface-secondary"
cursor="pointer"
display="flex"
gap="spacing-xxxs"
padding="spacing-xxxs"
height="fit-content"
justifyContent="space-between"
borderRadius="radius-sm"
width={{ lp: 'auto', initial: 'fit-content' }}
>
{dahboardChannelTabs?.map((channelTab, index) => {
if (channelTab.value === 'subscribed' && !isWalletConnected) return null;

if (channelTab.value === 'hottest' && isWalletConnected) return null;

return (
<Box
key={`${index}`}
display="flex"
justifyContent="center"
width={{ ll: '100%' }}
alignItems="center"
padding="spacing-xxs spacing-xs"
borderRadius="radius-sm"
onClick={() => setSelectedChannelTab(channelTab.value)}
css={css`
background-color: var(
--${selectedChannelTab === channelTab.value ? 'components-button-tertiary-background-inverse' : 'surface-transparent'}
);
`}
>
<Text
variant="h5-semibold"
ellipsis={true}
css={css`
color: var(--components-button-secondary-text-default);
`}
>
{channelTab?.label}
</Text>
</Box>
);
})}
</Box>
</Box>
<Box
display="flex"
flexDirection="column"
overflow="hidden auto"
borderRadius="radius-md"
minHeight="285px"
maxHeight="285px"
border="border-sm solid stroke-secondary"
padding="spacing-xxs spacing-sm"
>
{selectedChannelTab === 'trending' && <TrendingChannelsList />}
{selectedChannelTab === 'subscribed' && <SubscribedChannelsList />}
{selectedChannelTab === 'hottest' && <HottestChannelsList />}
</Box>
<Tabs
items={getUpdatedDashboardTabs(dashboardChannelTabs, isWalletConnected)}
activeKey={selectedChannelTab}
variant="fill"
onChange={(activeKey) => setSelectedChannelTab(activeKey as ChannelTabs)}
/>
</Box>
);
};
Expand Down
Loading