diff --git a/src/components/activity/AccountActivity.tsx b/src/components/activity/AccountActivity.tsx index 0bf67ad80..3821628bc 100644 --- a/src/components/activity/AccountActivity.tsx +++ b/src/components/activity/AccountActivity.tsx @@ -12,6 +12,8 @@ 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' import { createLoadMoreActivities, NotifActivities } from './Notifications' @@ -115,9 +117,10 @@ 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 isMyAddress = useIsMyAddress(address) const getActivityCounts = useGetActivityCounts() const router = useRouter() const [activeTab, setActiveTab] = useState('posts') @@ -172,7 +175,14 @@ const OffchainAccountActivity = ({ address }: ActivitiesByAddressProps) => { return ( - + {isMyAddress ? ( +
+ + +
+ ) : ( + + )}
{(tweetsCount > 0 || haveDisplayedTweetsTab) && ( diff --git a/src/components/utils/datahub/active-staking.ts b/src/components/utils/datahub/active-staking.ts index 3cbb212bb..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 { @@ -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] @@ -392,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/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/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(),