GRV-MobileApp/src/app/(tabs)/index.tsx
kirukib 1ed5e9729e Add GRV Summit attendee app (Expo SDK 58)
Expo Router app for summit attendees: email OTP login, booth and investee
QR scanning (camera + manual entry, /q/<token> universal links), mystery
investee celebration, points/rank/progress home, leaderboard, raffles,
merch ordering with pickup QR, and ticket QRs. Built against the attendee,
auth and public endpoints in GRV-Backend/API.md. Theme, fonts, icon and
splash follow the GRVSummit site.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 21:33:17 +03:00

220 lines
7.1 KiB
TypeScript
Raw 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 { router } from 'expo-router';
import { Image, Pressable, Text, View } from 'react-native';
import {
Button,
Card,
ErrorBox,
H2,
Icon,
Loading,
P,
PatternHeader,
Screen,
s,
type IconName,
} from '../../components/ui';
import { useMe, useRaffles } from '../../lib/api';
import { colors, fonts } from '../../lib/theme';
function Progress({
label,
found,
total,
icon,
onPress,
}: {
label: string;
found: number;
total: number;
icon: IconName;
onPress: () => void;
}) {
const pct = total ? Math.min(1, found / total) : 0;
return (
<Pressable onPress={onPress} style={{ flex: 1 }}>
<Card style={{ gap: 10 }}>
<View
style={{
width: 40,
height: 40,
borderRadius: 12,
backgroundColor: colors.surfaceMuted,
alignItems: 'center',
justifyContent: 'center',
}}
>
<Icon name={icon} color={colors.primary} />
</View>
<Text style={s.label}>{label}</Text>
<Text style={[s.num, { fontSize: 24 }]}>
{found}
<Text style={{ color: colors.grey2, fontSize: 16 }}> / {total}</Text>
</Text>
<View style={{ height: 6, borderRadius: 3, backgroundColor: colors.surfaceMuted }}>
<View
style={{
height: 6,
borderRadius: 3,
width: `${pct * 100}%`,
backgroundColor: colors.primary,
}}
/>
</View>
</Card>
</Pressable>
);
}
export default function Home() {
const me = useMe();
const raffles = useRaffles();
const m = me.data;
const header = (
<PatternHeader>
<Image
source={require('../../../assets/logo-white.png')}
style={{ width: 150, height: 32, marginTop: 8 }}
resizeMode="contain"
/>
<P style={{ color: colors.secondary, marginTop: 20 }}>
{m?.user.name ? `Hi ${m.user.name.split(' ')[0]}` : 'Welcome to the GRV Summit'}
</P>
<View style={{ flexDirection: 'row', alignItems: 'flex-end', marginTop: 4, gap: 16 }}>
<Text style={[s.num, { fontSize: 56, color: colors.white, lineHeight: 62 }]}>
{m?.points ?? '–'}
</Text>
<Text
style={{
fontFamily: fonts.semibold,
color: colors.white,
fontSize: 16,
marginBottom: 12,
}}
>
points
</Text>
<View style={{ flex: 1 }} />
<Pressable
onPress={() => router.push('/leaderboard')}
style={{ alignItems: 'flex-end', marginBottom: 10 }}
>
<Text style={[s.label, { color: colors.secondary }]}>Rank</Text>
<Text style={[s.num, { color: colors.white, fontSize: 24 }]}>
{m?.rank ? `#${m.rank}` : '–'}
</Text>
</Pressable>
</View>
</PatternHeader>
);
const refresh = () => {
void me.refetch();
void raffles.refetch();
};
const eligible = raffles.data?.filter((r) => r.eligible && !r.drawnAt).length ?? 0;
const nextRaffle = raffles.data
?.filter((r) => !r.eligible && !r.drawnAt)
.sort((a, b) => a.minPoints - b.minPoints)[0];
return (
<Screen header={header} onRefresh={refresh} refreshing={me.isRefetching}>
{me.isPending ? (
<Loading />
) : me.error ? (
<ErrorBox error={me.error} onRetry={refresh} />
) : (
m && (
<>
<Button title="Scan a QR code" onPress={() => router.push('/scan')} />
<View style={{ flexDirection: 'row', gap: 12 }}>
<Progress
label="Booths"
icon="store"
found={m.progress.booths.found}
total={m.progress.booths.total}
onPress={() => router.push('/booths')}
/>
<Progress
label="Investees"
icon="rocket"
found={m.progress.startups.found}
total={m.progress.startups.total}
onPress={() => router.push('/investees')}
/>
</View>
<Pressable onPress={() => router.push('/investees')}>
<Card
tone={m.progress.mysteryFound ? 'muted' : 'white'}
style={{ flexDirection: 'row', alignItems: 'center', gap: 14 }}
>
<View
style={{
width: 48,
height: 48,
borderRadius: 24,
backgroundColor: colors.primary,
alignItems: 'center',
justifyContent: 'center',
}}
>
{m.progress.mysteryFound ? (
<Icon name="check" color={colors.white} />
) : (
<Text style={[s.num, { color: colors.white, fontSize: 24 }]}>?</Text>
)}
</View>
<View style={{ flex: 1 }}>
<H2 style={{ fontSize: 17 }}>Mystery investee</H2>
<P muted style={{ fontSize: 14 }}>
{m.progress.mysteryFound
? 'Found! You earned double points.'
: 'One future investee is hiding in the crowd. Find them for double points.'}
</P>
</View>
</Card>
</Pressable>
<Pressable onPress={() => router.push('/raffles')}>
<Card style={{ flexDirection: 'row', alignItems: 'center', gap: 14 }}>
<Icon name="gift" color={colors.primary} size={28} />
<View style={{ flex: 1 }}>
<H2 style={{ fontSize: 17 }}>Raffles</H2>
<P muted style={{ fontSize: 14 }}>
{raffles.isPending
? 'Loading…'
: eligible
? `You're in ${eligible} draw${eligible > 1 ? 's' : ''}.`
: nextRaffle
? `${Math.max(0, nextRaffle.minPoints - m.points)} more points to enter "${nextRaffle.name}".`
: 'Prizes are drawn at the end of the summit.'}
{eligible && nextRaffle
? ` ${nextRaffle.minPoints - m.points} more for "${nextRaffle.name}".`
: ''}
</P>
</View>
<Icon name="chevron" color={colors.grey2} />
</Card>
</Pressable>
<Pressable onPress={() => router.push('/merch')}>
<Card style={{ flexDirection: 'row', alignItems: 'center', gap: 14 }}>
<Icon name="bag" color={colors.primary} size={28} />
<View style={{ flex: 1 }}>
<H2 style={{ fontSize: 17 }}>GRV merch</H2>
<P muted style={{ fontSize: 14 }}>
Order in the app, pay and collect at the GRV booth.
</P>
</View>
<Icon name="chevron" color={colors.grey2} />
</Card>
</Pressable>
</>
)
)}
</Screen>
);
}