refactor(user): remove unused view fields
This commit is contained in:
@@ -85,7 +85,7 @@ export function SidebarScreen() {
|
|||||||
sidebarState !== "guest" && user.currentUser == null;
|
sidebarState !== "guest" && user.currentUser == null;
|
||||||
|
|
||||||
const name = user.currentUser?.username ?? FALLBACK_USERNAME;
|
const name = user.currentUser?.username ?? FALLBACK_USERNAME;
|
||||||
const avatarUrl = user.avatarUrl ?? user.currentUser?.avatarUrl ?? null;
|
const avatarUrl = user.avatarUrl;
|
||||||
return (
|
return (
|
||||||
<MobileShell background="#fcf3f4">
|
<MobileShell background="#fcf3f4">
|
||||||
<div className={styles.shell}>
|
<div className={styles.shell}>
|
||||||
|
|||||||
@@ -8,25 +8,13 @@ import { z } from "zod";
|
|||||||
export const UserViewSchema = z.object({
|
export const UserViewSchema = z.object({
|
||||||
id: z.string(),
|
id: z.string(),
|
||||||
username: z.string(),
|
username: z.string(),
|
||||||
email: z.string(),
|
|
||||||
country: z.string(),
|
|
||||||
countryCode: z.string(),
|
countryCode: z.string(),
|
||||||
avatarUrl: z.string(),
|
|
||||||
intimacy: z.number(),
|
|
||||||
dolBalance: z.number(),
|
|
||||||
creditBalance: z.number(),
|
creditBalance: z.number(),
|
||||||
dailyFreeChatLimit: z.number(),
|
dailyFreeChatLimit: z.number(),
|
||||||
dailyFreeChatUsed: z.number(),
|
|
||||||
dailyFreeChatRemaining: z.number(),
|
dailyFreeChatRemaining: z.number(),
|
||||||
dailyFreePrivateLimit: z.number(),
|
dailyFreePrivateLimit: z.number(),
|
||||||
dailyFreePrivateUsed: z.number(),
|
|
||||||
dailyFreePrivateRemaining: z.number(),
|
dailyFreePrivateRemaining: z.number(),
|
||||||
vipExpiresAt: z.string().nullable(),
|
|
||||||
relationshipStage: z.string(),
|
|
||||||
currentMood: z.string(),
|
|
||||||
isGuest: z.boolean(),
|
|
||||||
isVip: z.boolean(),
|
isVip: z.boolean(),
|
||||||
voiceMinutesRemaining: z.number(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export type UserView = z.infer<typeof UserViewSchema>;
|
export type UserView = z.infer<typeof UserViewSchema>;
|
||||||
|
|||||||
@@ -10,25 +10,13 @@ describe("toView", () => {
|
|||||||
expect(toView({ id: "user-1", username: "Luna" })).toEqual({
|
expect(toView({ id: "user-1", username: "Luna" })).toEqual({
|
||||||
id: "user-1",
|
id: "user-1",
|
||||||
username: "Luna",
|
username: "Luna",
|
||||||
email: "",
|
|
||||||
country: "",
|
|
||||||
countryCode: "",
|
countryCode: "",
|
||||||
avatarUrl: "",
|
|
||||||
intimacy: 0,
|
|
||||||
dolBalance: 0,
|
|
||||||
creditBalance: 0,
|
creditBalance: 0,
|
||||||
dailyFreeChatLimit: 0,
|
dailyFreeChatLimit: 0,
|
||||||
dailyFreeChatUsed: 0,
|
|
||||||
dailyFreeChatRemaining: 0,
|
dailyFreeChatRemaining: 0,
|
||||||
dailyFreePrivateLimit: 0,
|
dailyFreePrivateLimit: 0,
|
||||||
dailyFreePrivateUsed: 0,
|
|
||||||
dailyFreePrivateRemaining: 0,
|
dailyFreePrivateRemaining: 0,
|
||||||
vipExpiresAt: null,
|
|
||||||
relationshipStage: "",
|
|
||||||
currentMood: "",
|
|
||||||
isGuest: false,
|
|
||||||
isVip: false,
|
isVip: false,
|
||||||
voiceMinutesRemaining: 0,
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -37,48 +25,25 @@ describe("toView", () => {
|
|||||||
toView({
|
toView({
|
||||||
id: "user-2",
|
id: "user-2",
|
||||||
username: "Elio",
|
username: "Elio",
|
||||||
email: "elio@example.com",
|
|
||||||
country: "Hong Kong",
|
|
||||||
countryCode: "HK",
|
countryCode: "HK",
|
||||||
avatarUrl: "https://example.com/avatar.png",
|
|
||||||
intimacy: 42,
|
|
||||||
dolBalance: 12,
|
dolBalance: 12,
|
||||||
creditBalance: 120,
|
creditBalance: 120,
|
||||||
dailyFreeChatLimit: 30,
|
dailyFreeChatLimit: 30,
|
||||||
dailyFreeChatUsed: 4,
|
|
||||||
dailyFreeChatRemaining: 26,
|
dailyFreeChatRemaining: 26,
|
||||||
dailyFreePrivateLimit: 2,
|
dailyFreePrivateLimit: 2,
|
||||||
dailyFreePrivateUsed: 1,
|
|
||||||
dailyFreePrivateRemaining: 1,
|
dailyFreePrivateRemaining: 1,
|
||||||
vipExpiresAt: "2026-07-26T00:00:00+00:00",
|
|
||||||
relationshipStage: "close_friend",
|
|
||||||
currentMood: "playful",
|
|
||||||
isGuest: true,
|
|
||||||
isVip: true,
|
isVip: true,
|
||||||
voiceMinutesRemaining: 30,
|
|
||||||
}),
|
}),
|
||||||
).toEqual({
|
).toEqual({
|
||||||
id: "user-2",
|
id: "user-2",
|
||||||
username: "Elio",
|
username: "Elio",
|
||||||
email: "elio@example.com",
|
|
||||||
country: "Hong Kong",
|
|
||||||
countryCode: "HK",
|
countryCode: "HK",
|
||||||
avatarUrl: "https://example.com/avatar.png",
|
|
||||||
intimacy: 42,
|
|
||||||
dolBalance: 12,
|
|
||||||
creditBalance: 120,
|
creditBalance: 120,
|
||||||
dailyFreeChatLimit: 30,
|
dailyFreeChatLimit: 30,
|
||||||
dailyFreeChatUsed: 4,
|
|
||||||
dailyFreeChatRemaining: 26,
|
dailyFreeChatRemaining: 26,
|
||||||
dailyFreePrivateLimit: 2,
|
dailyFreePrivateLimit: 2,
|
||||||
dailyFreePrivateUsed: 1,
|
|
||||||
dailyFreePrivateRemaining: 1,
|
dailyFreePrivateRemaining: 1,
|
||||||
vipExpiresAt: "2026-07-26T00:00:00+00:00",
|
|
||||||
relationshipStage: "close_friend",
|
|
||||||
currentMood: "playful",
|
|
||||||
isGuest: true,
|
|
||||||
isVip: true,
|
isVip: true,
|
||||||
voiceMinutesRemaining: 30,
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -93,7 +58,6 @@ describe("toView", () => {
|
|||||||
).toMatchObject({
|
).toMatchObject({
|
||||||
isVip: true,
|
isVip: true,
|
||||||
creditBalance: 120,
|
creditBalance: 120,
|
||||||
dolBalance: 120,
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -12,25 +12,13 @@ function makeUser(overrides: Partial<UserView> = {}): UserView {
|
|||||||
return {
|
return {
|
||||||
id: "user-1",
|
id: "user-1",
|
||||||
username: "Elio Fan",
|
username: "Elio Fan",
|
||||||
email: "user@example.com",
|
|
||||||
country: "Hong Kong",
|
|
||||||
countryCode: "HK",
|
countryCode: "HK",
|
||||||
avatarUrl: "https://example.com/avatar.png",
|
|
||||||
intimacy: 42,
|
|
||||||
dolBalance: 7,
|
|
||||||
creditBalance: 7,
|
creditBalance: 7,
|
||||||
dailyFreeChatLimit: 30,
|
dailyFreeChatLimit: 30,
|
||||||
dailyFreeChatUsed: 0,
|
|
||||||
dailyFreeChatRemaining: 30,
|
dailyFreeChatRemaining: 30,
|
||||||
dailyFreePrivateLimit: 2,
|
dailyFreePrivateLimit: 2,
|
||||||
dailyFreePrivateUsed: 0,
|
|
||||||
dailyFreePrivateRemaining: 2,
|
dailyFreePrivateRemaining: 2,
|
||||||
vipExpiresAt: null,
|
|
||||||
relationshipStage: "close_friend",
|
|
||||||
currentMood: "happy",
|
|
||||||
isGuest: false,
|
|
||||||
isVip: false,
|
isVip: false,
|
||||||
voiceMinutesRemaining: 12,
|
|
||||||
...overrides,
|
...overrides,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,50 +56,27 @@ export interface UserFetchData {
|
|||||||
export function toView(u: {
|
export function toView(u: {
|
||||||
id: string;
|
id: string;
|
||||||
username: string;
|
username: string;
|
||||||
email?: string;
|
|
||||||
country?: string;
|
|
||||||
countryCode?: string;
|
countryCode?: string;
|
||||||
avatarUrl?: string;
|
|
||||||
intimacy?: number;
|
|
||||||
dolBalance?: number;
|
dolBalance?: number;
|
||||||
creditBalance?: number;
|
creditBalance?: number;
|
||||||
dailyFreeChatLimit?: number;
|
dailyFreeChatLimit?: number;
|
||||||
dailyFreeChatUsed?: number;
|
|
||||||
dailyFreeChatRemaining?: number;
|
dailyFreeChatRemaining?: number;
|
||||||
dailyFreePrivateLimit?: number;
|
dailyFreePrivateLimit?: number;
|
||||||
dailyFreePrivateUsed?: number;
|
|
||||||
dailyFreePrivateRemaining?: number;
|
dailyFreePrivateRemaining?: number;
|
||||||
vipExpiresAt?: string | null;
|
|
||||||
relationshipStage?: string;
|
|
||||||
currentMood?: string;
|
|
||||||
isGuest?: boolean;
|
|
||||||
isVip?: boolean;
|
isVip?: boolean;
|
||||||
voiceMinutesRemaining?: number;
|
|
||||||
}): UserView {
|
}): UserView {
|
||||||
const creditBalance = u.creditBalance ?? u.dolBalance ?? 0;
|
const creditBalance = u.creditBalance ?? u.dolBalance ?? 0;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: u.id,
|
id: u.id,
|
||||||
username: u.username,
|
username: u.username,
|
||||||
email: u.email ?? "",
|
|
||||||
country: u.country ?? "",
|
|
||||||
countryCode: u.countryCode ?? "",
|
countryCode: u.countryCode ?? "",
|
||||||
avatarUrl: u.avatarUrl ?? "",
|
|
||||||
intimacy: u.intimacy ?? 0,
|
|
||||||
dolBalance: u.dolBalance ?? creditBalance,
|
|
||||||
creditBalance,
|
creditBalance,
|
||||||
dailyFreeChatLimit: u.dailyFreeChatLimit ?? 0,
|
dailyFreeChatLimit: u.dailyFreeChatLimit ?? 0,
|
||||||
dailyFreeChatUsed: u.dailyFreeChatUsed ?? 0,
|
|
||||||
dailyFreeChatRemaining: u.dailyFreeChatRemaining ?? 0,
|
dailyFreeChatRemaining: u.dailyFreeChatRemaining ?? 0,
|
||||||
dailyFreePrivateLimit: u.dailyFreePrivateLimit ?? 0,
|
dailyFreePrivateLimit: u.dailyFreePrivateLimit ?? 0,
|
||||||
dailyFreePrivateUsed: u.dailyFreePrivateUsed ?? 0,
|
|
||||||
dailyFreePrivateRemaining: u.dailyFreePrivateRemaining ?? 0,
|
dailyFreePrivateRemaining: u.dailyFreePrivateRemaining ?? 0,
|
||||||
vipExpiresAt: u.vipExpiresAt ?? null,
|
|
||||||
relationshipStage: u.relationshipStage ?? "",
|
|
||||||
currentMood: u.currentMood ?? "",
|
|
||||||
isGuest: u.isGuest ?? false,
|
|
||||||
isVip: u.isVip ?? false,
|
isVip: u.isVip ?? false,
|
||||||
voiceMinutesRemaining: u.voiceMinutesRemaining ?? 0,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,7 +88,6 @@ export function applyEntitlementSnapshotToView(
|
|||||||
return {
|
return {
|
||||||
...user,
|
...user,
|
||||||
isVip: snapshot.isVip,
|
isVip: snapshot.isVip,
|
||||||
dolBalance: snapshot.creditBalance,
|
|
||||||
creditBalance: snapshot.creditBalance,
|
creditBalance: snapshot.creditBalance,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user