Files
otunes/apps/mobile/components/profile-header-button.tsx
T

76 lines
1.9 KiB
TypeScript

import { useTabletLayout } from "@/hooks/use-tablet-layout"
import { useOpenSettings } from "@/hooks/use-open-settings"
import { Image } from "expo-image"
import { Pressable, StyleSheet, Text, View } from "react-native"
import { useCachedQuery } from "@/hooks/use-cached-query"
import { useProfileImageUrl } from "@/hooks/use-profile-image-url"
import { initialsFromName } from "@/lib/format"
import { radius, useThemeColors } from "@/lib/theme"
import { api } from "@otunes/convex/_generated/api"
export function ProfileHeaderButton() {
const tabletLayout = useTabletLayout()
const openSettings = useOpenSettings()
const colors = useThemeColors()
const user = useCachedQuery(api.auth.currentUser)
const imageUrl = useProfileImageUrl(user?.image)
if (tabletLayout) return null
return (
<Pressable
accessibilityLabel="Open profile"
accessibilityRole="button"
hitSlop={8}
onPress={openSettings}
style={({ pressed }) => [styles.button, { opacity: pressed ? 0.75 : 1 }]}
>
<View
style={[
styles.avatar,
{
backgroundColor: colors.muted,
borderColor: colors.border,
},
]}
>
{imageUrl ? (
<Image
source={{ uri: imageUrl }}
style={styles.image}
contentFit="cover"
/>
) : (
<Text style={[styles.initials, { color: colors.foreground }]}>
{initialsFromName(user?.name ?? "Me")}
</Text>
)}
</View>
</Pressable>
)
}
const styles = StyleSheet.create({
button: {
marginRight: 4,
},
avatar: {
width: 42,
height: 42,
borderRadius: radius.full,
borderWidth: 1,
alignItems: "center",
justifyContent: "center",
overflow: "hidden",
},
image: {
width: "100%",
height: "100%",
},
initials: {
fontSize: 14,
fontWeight: "700",
},
})