Skip to content

Commit e321352

Browse files
committed
refactor: channel videos provider
1 parent b7bd310 commit e321352

2 files changed

Lines changed: 6 additions & 7 deletions

File tree

src/providers/ChannelVideosProvider.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
useRef,
1111
useState,
1212
} from 'react';
13+
import { views } from 'store/reducers/settings';
1314
import { GetChannelVideosResponse } from 'store/services/youtube';
1415
import { Channel, Video, HomeView } from 'types';
1516

@@ -32,9 +33,7 @@ type ChannelVideosContextType = {
3233
) => Video | undefined;
3334
};
3435

35-
const ALL_VIEWS = Object.values(HomeView);
36-
37-
const INITIAL_COUNT = ALL_VIEWS.reduce(
36+
const initialVideosCount = views.reduce(
3837
(acc, view) => ({
3938
...acc,
4039
[view]: {
@@ -45,7 +44,7 @@ const INITIAL_COUNT = ALL_VIEWS.reduce(
4544
{},
4645
);
4746

48-
const INITIAL_MAP = ALL_VIEWS.reduce(
47+
const initialChannelsMap = views.reduce(
4948
(acc, view) => ({ ...acc, [view]: new Map() }),
5049
{},
5150
);
@@ -56,9 +55,9 @@ const ChannelVideosContext = createContext<
5655

5756
export const ChannelVideosProvider: FC = memo(({ children }) => {
5857
const [videosCount, setVideosCount] =
59-
useState<ChannelVideosContextType['videosCount']>(INITIAL_COUNT);
58+
useState<ChannelVideosContextType['videosCount']>(initialVideosCount);
6059
const channelsMap = useRef<{ [key: string]: Map<string, ChannelData> }>(
61-
INITIAL_MAP,
60+
initialChannelsMap,
6261
);
6362

6463
const updateCount = useCallback(

src/store/reducers/settings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export const defaultSettings = {
6262
},
6363
};
6464

65-
const views = Object.values(HomeView);
65+
export const views = Object.values(HomeView);
6666

6767
interface SettingsState extends Settings {}
6868

0 commit comments

Comments
 (0)