♻️ refactor: dedupe utils, lift CardGrid/IconLabel primitives

This commit is contained in:
2026-06-29 05:56:49 +07:00
parent 1a91ffbe92
commit a18d9612ee
15 changed files with 106 additions and 81 deletions
+3 -3
View File
@@ -92,10 +92,10 @@ function normalizeStatus(status?: string): UserStatus {
}
}
function toIso(v?: string | Date | null): string | undefined {
export function toIso(v?: string | Date | null): string | undefined {
if (!v) return undefined;
const s = v instanceof Date ? v.toISOString() : v;
return s === "" ? undefined : s;
const date = v instanceof Date ? v : new Date(v);
return Number.isNaN(date.getTime()) ? undefined : date.toISOString();
}
export function toUserProfile(raw: RawUser, selfId: string): UserProfile {
+1 -6
View File
@@ -8,6 +8,7 @@ import type {
import type { TwoFactorMethod } from "../../shared/types/auth";
import type { UserStatus } from "../../shared/types/user";
import { requireActiveClient } from "./client";
import { toIso } from "./mappers";
import { userCache } from "./userService";
import { cacheKeys } from "../cache/policies";
import { entityStore } from "../store/entityStore";
@@ -20,12 +21,6 @@ const CONTENT_FILTER_KEYS: ContentFilterKey[] = [
"content_horror",
];
function toIso(d?: Date | string | null): string | undefined {
if (!d) return undefined;
const date = typeof d === "string" ? new Date(d) : d;
return Number.isNaN(date.getTime()) ? undefined : date.toISOString();
}
function toSettings(u: CurrentUser): AccountSettings {
const filters = (u.contentFilters ?? []).filter((t): t is ContentFilterKey =>
(CONTENT_FILTER_KEYS as string[]).includes(t),
+4 -1
View File
@@ -49,10 +49,13 @@ export async function getUser(userId: string): Promise<UserProfile> {
export async function getUserByName(username: string): Promise<UserProfile> {
const vrc = requireActiveClient();
const self = await selfId();
return userCache.get(cacheKeys.userByName(username), policies.user, async () => {
const key = cacheKeys.userByName(username);
const profile = await userCache.get(key, policies.user, async () => {
const { data } = await vrc.getUserByName({ path: { username }, throwOnError: true });
return toUserProfile(data, self);
});
refreshStore(profile, key);
return profile;
}
export async function searchUsers(query: string): Promise<UserProfile[]> {