From 9d7c23d7c91d574f5428bccb91b56361e36d6a13 Mon Sep 17 00:00:00 2001 From: teodorus-nathaniel Date: Wed, 17 Jan 2024 22:52:46 +0700 Subject: [PATCH 01/11] feat: add super like stats query --- src/components/statistics/Statistics.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/components/statistics/Statistics.tsx b/src/components/statistics/Statistics.tsx index 8275d6cef..4db0a6d43 100644 --- a/src/components/statistics/Statistics.tsx +++ b/src/components/statistics/Statistics.tsx @@ -8,6 +8,7 @@ import messages from 'src/messages' import { useMyAddress } from '../auth/MyAccountsContext' import { PageContent } from '../main/PageWrapper' import { useResponsiveSize } from '../responsive/ResponsiveContext' +import { getSuperLikesStats } from '../utils/datahub/active-staking' import { Loading } from '../utils/index' import Section from '../utils/Section' import { Stats } from '../utils/Stats' @@ -165,12 +166,19 @@ export function Statistics(props: FormProps) { const load = async () => { setIsLoaded(false) - const statisticsDataArr = await Promise.all( + const statisticsDataArrPromise = Promise.all( eventArr.map(async eventName => { const event = eventName as ActivityEvent return getActivityCountStat({ event, period: constrainedPeriod }) }), ) + const superLikeDataPromise = getSuperLikesStats(constrainedPeriod) + + const [statisticsDataArr, superLikeData] = await Promise.all([ + statisticsDataArrPromise, + superLikeDataPromise, + ] as const) + console.log(statisticsDataArr, superLikeData) if (isMounted) { setData(statisticsDataArr) From 6c38da01ce009813cb1afa17069204c8073d4e59 Mon Sep 17 00:00:00 2001 From: teodorus-nathaniel Date: Wed, 17 Jan 2024 22:53:21 +0700 Subject: [PATCH 02/11] feat: add superlikes stats query --- .../utils/datahub/active-staking.ts | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/components/utils/datahub/active-staking.ts b/src/components/utils/datahub/active-staking.ts index 1dead8f3c..cd443630f 100644 --- a/src/components/utils/datahub/active-staking.ts +++ b/src/components/utils/datahub/active-staking.ts @@ -278,6 +278,36 @@ export async function getRewardHistory(address: string): Promise } } +const GET_SUPER_LIKES_STATS = gql` + query GetSuperLikesStats($from: String!, $to: String!) { + activeStakingSuperLikeCountsByDate(args: { fromDate: $from, toDate: $to }) { + count + dayUnixTimestamp + } + } +` +export async function getSuperLikesStats( + period: number, +): Promise<{ count: number; dayUnixTimestamp: number }[]> { + const { day: currentTimestamp } = getDayAndWeekTimestamp() + const currentMinusPeriod = dayjs().subtract(period, 'day').toDate() + const { day: startTimestamp } = getDayAndWeekTimestamp(currentMinusPeriod) + const res = await datahubQueryRequest< + { + activeStakingSuperLikeCountsByData: { + count: number + dayUnixTimestamp: number + }[] + }, + { from: string; to: string } + >({ + document: GET_SUPER_LIKES_STATS, + variables: { from: startTimestamp.toString(), to: currentTimestamp.toString() }, + }) + + return res.activeStakingSuperLikeCountsByData +} + // MUTATIONS export async function createSuperLike( params: DatahubParams>, From fc5769bff7bc2a23a5bdc79d13ba452f95a77450 Mon Sep 17 00:00:00 2001 From: teodorus-nathaniel Date: Thu, 18 Jan 2024 00:12:43 +0700 Subject: [PATCH 03/11] refactor: move limit props --- src/components/creators/cards/CreatorInfoCard.tsx | 6 +++++- .../utils/CollapsibleParagraph/CollapsibleParagraph.tsx | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/components/creators/cards/CreatorInfoCard.tsx b/src/components/creators/cards/CreatorInfoCard.tsx index 8d1955629..f0b602740 100644 --- a/src/components/creators/cards/CreatorInfoCard.tsx +++ b/src/components/creators/cards/CreatorInfoCard.tsx @@ -62,7 +62,11 @@ export default function CreatorInfoCard({ space, showStakeButton = true }: Creat /> - + {!stakeData?.hasStaked ? ( (shouldShowFollowButton || shouldShowStakeButton) && (
diff --git a/src/components/utils/CollapsibleParagraph/CollapsibleParagraph.tsx b/src/components/utils/CollapsibleParagraph/CollapsibleParagraph.tsx index 1ac94008e..2f92495be 100644 --- a/src/components/utils/CollapsibleParagraph/CollapsibleParagraph.tsx +++ b/src/components/utils/CollapsibleParagraph/CollapsibleParagraph.tsx @@ -7,9 +7,10 @@ import styles from './CollapsibleParagraph.module.sass' export type CollapsibleParagraphProps = ComponentProps<'span'> & { text: string + limit?: number } -export default function CollapsibleParagraph({ text, ...props }: CollapsibleParagraphProps) { +export default function CollapsibleParagraph({ text, limit, ...props }: CollapsibleParagraphProps) { const [collapseAbout, setCollapseAbout] = useState(true) const summarized = useMemo(() => summarizeMd(text), [text]) @@ -31,6 +32,7 @@ export default function CollapsibleParagraph({ text, ...props }: CollapsiblePara ) : ( From 987112b75ae7b57efdb137c1479f30661f298913 Mon Sep 17 00:00:00 2001 From: teodorus-nathaniel Date: Thu, 18 Jan 2024 00:29:40 +0700 Subject: [PATCH 04/11] feat: merge super likes stat with old likes --- src/components/statistics/Statistics.tsx | 38 ++++++++++++++++++- .../utils/datahub/active-staking.ts | 5 +-- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/components/statistics/Statistics.tsx b/src/components/statistics/Statistics.tsx index 4db0a6d43..7510bb966 100644 --- a/src/components/statistics/Statistics.tsx +++ b/src/components/statistics/Statistics.tsx @@ -8,7 +8,7 @@ import messages from 'src/messages' import { useMyAddress } from '../auth/MyAccountsContext' import { PageContent } from '../main/PageWrapper' import { useResponsiveSize } from '../responsive/ResponsiveContext' -import { getSuperLikesStats } from '../utils/datahub/active-staking' +import { getSuperLikesStats, SuperLikesStat } from '../utils/datahub/active-staking' import { Loading } from '../utils/index' import Section from '../utils/Section' import { Stats } from '../utils/Stats' @@ -178,7 +178,8 @@ export function Statistics(props: FormProps) { statisticsDataArrPromise, superLikeDataPromise, ] as const) - console.log(statisticsDataArr, superLikeData) + + combineOldLikesAndSuperLikes(statisticsDataArr, superLikeData) if (isMounted) { setData(statisticsDataArr) @@ -232,6 +233,39 @@ export function Statistics(props: FormProps) { ) } +function combineOldLikesAndSuperLikes( + stats: StatType[], + superLikesStats: SuperLikesStat[], +): StatType[] { + const likesStat = stats.find( + stat => stat.activityType === 'PostReactionCreated,CommentReactionCreated', + ) + if (!likesStat) return stats + + const totalSuperLikes = superLikesStats.reduce((acc, stat) => acc + stat.count, 0) + likesStat.totalCount += totalSuperLikes + likesStat.countByPeriod += totalSuperLikes + likesStat.todayCount = superLikesStats[superLikesStats.length - 1].count + + const allLikesMap = new Map() + likesStat.statisticsData.forEach(stat => allLikesMap.set(stat.format_date, stat)) + + superLikesStats.forEach(stat => { + const dateFormat = dayjs(stat.dayUnixTimestamp).format('YYYY-MM-DD') + const existingStat = allLikesMap.get(dateFormat) + if (existingStat) { + existingStat.count += stat.count + } else { + likesStat.statisticsData.push({ count: stat.count, format_date: dateFormat }) + } + }) + + likesStat.statisticsData.sort((a, b) => { + return dayjs(a.format_date).unix() - dayjs(b.format_date).unix() + }) + return stats +} + const getDatesBetweenDates = (startDate: Date, endDate: Date) => { let dates: string[] = [] const theDate = new Date(startDate) diff --git a/src/components/utils/datahub/active-staking.ts b/src/components/utils/datahub/active-staking.ts index cd443630f..85994352e 100644 --- a/src/components/utils/datahub/active-staking.ts +++ b/src/components/utils/datahub/active-staking.ts @@ -286,9 +286,8 @@ const GET_SUPER_LIKES_STATS = gql` } } ` -export async function getSuperLikesStats( - period: number, -): Promise<{ count: number; dayUnixTimestamp: number }[]> { +export type SuperLikesStat = { count: number; dayUnixTimestamp: number } +export async function getSuperLikesStats(period: number): Promise { const { day: currentTimestamp } = getDayAndWeekTimestamp() const currentMinusPeriod = dayjs().subtract(period, 'day').toDate() const { day: startTimestamp } = getDayAndWeekTimestamp(currentMinusPeriod) From df056490ac29fb242377ff985b6f5a268d20ae57 Mon Sep 17 00:00:00 2001 From: teodorus-nathaniel Date: Thu, 18 Jan 2024 18:30:26 +0700 Subject: [PATCH 05/11] fix: wrong logic in appending data of statistics --- src/components/statistics/Statistics.tsx | 5 ++++- src/components/utils/datahub/active-staking.ts | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/components/statistics/Statistics.tsx b/src/components/statistics/Statistics.tsx index 7510bb966..cb2873c08 100644 --- a/src/components/statistics/Statistics.tsx +++ b/src/components/statistics/Statistics.tsx @@ -179,6 +179,8 @@ export function Statistics(props: FormProps) { superLikeDataPromise, ] as const) + console.log(superLikeData) + combineOldLikesAndSuperLikes(statisticsDataArr, superLikeData) if (isMounted) { @@ -240,6 +242,7 @@ function combineOldLikesAndSuperLikes( const likesStat = stats.find( stat => stat.activityType === 'PostReactionCreated,CommentReactionCreated', ) + console.log(likesStat, stats) if (!likesStat) return stats const totalSuperLikes = superLikesStats.reduce((acc, stat) => acc + stat.count, 0) @@ -251,7 +254,7 @@ function combineOldLikesAndSuperLikes( likesStat.statisticsData.forEach(stat => allLikesMap.set(stat.format_date, stat)) superLikesStats.forEach(stat => { - const dateFormat = dayjs(stat.dayUnixTimestamp).format('YYYY-MM-DD') + const dateFormat = dayjs(stat.dayUnixTimestamp * 1000).format('YYYY-MM-DD') const existingStat = allLikesMap.get(dateFormat) if (existingStat) { existingStat.count += stat.count diff --git a/src/components/utils/datahub/active-staking.ts b/src/components/utils/datahub/active-staking.ts index 85994352e..15313ae0a 100644 --- a/src/components/utils/datahub/active-staking.ts +++ b/src/components/utils/datahub/active-staking.ts @@ -293,7 +293,7 @@ export async function getSuperLikesStats(period: number): Promise Date: Thu, 18 Jan 2024 18:35:16 +0700 Subject: [PATCH 06/11] fix: alignment of reward stat --- src/components/posts/view-post/helpers.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/posts/view-post/helpers.tsx b/src/components/posts/view-post/helpers.tsx index 2a2787e36..5e814d780 100644 --- a/src/components/posts/view-post/helpers.tsx +++ b/src/components/posts/view-post/helpers.tsx @@ -327,7 +327,7 @@ export const PostActionsPanel: FC = props => { {preview && }
- + {/* */} ) From 7a5c1281f2cd79e18d2e47fc9e19904f979b49d9 Mon Sep 17 00:00:00 2001 From: teodorus-nathaniel Date: Thu, 18 Jan 2024 18:41:56 +0700 Subject: [PATCH 07/11] chore: remove logs --- src/components/statistics/Statistics.tsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/components/statistics/Statistics.tsx b/src/components/statistics/Statistics.tsx index cb2873c08..4c376527f 100644 --- a/src/components/statistics/Statistics.tsx +++ b/src/components/statistics/Statistics.tsx @@ -179,8 +179,6 @@ export function Statistics(props: FormProps) { superLikeDataPromise, ] as const) - console.log(superLikeData) - combineOldLikesAndSuperLikes(statisticsDataArr, superLikeData) if (isMounted) { @@ -242,7 +240,6 @@ function combineOldLikesAndSuperLikes( const likesStat = stats.find( stat => stat.activityType === 'PostReactionCreated,CommentReactionCreated', ) - console.log(likesStat, stats) if (!likesStat) return stats const totalSuperLikes = superLikesStats.reduce((acc, stat) => acc + stat.count, 0) From 6c43a472dcaef554acc328327c8248ca186ad6b4 Mon Sep 17 00:00:00 2001 From: teodorus-nathaniel Date: Thu, 18 Jan 2024 18:49:47 +0700 Subject: [PATCH 08/11] feat: add back stats button in sidebar --- src/layout/SideMenuItems.tsx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/layout/SideMenuItems.tsx b/src/layout/SideMenuItems.tsx index 324ca2a8b..682726e2e 100644 --- a/src/layout/SideMenuItems.tsx +++ b/src/layout/SideMenuItems.tsx @@ -3,6 +3,7 @@ import { BugOutlined, BulbOutlined, GlobalOutlined, + LineChartOutlined, // LineChartOutlined, LinkOutlined, NotificationOutlined, @@ -55,11 +56,11 @@ export const DefaultMenu: MenuItem[] = [ // page: [ polkaStatsUrl ], // icon: , // }, - // { - // name: 'Statistics', - // page: ['/stats'], - // icon: , - // }, + { + name: 'Statistics', + page: ['/stats'], + icon: , + }, Divider, { name: config.appName, From 6351f11d8daafb929a545d69d606303d79fe92e6 Mon Sep 17 00:00:00 2001 From: teodorus-nathaniel Date: Thu, 18 Jan 2024 19:52:11 +0700 Subject: [PATCH 09/11] chore: reorder stats card and hide post shared --- src/components/statistics/Statistics.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/statistics/Statistics.tsx b/src/components/statistics/Statistics.tsx index 4c376527f..a0cc52ab3 100644 --- a/src/components/statistics/Statistics.tsx +++ b/src/components/statistics/Statistics.tsx @@ -27,10 +27,10 @@ export type ActivityEvent = export const eventArr = [ 'PostReactionCreated,CommentReactionCreated', 'PostCreated', + 'CommentCreated,CommentReplyCreated', 'SpaceCreated', 'SpaceFollowed', - 'PostShared,CommentShared', - 'CommentCreated,CommentReplyCreated', + // 'PostShared,CommentShared', 'AccountFollowed', ] From 228aaeef3ba72941f6f0cc18c50379e9ed3c0f34 Mon Sep 17 00:00:00 2001 From: teodorus-nathaniel Date: Thu, 18 Jan 2024 21:28:51 +0700 Subject: [PATCH 10/11] feat: integrate total super likes data --- src/components/statistics/Statistics.tsx | 10 ++++---- .../utils/datahub/active-staking.ts | 25 +++++++++++++------ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/components/statistics/Statistics.tsx b/src/components/statistics/Statistics.tsx index a0cc52ab3..af93f0a39 100644 --- a/src/components/statistics/Statistics.tsx +++ b/src/components/statistics/Statistics.tsx @@ -235,22 +235,22 @@ export function Statistics(props: FormProps) { function combineOldLikesAndSuperLikes( stats: StatType[], - superLikesStats: SuperLikesStat[], + superLikesStats: SuperLikesStat, ): StatType[] { const likesStat = stats.find( stat => stat.activityType === 'PostReactionCreated,CommentReactionCreated', ) if (!likesStat) return stats - const totalSuperLikes = superLikesStats.reduce((acc, stat) => acc + stat.count, 0) - likesStat.totalCount += totalSuperLikes + const totalSuperLikes = superLikesStats.data.reduce((acc, stat) => acc + stat.count, 0) + likesStat.totalCount += superLikesStats.total likesStat.countByPeriod += totalSuperLikes - likesStat.todayCount = superLikesStats[superLikesStats.length - 1].count + likesStat.todayCount = superLikesStats.data[superLikesStats.data.length - 1].count const allLikesMap = new Map() likesStat.statisticsData.forEach(stat => allLikesMap.set(stat.format_date, stat)) - superLikesStats.forEach(stat => { + superLikesStats.data.forEach(stat => { const dateFormat = dayjs(stat.dayUnixTimestamp * 1000).format('YYYY-MM-DD') const existingStat = allLikesMap.get(dateFormat) if (existingStat) { diff --git a/src/components/utils/datahub/active-staking.ts b/src/components/utils/datahub/active-staking.ts index 15313ae0a..6d60d2476 100644 --- a/src/components/utils/datahub/active-staking.ts +++ b/src/components/utils/datahub/active-staking.ts @@ -281,22 +281,28 @@ export async function getRewardHistory(address: string): Promise const GET_SUPER_LIKES_STATS = gql` query GetSuperLikesStats($from: String!, $to: String!) { activeStakingSuperLikeCountsByDate(args: { fromDate: $from, toDate: $to }) { - count - dayUnixTimestamp + byDate { + count + dayUnixTimestamp + } + total } } ` -export type SuperLikesStat = { count: number; dayUnixTimestamp: number } -export async function getSuperLikesStats(period: number): Promise { +export type SuperLikesStat = { total: number; data: { count: number; dayUnixTimestamp: number }[] } +export async function getSuperLikesStats(period: number): Promise { const { day: currentTimestamp } = getDayAndWeekTimestamp() const currentMinusPeriod = dayjs().subtract(period, 'day').toDate() const { day: startTimestamp } = getDayAndWeekTimestamp(currentMinusPeriod) const res = await datahubQueryRequest< { activeStakingSuperLikeCountsByDate: { - count: number - dayUnixTimestamp: number - }[] + byDate: { + count: number + dayUnixTimestamp: number + }[] + total: number + } }, { from: string; to: string } >({ @@ -304,7 +310,10 @@ export async function getSuperLikesStats(period: number): Promise Date: Thu, 18 Jan 2024 21:32:51 +0700 Subject: [PATCH 11/11] fix: add total arg to fetching of super likes stat --- src/components/utils/datahub/active-staking.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/utils/datahub/active-staking.ts b/src/components/utils/datahub/active-staking.ts index 6d60d2476..9eac1fd8a 100644 --- a/src/components/utils/datahub/active-staking.ts +++ b/src/components/utils/datahub/active-staking.ts @@ -280,7 +280,7 @@ export async function getRewardHistory(address: string): Promise const GET_SUPER_LIKES_STATS = gql` query GetSuperLikesStats($from: String!, $to: String!) { - activeStakingSuperLikeCountsByDate(args: { fromDate: $from, toDate: $to }) { + activeStakingSuperLikeCountsByDate(args: { fromDate: $from, toDate: $to, total: true }) { byDate { count dayUnixTimestamp