Files
archived-orca/mobile/src/components/MobileRepoIcon.tsx

98 lines
2.4 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import {
Bot,
Box,
Braces,
Briefcase,
Building2,
Code2,
Cpu,
Database,
Folder,
Gauge,
Globe,
Layers,
type LucideIcon,
Package,
Palette,
Rocket,
Server,
// `Shapes` is lucide's own export name; exempted in config/oxlint-anti-slop.json.
Shapes,
Sparkles,
SquareTerminal,
Wrench
} from 'lucide-react-native'
import { useState } from 'react'
import { Image, StyleSheet, Text, View } from 'react-native'
import type { MobileRenderableRepoIcon } from '../host-screen/host-screen-reply-schema'
import { colors, radii } from '../theme/mobile-theme'
import { useMobileColorScheme } from '../theme/use-mobile-color-scheme'
// Match desktop repo-icon picker’s lucide glyphs so mobile project headers retain chosen icons.
const REPO_LUCIDE_ICONS: Record<string, LucideIcon> = {
Folder,
Code2,
SquareTerminal,
Bot,
Package,
Database,
Globe,
Server,
Layers,
Box,
Braces,
Briefcase,
Building2,
Cpu,
Gauge,
Palette,
Rocket,
Shapes,
Sparkles,
Wrench
}
type Props = {
// Accept decoded catalog icon fields (type/src/label/emoji/name), not unused source; RepoIcon remains compatible.
repoIcon?: MobileRenderableRepoIcon | null
size?: number
color?: string
}
// Render desktop-style custom image/emoji/lucide with Folder fallback, never bare project dot.
export function MobileRepoIcon({ repoIcon, size = 14, color = colors.textSecondary }: Props) {
useMobileColorScheme()
// Keyed by src so a changed icon gets a fresh try; the page shell refuses every https load.
const [failedSrc, setFailedSrc] = useState<string | null>(null)
if (repoIcon?.type === 'image' && repoIcon.src !== failedSrc) {
const { src } = repoIcon
return (
<Image
source={{ uri: src }}
style={{ width: size, height: size, borderRadius: radii.mark }}
accessibilityLabel={repoIcon.label}
onError={() => setFailedSrc(src)}
/>
)
}
if (repoIcon?.type === 'emoji') {
return <Text style={[styles.emoji, { fontSize: size }]}>{repoIcon.emoji}</Text>
}
const Icon = (repoIcon?.type === 'lucide' && REPO_LUCIDE_ICONS[repoIcon.name]) || Folder
return (
<View style={styles.glyph}>
<Icon size={size} color={color} strokeWidth={2} />
</View>
)
}
const styles = StyleSheet.create({
emoji: {
textAlign: 'center'
},
glyph: {
alignItems: 'center',
justifyContent: 'center'
}
})