From 9f5e1533fce916caf894519a88721a611cf9dfe3 Mon Sep 17 00:00:00 2001 From: chenhang Date: Tue, 7 Jul 2026 15:40:27 +0800 Subject: [PATCH] refactor(user): remove unused view fields --- src/app/sidebar/sidebar-screen.tsx | 2 +- src/data/dto/user/user_view.ts | 12 ------- .../__tests__/user-machine.helpers.test.ts | 36 ------------------- .../user/__tests__/user-machine.test.ts | 12 ------- src/stores/user/user-machine.helpers.ts | 24 ------------- 5 files changed, 1 insertion(+), 85 deletions(-) diff --git a/src/app/sidebar/sidebar-screen.tsx b/src/app/sidebar/sidebar-screen.tsx index dca25a19..e95ceca3 100644 --- a/src/app/sidebar/sidebar-screen.tsx +++ b/src/app/sidebar/sidebar-screen.tsx @@ -85,7 +85,7 @@ export function SidebarScreen() { sidebarState !== "guest" && user.currentUser == null; const name = user.currentUser?.username ?? FALLBACK_USERNAME; - const avatarUrl = user.avatarUrl ?? user.currentUser?.avatarUrl ?? null; + const avatarUrl = user.avatarUrl; return (
diff --git a/src/data/dto/user/user_view.ts b/src/data/dto/user/user_view.ts index 93c7146f..f47325b3 100644 --- a/src/data/dto/user/user_view.ts +++ b/src/data/dto/user/user_view.ts @@ -8,25 +8,13 @@ import { z } from "zod"; export const UserViewSchema = z.object({ id: z.string(), username: z.string(), - email: z.string(), - country: z.string(), countryCode: z.string(), - avatarUrl: z.string(), - intimacy: z.number(), - dolBalance: z.number(), creditBalance: z.number(), dailyFreeChatLimit: z.number(), - dailyFreeChatUsed: z.number(), dailyFreeChatRemaining: z.number(), dailyFreePrivateLimit: z.number(), - dailyFreePrivateUsed: z.number(), dailyFreePrivateRemaining: z.number(), - vipExpiresAt: z.string().nullable(), - relationshipStage: z.string(), - currentMood: z.string(), - isGuest: z.boolean(), isVip: z.boolean(), - voiceMinutesRemaining: z.number(), }); export type UserView = z.infer; diff --git a/src/stores/user/__tests__/user-machine.helpers.test.ts b/src/stores/user/__tests__/user-machine.helpers.test.ts index fe69be9a..289a35b4 100644 --- a/src/stores/user/__tests__/user-machine.helpers.test.ts +++ b/src/stores/user/__tests__/user-machine.helpers.test.ts @@ -10,25 +10,13 @@ describe("toView", () => { expect(toView({ id: "user-1", username: "Luna" })).toEqual({ id: "user-1", username: "Luna", - email: "", - country: "", countryCode: "", - avatarUrl: "", - intimacy: 0, - dolBalance: 0, creditBalance: 0, dailyFreeChatLimit: 0, - dailyFreeChatUsed: 0, dailyFreeChatRemaining: 0, dailyFreePrivateLimit: 0, - dailyFreePrivateUsed: 0, dailyFreePrivateRemaining: 0, - vipExpiresAt: null, - relationshipStage: "", - currentMood: "", - isGuest: false, isVip: false, - voiceMinutesRemaining: 0, }); }); @@ -37,48 +25,25 @@ describe("toView", () => { toView({ id: "user-2", username: "Elio", - email: "elio@example.com", - country: "Hong Kong", countryCode: "HK", - avatarUrl: "https://example.com/avatar.png", - intimacy: 42, dolBalance: 12, creditBalance: 120, dailyFreeChatLimit: 30, - dailyFreeChatUsed: 4, dailyFreeChatRemaining: 26, dailyFreePrivateLimit: 2, - dailyFreePrivateUsed: 1, dailyFreePrivateRemaining: 1, - vipExpiresAt: "2026-07-26T00:00:00+00:00", - relationshipStage: "close_friend", - currentMood: "playful", - isGuest: true, isVip: true, - voiceMinutesRemaining: 30, }), ).toEqual({ id: "user-2", username: "Elio", - email: "elio@example.com", - country: "Hong Kong", countryCode: "HK", - avatarUrl: "https://example.com/avatar.png", - intimacy: 42, - dolBalance: 12, creditBalance: 120, dailyFreeChatLimit: 30, - dailyFreeChatUsed: 4, dailyFreeChatRemaining: 26, dailyFreePrivateLimit: 2, - dailyFreePrivateUsed: 1, dailyFreePrivateRemaining: 1, - vipExpiresAt: "2026-07-26T00:00:00+00:00", - relationshipStage: "close_friend", - currentMood: "playful", - isGuest: true, isVip: true, - voiceMinutesRemaining: 30, }); }); @@ -93,7 +58,6 @@ describe("toView", () => { ).toMatchObject({ isVip: true, creditBalance: 120, - dolBalance: 120, }); }); }); diff --git a/src/stores/user/__tests__/user-machine.test.ts b/src/stores/user/__tests__/user-machine.test.ts index 5c8fed55..d1622565 100644 --- a/src/stores/user/__tests__/user-machine.test.ts +++ b/src/stores/user/__tests__/user-machine.test.ts @@ -12,25 +12,13 @@ function makeUser(overrides: Partial = {}): UserView { return { id: "user-1", username: "Elio Fan", - email: "user@example.com", - country: "Hong Kong", countryCode: "HK", - avatarUrl: "https://example.com/avatar.png", - intimacy: 42, - dolBalance: 7, creditBalance: 7, dailyFreeChatLimit: 30, - dailyFreeChatUsed: 0, dailyFreeChatRemaining: 30, dailyFreePrivateLimit: 2, - dailyFreePrivateUsed: 0, dailyFreePrivateRemaining: 2, - vipExpiresAt: null, - relationshipStage: "close_friend", - currentMood: "happy", - isGuest: false, isVip: false, - voiceMinutesRemaining: 12, ...overrides, }; } diff --git a/src/stores/user/user-machine.helpers.ts b/src/stores/user/user-machine.helpers.ts index fbc0f82e..799a6a6e 100644 --- a/src/stores/user/user-machine.helpers.ts +++ b/src/stores/user/user-machine.helpers.ts @@ -56,50 +56,27 @@ export interface UserFetchData { export function toView(u: { id: string; username: string; - email?: string; - country?: string; countryCode?: string; - avatarUrl?: string; - intimacy?: number; dolBalance?: number; creditBalance?: number; dailyFreeChatLimit?: number; - dailyFreeChatUsed?: number; dailyFreeChatRemaining?: number; dailyFreePrivateLimit?: number; - dailyFreePrivateUsed?: number; dailyFreePrivateRemaining?: number; - vipExpiresAt?: string | null; - relationshipStage?: string; - currentMood?: string; - isGuest?: boolean; isVip?: boolean; - voiceMinutesRemaining?: number; }): UserView { const creditBalance = u.creditBalance ?? u.dolBalance ?? 0; return { id: u.id, username: u.username, - email: u.email ?? "", - country: u.country ?? "", countryCode: u.countryCode ?? "", - avatarUrl: u.avatarUrl ?? "", - intimacy: u.intimacy ?? 0, - dolBalance: u.dolBalance ?? creditBalance, creditBalance, dailyFreeChatLimit: u.dailyFreeChatLimit ?? 0, - dailyFreeChatUsed: u.dailyFreeChatUsed ?? 0, dailyFreeChatRemaining: u.dailyFreeChatRemaining ?? 0, dailyFreePrivateLimit: u.dailyFreePrivateLimit ?? 0, - dailyFreePrivateUsed: u.dailyFreePrivateUsed ?? 0, dailyFreePrivateRemaining: u.dailyFreePrivateRemaining ?? 0, - vipExpiresAt: u.vipExpiresAt ?? null, - relationshipStage: u.relationshipStage ?? "", - currentMood: u.currentMood ?? "", - isGuest: u.isGuest ?? false, isVip: u.isVip ?? false, - voiceMinutesRemaining: u.voiceMinutesRemaining ?? 0, }; } @@ -111,7 +88,6 @@ export function applyEntitlementSnapshotToView( return { ...user, isVip: snapshot.isVip, - dolBalance: snapshot.creditBalance, creditBalance: snapshot.creditBalance, }; }