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

Migrated getChannel to Push SDK #1450

Merged
merged 2 commits into from
Mar 13, 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
72 changes: 37 additions & 35 deletions src/segments/ViewChannels.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// React + Web3 Essentials
import React, { useContext, useEffect, useRef, useState } from 'react';
import React, {useEffect, useState } from 'react';

// External Packages
import { AiOutlineSearch } from 'react-icons/ai';
Expand All @@ -12,24 +12,20 @@ import ChainsSelect from 'components/ChainsSelect';
import Faucets from 'components/Faucets';
import ViewChannelItem from 'components/ViewChannelItem';
import LoaderSpinner, { LOADER_TYPE } from 'components/reusables/loaders/LoaderSpinner';
import { convertAddressToAddrCaip } from 'helpers/CaipHelper';
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 { getChannels, getChannelsSearch } from 'services'; // Api Services
import DisplayNotice from '../primaries/DisplayNotice';
import { Item, ItemH } from '../primaries/SharedStyling';
import { Item } from '../primaries/SharedStyling';

// Internal Configs
import UpdateChannelTooltipContent from 'components/UpdateChannelTooltipContent';
import Tooltip from 'components/reusables/tooltip/Tooltip';
import { appConfig } from 'config';
import { AppContext } from 'contexts/AppContext';
import InfoImage from "../assets/info.svg";

// import Tooltip from './reusables/tooltip/Tooltip';
// import UpdateChannelTooltipContent from './UpdateChannelTooltipContent';

// Constants
const CHANNELS_PER_PAGE = 10; //pagination parameter which indicates how many channels to return over one iteration
Expand All @@ -45,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 @@ -88,34 +84,40 @@ function ViewChannels({ loadTeaser, playTeaser, minimal }) {

// to fetch initial channels and logged in user data
const fetchInitialsChannelMeta = async () => {
// fetch the meta of the first `CHANNELS_PER_PAGE` channels
const channelsMeta = await getChannels({
page: Math.ceil(channelsVisited / CHANNELS_PER_PAGE) || 1,
limit: CHANNELS_PER_PAGE,
});
dispatch(incrementPage());
if (!channels.length) {
dispatch(setChannelMeta(channelsMeta));
}

// 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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add try-catch in this function as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added !

const moreChannels = await getChannels({
page: Math.ceil(startingPoint / CHANNELS_PER_PAGE) || 1,
limit: CHANNELS_PER_PAGE,
});
dispatch(setChannelMeta([...channels, ...moreChannels]));
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
23 changes: 0 additions & 23 deletions src/services/channels/getChannels.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/services/channels/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from "./getChannelDelegates";
export * from "./getChannels";
export * from "./getChannelsSearch";
export * from "./getChannel";
Loading