From b9076425eebb92679e94ac93ac578f5b57d928ed Mon Sep 17 00:00:00 2001 From: teodorus-nathaniel Date: Tue, 30 Jan 2024 18:38:36 +0700 Subject: [PATCH 1/5] feat: add write something block to activity page --- src/components/activity/AccountActivity.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/components/activity/AccountActivity.tsx b/src/components/activity/AccountActivity.tsx index 0bf67ad80..458bdb5c6 100644 --- a/src/components/activity/AccountActivity.tsx +++ b/src/components/activity/AccountActivity.tsx @@ -12,6 +12,7 @@ import { useGetReactionActivities, useGetTweetActivities, } from 'src/graphql/hooks' +import WriteSomething from '../posts/WriteSomething' import { Loading } from '../utils' import { createLoadMorePosts, FeedActivities } from './FeedActivities' import { createLoadMoreActivities, NotifActivities } from './Notifications' @@ -115,7 +116,7 @@ const activityTabs = [ 'spaces', 'all', ] as const -type ActivityTab = typeof activityTabs[number] +type ActivityTab = (typeof activityTabs)[number] const getTab = (tab: ActivityTab) => tab const OffchainAccountActivity = ({ address }: ActivitiesByAddressProps) => { const getActivityCounts = useGetActivityCounts() @@ -172,7 +173,10 @@ const OffchainAccountActivity = ({ address }: ActivitiesByAddressProps) => { return ( - +
+ + +
{(tweetsCount > 0 || haveDisplayedTweetsTab) && ( From 013cb7c30671845f911dc929b016fce250e5c495 Mon Sep 17 00:00:00 2001 From: teodorus-nathaniel Date: Tue, 30 Jan 2024 19:27:43 +0700 Subject: [PATCH 2/5] fix: make some queries use fetch policy network only --- src/components/utils/datahub/active-staking.ts | 3 +++ src/components/utils/datahub/utils.ts | 4 ++++ src/graphql/client.ts | 7 +++++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/components/utils/datahub/active-staking.ts b/src/components/utils/datahub/active-staking.ts index 3cbb212bb..0a9f1c2b7 100644 --- a/src/components/utils/datahub/active-staking.ts +++ b/src/components/utils/datahub/active-staking.ts @@ -49,6 +49,7 @@ export async function getSuperLikeCounts(postIds: string[]): Promise({ query: GET_SUPER_LIKE_COUNTS, variables: { postIds }, + fetchPolicy: 'network-only', }) const resultMap = new Map() @@ -124,6 +125,7 @@ export async function getAddressLikeCountToPosts( >({ query: GET_ADDRESS_LIKE_COUNT_TO_POSTS, variables: { postIds, address }, + fetchPolicy: 'network-only', }) const resultMap = new Map() @@ -212,6 +214,7 @@ export async function getRewardReport(address: string): Promise { >({ query: GET_REWARD_REPORT, variables: { address, ...getDayAndWeekTimestamp() }, + fetchPolicy: 'network-only', }) const weekReward = res.data.activeStakingRewardsByWeek?.[0] diff --git a/src/components/utils/datahub/utils.ts b/src/components/utils/datahub/utils.ts index e643ec0b0..569692c04 100644 --- a/src/components/utils/datahub/utils.ts +++ b/src/components/utils/datahub/utils.ts @@ -19,6 +19,7 @@ import ws from 'isomorphic-ws' import { datahubQueryUrl, datahubSubscriptionUrl } from 'src/config/env' import { createApolloClient } from 'src/graphql/client' import { wait } from 'src/utils/promise' +import { isServerSide } from '..' dayjs.extend(utc) dayjs.extend(isoWeek) @@ -53,6 +54,9 @@ export function datahubQueryRequest( config: QueryOptions, ) { const client = getApolloClient() + if (isServerSide()) { + config.fetchPolicy = 'no-cache' + } return client.query(config) } diff --git a/src/graphql/client.ts b/src/graphql/client.ts index 63f86b556..e2f8adb81 100644 --- a/src/graphql/client.ts +++ b/src/graphql/client.ts @@ -12,8 +12,11 @@ export function getApolloClient() { return apolloClient } -export const createApolloClient = (graphqlUrl: string): ApolloClient => { - let config: DefaultOptions = {} +export const createApolloClient = ( + graphqlUrl: string, + defaultOptions?: DefaultOptions, +): ApolloClient => { + let config: DefaultOptions = defaultOptions ?? {} if (isServerSide()) { config = { query: { From 433e7e40e14ddc8282aa6a586be313305dfb9591 Mon Sep 17 00:00:00 2001 From: teodorus-nathaniel Date: Tue, 30 Jan 2024 00:51:22 +0700 Subject: [PATCH 3/5] refactor: only refetch super like count if its already fetched before --- src/components/utils/datahub/active-staking.ts | 4 ++-- .../features/activeStaking/superLikeCountsSlice.ts | 13 ++++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/components/utils/datahub/active-staking.ts b/src/components/utils/datahub/active-staking.ts index 0a9f1c2b7..b5a7a1b3c 100644 --- a/src/components/utils/datahub/active-staking.ts +++ b/src/components/utils/datahub/active-staking.ts @@ -17,7 +17,7 @@ import { PostRewards } from 'src/rtk/features/activeStaking/postRewardSlice' import { RewardHistory } from 'src/rtk/features/activeStaking/rewardHistorySlice' import { fetchRewardReport, RewardReport } from 'src/rtk/features/activeStaking/rewardReportSlice' import { - fetchSuperLikeCounts, + invalidateSuperLikeCounts, SuperLikeCount, } from 'src/rtk/features/activeStaking/superLikeCountsSlice' import { @@ -395,7 +395,7 @@ async function processSubscriptionEvent( const dispatch = getStoreDispatcher() if (!dispatch) throw new Error('Dispatcher not exist') - dispatch(fetchSuperLikeCounts({ postIds: [post.persistentId], reload: true })) + dispatch(invalidateSuperLikeCounts({ postId: post.persistentId })) if (staker.id === myAddress) { dispatch(fetchRewardReport({ address: myAddress, reload: true })) dispatch( diff --git a/src/rtk/features/activeStaking/superLikeCountsSlice.ts b/src/rtk/features/activeStaking/superLikeCountsSlice.ts index c0c2d8910..ce1cd58e6 100644 --- a/src/rtk/features/activeStaking/superLikeCountsSlice.ts +++ b/src/rtk/features/activeStaking/superLikeCountsSlice.ts @@ -1,5 +1,6 @@ -import { createEntityAdapter, createSlice } from '@reduxjs/toolkit' +import { createAsyncThunk, createEntityAdapter, createSlice } from '@reduxjs/toolkit' import { getSuperLikeCounts } from 'src/components/utils/datahub/active-staking' +import { ThunkApiConfig } from 'src/rtk/app/helpers' import { RootState } from 'src/rtk/app/rootReducer' import { createSimpleManyFetchWrapper } from 'src/rtk/app/wrappers' @@ -35,6 +36,16 @@ export const fetchSuperLikeCounts = createSimpleManyFetchWrapper< }, }) +export const invalidateSuperLikeCounts = createAsyncThunk( + `${sliceName}/invalidate`, + async ({ postId }, { getState, dispatch }) => { + const state = selectPostSuperLikeCount(getState(), postId) + if (!state) return + + await dispatch(fetchSuperLikeCounts({ postIds: [postId], reload: true })) + }, +) + const slice = createSlice({ name: sliceName, initialState: adapter.getInitialState(), From ef44c93d9e5f9cb17448b97301eaf2d9e15a25b7 Mon Sep 17 00:00:00 2001 From: teodorus-nathaniel Date: Tue, 30 Jan 2024 19:34:23 +0700 Subject: [PATCH 4/5] fix: only show write something block if its your activity page --- src/components/activity/AccountActivity.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/components/activity/AccountActivity.tsx b/src/components/activity/AccountActivity.tsx index 458bdb5c6..3821628bc 100644 --- a/src/components/activity/AccountActivity.tsx +++ b/src/components/activity/AccountActivity.tsx @@ -12,6 +12,7 @@ import { useGetReactionActivities, useGetTweetActivities, } from 'src/graphql/hooks' +import { useIsMyAddress } from '../auth/MyAccountsContext' import WriteSomething from '../posts/WriteSomething' import { Loading } from '../utils' import { createLoadMorePosts, FeedActivities } from './FeedActivities' @@ -119,6 +120,7 @@ const activityTabs = [ type ActivityTab = (typeof activityTabs)[number] const getTab = (tab: ActivityTab) => tab const OffchainAccountActivity = ({ address }: ActivitiesByAddressProps) => { + const isMyAddress = useIsMyAddress(address) const getActivityCounts = useGetActivityCounts() const router = useRouter() const [activeTab, setActiveTab] = useState('posts') @@ -173,10 +175,14 @@ const OffchainAccountActivity = ({ address }: ActivitiesByAddressProps) => { return ( -
- + {isMyAddress ? ( +
+ + +
+ ) : ( -
+ )}
{(tweetsCount > 0 || haveDisplayedTweetsTab) && ( From 622dacb7dc108d516872eb0f38106b1b457b3c6a Mon Sep 17 00:00:00 2001 From: teodorus-nathaniel Date: Tue, 30 Jan 2024 19:36:01 +0700 Subject: [PATCH 5/5] chore: revert unnecessary change --- src/graphql/client.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/graphql/client.ts b/src/graphql/client.ts index e2f8adb81..63f86b556 100644 --- a/src/graphql/client.ts +++ b/src/graphql/client.ts @@ -12,11 +12,8 @@ export function getApolloClient() { return apolloClient } -export const createApolloClient = ( - graphqlUrl: string, - defaultOptions?: DefaultOptions, -): ApolloClient => { - let config: DefaultOptions = defaultOptions ?? {} +export const createApolloClient = (graphqlUrl: string): ApolloClient => { + let config: DefaultOptions = {} if (isServerSide()) { config = { query: {