Skip to content

Commit

Permalink
fix: added try catch
Browse files Browse the repository at this point in the history
  • Loading branch information
hrithik73 committed Mar 13, 2024
1 parent a8b7f91 commit 730f1f4
Showing 1 changed file with 35 additions and 25 deletions.
60 changes: 35 additions & 25 deletions src/segments/ViewChannels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ import ViewChannelItem from 'components/ViewChannelItem';
import LoaderSpinner, { LOADER_TYPE } from 'components/reusables/loaders/LoaderSpinner';
import UtilityHelper, { MaskedAliasChannels, MaskedChannels } from 'helpers/UtilityHelper';
import { useAccount } from 'hooks';
import { incrementPage, setChannelMeta, updateBulkSubscriptions, updateBulkUserSettings } from 'redux/slices/channelSlice';
import {
incrementPage,
setChannelMeta,
updateBulkSubscriptions,
updateBulkUserSettings,
} from 'redux/slices/channelSlice';
import { incrementStepIndex } from 'redux/slices/userJourneySlice';
import DisplayNotice from '../primaries/DisplayNotice';
import { Item } from '../primaries/SharedStyling';
Expand All @@ -36,7 +41,7 @@ function ViewChannels({ loadTeaser, playTeaser, minimal }) {
const dispatch = useDispatch();
const { userPushSDKInstance } = useSelector((state: any) => {
return state.user;
});
});
const { account, chainId } = useAccount();
const { channels, page, ZERO_ADDRESS } = useSelector((state: any) => state.channels);
const { run, stepIndex } = useSelector((state: any) => state.userJourney);
Expand Down Expand Up @@ -79,35 +84,40 @@ function ViewChannels({ loadTeaser, playTeaser, minimal }) {

// to fetch initial channels and logged in user data
const fetchInitialsChannelMeta = async () => {

let options = {
page: Math.ceil(channelsVisited / CHANNELS_PER_PAGE) || 1,
limit: CHANNELS_PER_PAGE,
}
const channelsMeta = await userPushSDKInstance.channel.list({options})
dispatch(incrementPage());
if (!channels.length) {
dispatch(setChannelMeta(channelsMeta?.channels));
}

// increases the step once the channel are loaded
if (run && stepIndex === 3) {
dispatch(incrementStepIndex());
dispatch(incrementStepIndex());
try {
let options = {
page: Math.ceil(channelsVisited / CHANNELS_PER_PAGE) || 1,
limit: CHANNELS_PER_PAGE,
};
const channelsMeta = await userPushSDKInstance.channel.list({ options });
dispatch(incrementPage());
if (!channels.length) {
dispatch(setChannelMeta(channelsMeta?.channels));
}
// increases the step once the channel are loaded
if (run && stepIndex === 3) {
dispatch(incrementStepIndex());
dispatch(incrementStepIndex());
}
setLoading(false);
} catch (error) {
console.error(error);
}

setLoading(false);
};

// load more channels when we get to the bottom of the page
const loadMoreChannelMeta = async (newPageNumber: any) => {
const startingPoint = newPageNumber * CHANNELS_PER_PAGE;
const moreChannels= await userPushSDKInstance.channel.list({
page: Math.ceil(startingPoint / CHANNELS_PER_PAGE) || 1,
limit: CHANNELS_PER_PAGE
})
dispatch(setChannelMeta([...channels, ...moreChannels?.channels]));
setMoreLoading(false);
try {
const moreChannels = await userPushSDKInstance.channel.list({
page: Math.ceil(startingPoint / CHANNELS_PER_PAGE) || 1,
limit: CHANNELS_PER_PAGE,
});
dispatch(setChannelMeta([...channels, ...moreChannels?.channels]));
setMoreLoading(false);
} catch (error) {
console.error(error);
}
};

const loadMoreSearchChannels = async () => {
Expand Down

0 comments on commit 730f1f4

Please sign in to comment.