112 lines
2.4 KiB
TypeScript
112 lines
2.4 KiB
TypeScript
import { View, Text, ScrollView, TouchableOpacity, StyleSheet } from 'react-native'
|
|
import { useState, useEffect } from 'react'
|
|
import { useRouter } from 'expo-router'
|
|
|
|
export default function HomeScreen() {
|
|
const [poll, setPoll] = useState<any>(null)
|
|
const router = useRouter()
|
|
|
|
useEffect(() => {
|
|
loadTodaysPoll()
|
|
}, [])
|
|
|
|
const loadTodaysPoll = async () => {
|
|
try {
|
|
const res = await fetch('https://your-app.vercel.app/api/polls')
|
|
const data = await res.json()
|
|
setPoll(data[0])
|
|
} catch (error) {
|
|
console.error('Failed to load poll:', error)
|
|
}
|
|
}
|
|
|
|
if (!poll) {
|
|
return (
|
|
<View style={styles.container}>
|
|
<Text style={styles.loading}>Loading...</Text>
|
|
</View>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<ScrollView style={styles.container}>
|
|
<View style={styles.header}>
|
|
<Text style={styles.emoji}>{poll.emoji}</Text>
|
|
<Text style={styles.title}>{poll.question}</Text>
|
|
<Text style={styles.pot}>💰 {poll.totalPot} cUSD</Text>
|
|
</View>
|
|
|
|
<View style={styles.options}>
|
|
{poll.options.map((option: any) => (
|
|
<TouchableOpacity
|
|
key={option.id}
|
|
style={styles.option}
|
|
onPress={() => router.push(`/vote/${poll.id}/${option.id}`)}
|
|
>
|
|
<Text style={styles.optionEmoji}>{option.emoji}</Text>
|
|
<Text style={styles.optionText}>{option.text}</Text>
|
|
<Text style={styles.optionVotes}>{option.votes} votes</Text>
|
|
</TouchableOpacity>
|
|
))}
|
|
</View>
|
|
</ScrollView>
|
|
)
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
container: {
|
|
flex: 1,
|
|
backgroundColor: '#1a1a1a',
|
|
},
|
|
header: {
|
|
padding: 20,
|
|
alignItems: 'center',
|
|
},
|
|
emoji: {
|
|
fontSize: 64,
|
|
marginBottom: 16,
|
|
},
|
|
title: {
|
|
fontSize: 24,
|
|
fontWeight: 'bold',
|
|
color: '#fff',
|
|
textAlign: 'center',
|
|
marginBottom: 8,
|
|
},
|
|
pot: {
|
|
fontSize: 18,
|
|
color: '#35D07F',
|
|
fontWeight: '600',
|
|
},
|
|
loading: {
|
|
color: '#fff',
|
|
fontSize: 18,
|
|
textAlign: 'center',
|
|
marginTop: 100,
|
|
},
|
|
options: {
|
|
padding: 16,
|
|
gap: 12,
|
|
},
|
|
option: {
|
|
backgroundColor: '#2a2a2a',
|
|
borderRadius: 16,
|
|
padding: 20,
|
|
alignItems: 'center',
|
|
},
|
|
optionEmoji: {
|
|
fontSize: 48,
|
|
marginBottom: 8,
|
|
},
|
|
optionText: {
|
|
fontSize: 18,
|
|
fontWeight: '600',
|
|
color: '#fff',
|
|
marginBottom: 4,
|
|
},
|
|
optionVotes: {
|
|
fontSize: 14,
|
|
color: '#888',
|
|
},
|
|
})
|