mirror of
https://github.com/hicccc77/WeFlow.git
synced 2026-03-25 07:16:51 +00:00
feat(sns): show my post count in overview stats
This commit is contained in:
@@ -25,6 +25,7 @@ interface Contact {
|
||||
interface SnsOverviewStats {
|
||||
totalPosts: number
|
||||
totalFriends: number
|
||||
myPosts: number | null
|
||||
earliestTime: number | null
|
||||
latestTime: number | null
|
||||
}
|
||||
@@ -39,6 +40,7 @@ export default function SnsPage() {
|
||||
const [overviewStats, setOverviewStats] = useState<SnsOverviewStats>({
|
||||
totalPosts: 0,
|
||||
totalFriends: 0,
|
||||
myPosts: null,
|
||||
earliestTime: null,
|
||||
latestTime: null
|
||||
})
|
||||
@@ -196,6 +198,9 @@ export default function SnsPage() {
|
||||
setOverviewStats({
|
||||
totalPosts: cachedTotalPosts,
|
||||
totalFriends: cachedTotalFriends,
|
||||
myPosts: typeof cachedOverview.myPosts === 'number' && Number.isFinite(cachedOverview.myPosts) && cachedOverview.myPosts >= 0
|
||||
? Math.floor(cachedOverview.myPosts)
|
||||
: null,
|
||||
earliestTime: cachedOverview.earliestTime ?? null,
|
||||
latestTime: cachedOverview.latestTime ?? null
|
||||
})
|
||||
@@ -234,6 +239,9 @@ export default function SnsPage() {
|
||||
|
||||
const totalPosts = Math.max(0, Number(statsResult.data.totalPosts || 0))
|
||||
const totalFriends = Math.max(0, Number(statsResult.data.totalFriends || 0))
|
||||
const myPosts = (typeof statsResult.data.myPosts === 'number' && Number.isFinite(statsResult.data.myPosts) && statsResult.data.myPosts >= 0)
|
||||
? Math.floor(statsResult.data.myPosts)
|
||||
: null
|
||||
let earliestTime: number | null = null
|
||||
let latestTime: number | null = null
|
||||
|
||||
@@ -256,6 +264,7 @@ export default function SnsPage() {
|
||||
const nextOverviewStats = {
|
||||
totalPosts,
|
||||
totalFriends,
|
||||
myPosts,
|
||||
earliestTime,
|
||||
latestTime
|
||||
}
|
||||
@@ -279,7 +288,8 @@ export default function SnsPage() {
|
||||
if (overviewStatsStatus === 'loading') {
|
||||
return '统计中...'
|
||||
}
|
||||
return `共 ${overviewStats.totalPosts} 条 | ${formatDateOnly(overviewStats.earliestTime)} ~ ${formatDateOnly(overviewStats.latestTime)} | ${overviewStats.totalFriends} 位好友`
|
||||
const myPostsLabel = overviewStats.myPosts === null ? '--' : String(overviewStats.myPosts)
|
||||
return `共 ${overviewStats.totalPosts} 条 | 我的朋友圈 ${myPostsLabel} 条 | ${formatDateOnly(overviewStats.earliestTime)} ~ ${formatDateOnly(overviewStats.latestTime)} | ${overviewStats.totalFriends} 位好友`
|
||||
}
|
||||
|
||||
const loadPosts = useCallback(async (options: { reset?: boolean, direction?: 'older' | 'newer' } = {}) => {
|
||||
|
||||
@@ -469,6 +469,7 @@ export interface ExportSnsStatsCacheItem {
|
||||
export interface SnsPageOverviewCache {
|
||||
totalPosts: number
|
||||
totalFriends: number
|
||||
myPosts: number | null
|
||||
earliestTime: number | null
|
||||
latestTime: number | null
|
||||
}
|
||||
@@ -610,12 +611,18 @@ export async function getSnsPageCache(scopeKey: string): Promise<SnsPageCacheIte
|
||||
if (typeof v === 'number' && Number.isFinite(v) && v > 0) return Math.floor(v)
|
||||
return null
|
||||
}
|
||||
const normalizeNullableCount = (v: unknown) => {
|
||||
if (v === null || v === undefined) return null
|
||||
if (typeof v === 'number' && Number.isFinite(v) && v >= 0) return Math.floor(v)
|
||||
return null
|
||||
}
|
||||
|
||||
return {
|
||||
updatedAt: typeof raw.updatedAt === 'number' && Number.isFinite(raw.updatedAt) ? raw.updatedAt : 0,
|
||||
overviewStats: {
|
||||
totalPosts: Math.max(0, normalizeNumber(overviewObj.totalPosts)),
|
||||
totalFriends: Math.max(0, normalizeNumber(overviewObj.totalFriends)),
|
||||
myPosts: normalizeNullableCount(overviewObj.myPosts),
|
||||
earliestTime: normalizeNullableTimestamp(overviewObj.earliestTime),
|
||||
latestTime: normalizeNullableTimestamp(overviewObj.latestTime)
|
||||
},
|
||||
@@ -639,12 +646,18 @@ export async function setSnsPageCache(
|
||||
if (typeof v === 'number' && Number.isFinite(v) && v > 0) return Math.floor(v)
|
||||
return null
|
||||
}
|
||||
const normalizeNullableCount = (v: unknown) => {
|
||||
if (v === null || v === undefined) return null
|
||||
if (typeof v === 'number' && Number.isFinite(v) && v >= 0) return Math.floor(v)
|
||||
return null
|
||||
}
|
||||
|
||||
map[scopeKey] = {
|
||||
updatedAt: Date.now(),
|
||||
overviewStats: {
|
||||
totalPosts: normalizeNumber(payload?.overviewStats?.totalPosts),
|
||||
totalFriends: normalizeNumber(payload?.overviewStats?.totalFriends),
|
||||
myPosts: normalizeNullableCount(payload?.overviewStats?.myPosts),
|
||||
earliestTime: normalizeNullableTimestamp(payload?.overviewStats?.earliestTime),
|
||||
latestTime: normalizeNullableTimestamp(payload?.overviewStats?.latestTime)
|
||||
},
|
||||
|
||||
4
src/types/electron.d.ts
vendored
4
src/types/electron.d.ts
vendored
@@ -730,8 +730,8 @@ export interface ElectronAPI {
|
||||
selectExportDir: () => Promise<{ canceled: boolean; filePath?: string }>
|
||||
getSnsUsernames: () => Promise<{ success: boolean; usernames?: string[]; error?: string }>
|
||||
getUserPostCounts: () => Promise<{ success: boolean; data?: Record<string, number>; error?: string }>
|
||||
getExportStatsFast: () => Promise<{ success: boolean; data?: { totalPosts: number; totalFriends: number }; error?: string }>
|
||||
getExportStats: () => Promise<{ success: boolean; data?: { totalPosts: number; totalFriends: number }; error?: string }>
|
||||
getExportStatsFast: () => Promise<{ success: boolean; data?: { totalPosts: number; totalFriends: number; myPosts: number | null }; error?: string }>
|
||||
getExportStats: () => Promise<{ success: boolean; data?: { totalPosts: number; totalFriends: number; myPosts: number | null }; error?: string }>
|
||||
installBlockDeleteTrigger: () => Promise<{ success: boolean; alreadyInstalled?: boolean; error?: string }>
|
||||
uninstallBlockDeleteTrigger: () => Promise<{ success: boolean; error?: string }>
|
||||
checkBlockDeleteTrigger: () => Promise<{ success: boolean; installed?: boolean; error?: string }>
|
||||
|
||||
Reference in New Issue
Block a user