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

DPLT-1053 Feat: implement Following feed #138

Merged
merged 12 commits into from
Jul 22, 2023
Merged

DPLT-1053 Feat: implement Following feed #138

merged 12 commits into from
Jul 22, 2023

Conversation

roshaans
Copy link
Contributor

@roshaans roshaans commented Jul 20, 2023

Implements the Following Feed.

You can access the feed here: https://www.near.org/dev-queryapi.dataplatform.near/widget/QueryApi.dev.Feed

@@ -2,12 +2,24 @@ const GRAPHQL_ENDPOINT =
"https://near-queryapi.api.pagoda.co";
const APP_OWNER = "dataplatform.near";

let accountsFollowing = undefined;

Copy link
Contributor Author

@roshaans roshaans Jul 20, 2023

Choose a reason for hiding this comment

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

We fetch the followers inside a parent widget to prevent rendering issues.

@@ -23,55 +17,6 @@ const Subheading = styled.h2`
outline: none;
`;

let querySortFilter = "";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Logic to fetch posts happens inside of parent widget now: QueryAPI.Examples.Feed.Posts

)}

<FeedWrapper>
<Widget src={`${APP_OWNER}/widget/QueryApi.Examples.Feed`} props={{ hasMore, loadMorePosts, posts: state.posts}} />
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We pass loadMorePosts down to the Feed widget so that the InfiniteScroll component can call it.

`;

const hasMore = state.postsCountLeft != state.posts.length

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a bit hacky. It was a pain to get this to work correctly when switching tabs from all to following while making sure we do not send more than one fetch request which would create duplicate posts in the feed.

We first load the all feed regardless during init. After doing so, we fetch following feed.


function selectTab(selectedTab) {
Storage.privateSet("selectedTab", selectedTab);
State.update({
Copy link
Contributor Author

@roshaans roshaans Jul 20, 2023

Choose a reason for hiding this comment

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

whenever we switch tabs, reset the state and then refetch

}

const loadMorePosts = () => {
const queryName = state.selectedTab == "following" && accountsFollowing ? "GetFollowingPosts" : "GetPostsQuery"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

figure out what query to execute.

content
}
}
dataplatform_near_social_feed_posts_aggregate(order_by: [${querySortOption} { block_height: desc }], offset: $offset){
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we pass the same filter to the aggreagate table to figure out how many more posts are left with this query to load.

@roshaans roshaans marked this pull request as ready for review July 20, 2023 18:54
@roshaans roshaans requested a review from a team as a code owner July 20, 2023 18:54
@roshaans roshaans force-pushed the feat/following-feed branch from c85457e to b532ad9 Compare July 20, 2023 19:10
fetchGraphQL(createQuery(sortOption, type), queryName, {
offset: state.posts.length,
}).then((result) => {
if (result.status === 200) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You also need to check if result.body.data does not contain the error key. GraphQL will return 200 even if there are errors.

postsCountLeft: 0,
selectedTab
});
loadMorePosts()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does State.update() trigger a re-render? If so, then this might not be needed. If we re-render with 0 posts, <InfiniteScroll /> should call loadMorePosts() itself?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just tested it. It loads on initial page load, but then when we switch tabs, it does not trigger loadMorePosts() again.

@roshaans roshaans requested a review from morgsmccauley July 21, 2023 16:16
@roshaans roshaans merged commit 20d2aaa into main Jul 22, 2023
@roshaans roshaans deleted the feat/following-feed branch July 22, 2023 06:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants