Skip to content

Commit

Permalink
fix(home): correctly update videos count on the All view
Browse files Browse the repository at this point in the history
  • Loading branch information
AXeL-dev committed Nov 12, 2022
1 parent ecece51 commit 2a8efb7
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions src/providers/ChannelVideosProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable react-hooks/exhaustive-deps */
import { debounce } from 'helpers/utils';
import { useDidMountEffect } from 'hooks';
import { useStateRef } from 'hooks';
import {
createContext,
FC,
Expand Down Expand Up @@ -66,6 +66,7 @@ export const ChannelVideosProvider: FC = memo(({ children }) => {
initialChannelsMap,
);
const hiddenChannels = useAppSelector(selectHiddenChannels);
const hiddenChannelsRef = useStateRef(hiddenChannels);

const updateCount = useCallback(
debounce((view: HomeView, count: ChannelVideosCount) => {
Expand All @@ -92,21 +93,17 @@ export const ChannelVideosProvider: FC = memo(({ children }) => {
return count;
};

useDidMountEffect(() => {
// update videos count for the all view (since it is the only view where we hide channels)
const hiddenChannelsIds = hiddenChannels.map(({ id }) => id);
const count = getCount(
HomeView.All,
({ channel }) => !hiddenChannelsIds.includes(channel.id),
);
updateCount(HomeView.All, count);
}, [hiddenChannels]);

const setChannelData = (view: HomeView, data: ChannelData) => {
// save channel data per view
channelsMap.current[view].set(data.channel.id, data);
// update videos count per view
const count = getCount(view);
const hiddenChannelsIds = hiddenChannelsRef.current.map(({ id }) => id);
const count = getCount(
view,
view === HomeView.All
? ({ channel }) => !hiddenChannelsIds.includes(channel.id)
: undefined,
);
updateCount(view, count);
};

Expand Down

0 comments on commit 2a8efb7

Please sign in to comment.