introduced basic typechecking

This commit is contained in:
Shea Duma committed 2026-04-22 19:49:17 +03:00
1 parent b8e6b796c9
commit 67a2d7ccb3
4 files changed
+17 -30

No files matched your search

+2 -2
View File
@@ -70,7 +70,7 @@ export function UserHero({ userId, avatarUrl, bannerUrl, presence, autoplayGifs
const status = presence?.status;
const isExpandable = (status?.length ?? 0) > 70;
const fetchedProfile = useUserProfile(userId, undefined, undefined, true);
const fetchedProfile = useUserProfile(userId);
return (
<Box
@@ -203,7 +203,7 @@ export function UserHeroName({ displayName, userId }: UserHeroNameProps) {
const nick = useNickname(userId);
// Sable username color and fonts
const { color, font } = useSableCosmetics(userId, useRoom(), true);
const { color, font } = useSableCosmetics(userId, useRoom());
const shownName = nick ?? displayName ?? username ?? userId;
return (
@@ -53,7 +53,6 @@ import { UserInviteAlert, UserBanAlert, UserModeration, UserKickAlert } from './
import { PowerChip } from './PowerChip';
import { IgnoredUserAlert, MutualRoomsChip, OptionsChip, ServerChip, ShareChip } from './UserChips';
import { UserHero, UserHeroName } from './UserHero';
import { text } from 'stream/consumers';
const KNOWN_KEYS = [
'moe.sable.app.bio',
@@ -399,7 +398,7 @@ export function UserRoomProfile({ userId, initialProfile }: Readonly<UserRoomPro
const presence = useUserPresence(userId);
const fetchedProfile = useUserProfile(userId, room, undefined, true);
const fetchedProfile = useUserProfile(userId, room);
const extendedProfile =
fetchedProfile && Object.keys(fetchedProfile).length > 0
? fetchedProfile
@@ -459,6 +458,7 @@ export function UserRoomProfile({ userId, initialProfile }: Readonly<UserRoomPro
}),
[mx, room, linkifyOpts, settingsLinkBaseUrl, useAuthentication, spoilerClickHandler]
);
function shadeColor(initialColor: string, percent: number) {
if (!initialColor || initialColor[0] !== '#' || initialColor.length !== 7) return undefined;
const ratio = 1 + percent / 100;
@@ -477,8 +477,8 @@ export function UserRoomProfile({ userId, initialProfile }: Readonly<UserRoomPro
return `#${RR}${GG}${BB}`;
}
const backgroundColor = fetchedProfile?.heroColorScheme?.color ?? color.Surface.Container;
const fetchedBrightness = fetchedProfile?.heroColorScheme?.brightness;
const backgroundColor = fetchedProfile.heroColor ?? color.Surface.Container;
const fetchedBrightness = fetchedProfile?.heroBrightness;
const isBackgroundDark = fetchedBrightness ? fetchedBrightness === 'dark' : undefined;
const innerColor = shadeColor(backgroundColor, isBackgroundDark ? -70 : 70);
const cardColor =
+3 -15
View File
@@ -8,9 +8,9 @@ import { usePowerLevelTags } from './usePowerLevelTags';
import { useTheme } from './useTheme';
import { useUserProfile } from './useUserProfile';
export function useSableCosmetics(userId: string, room: Room, isInHero?: boolean) {
export function useSableCosmetics(userId: string, room: Room) {
const theme = useTheme();
const profile = useUserProfile(userId, room, undefined, isInHero);
const profile = useUserProfile(userId, room);
const powerLevels = usePowerLevels(room);
const creators = useRoomCreators(room);
@@ -34,19 +34,7 @@ export function useSableCosmetics(userId: string, room: Room, isInHero?: boolean
color: finalColor,
font: profile.resolvedFont,
};
if (isInHero && profile.heroColorScheme) {
resolvedCosmetics.heroColorScheme = profile.heroColorScheme;
}
return resolvedCosmetics;
}, [
room,
userId,
profile.resolvedColor,
profile.resolvedFont,
profile.heroColorScheme,
isInHero,
getPowerTag,
accessibleTagColors,
]);
}, [room, userId, profile.resolvedColor, profile.resolvedFont, getPowerTag, accessibleTagColors]);
}
+8 -9
View File
@@ -97,12 +97,13 @@ const sanitizeFont = (f: string) => f.replaceAll(/[;{}<>]/g, '').slice(0, 32);
export const useUserProfile = (
userId: string,
room?: Room,
initialProfile?: Partial<UserProfile>,
isInUserHero?: boolean
initialProfile?: Partial<UserProfile>
): UserProfile & {
resolvedColor?: string;
resolvedFont?: string;
resolvedPronouns?: any[];
heroColor?: string;
heroBrightness?: string;
} => {
const mx = useMatrixClient();
const [legacyUsernameColor] = useSetting(settingsAtom, 'legacyUsernameColor');
@@ -212,15 +213,12 @@ export const useUserProfile = (
}
}
}
const validHeroColor = isValidHex(data?.heroColorScheme?.color);
const heroBrightness = data?.heroColorScheme?.brightness;
const validGlobalVal = isValidHex(data?.nameColor);
const validGlobalValDark = isValidHex(data?.nameColorDark);
const validGlobalValLight = isValidHex(data?.nameColorLight);
console.log(
'Hero Color Scheme: ',
data?.heroColorScheme?.color,
'Is User Hero: ',
isInUserHero === true
);
const validGlobalGeneral =
(renderGlobalColors || userId === mx.getUserId()) && !!validGlobalVal
@@ -265,6 +263,8 @@ export const useUserProfile = (
resolvedFont,
resolvedPronouns,
pronouns: resolvedPronouns,
heroColor: validHeroColor,
heroBrightness,
};
}, [
cached,
@@ -274,7 +274,6 @@ export const useUserProfile = (
room,
renderRoomColors,
renderRoomFonts,
isInUserHero,
renderGlobalColors,
themeKind,
legacyUsernameColor,