import React, { useState, useCallback } from 'react' import { View, Text, ScrollView, StyleSheet, RefreshControl } from 'react-native' import { useFocusEffect } from 'expo-router' import { COLORS } from '../../constants/Config' import client from '../../services/api' const HOURS = Array.from({ length: 24 }, (_, i) => i) const DAYS = ['월', '화', '수', '목', '금', '토', '일'] export default function SRHeatmapScreen() { const [matrix, setMatrix] = useState([]) const [maxVal, setMaxVal] = useState(1) const [loading, setLoading] = useState(false) const load = useCallback(async () => { setLoading(true) try { const r = await client.get('/api/mobile2/hourly-pattern') const m = r.data?.matrix ?? r.data ?? [] setMatrix(m) setMaxVal(Math.max(1, ...m.flat().filter(Number.isFinite))) } catch { setMatrix([]) } finally { setLoading(false) } }, []) useFocusEffect(useCallback(() => { load() }, [load])) const cellColor = (v: number) => { const alpha = Math.round((v / maxVal) * 255).toString(16).padStart(2, '0') return `${COLORS.accent}${alpha}` } return ( }> SR 발생 히트맵 (요일×시간) {HOURS.filter(h => h % 3 === 0).map(h => ( {h}시 ))} {matrix.map((row, di) => ( {row.map((v, hi) => ( {v > 0 && {v}} ))} ))} {DAYS.slice(0, matrix.length).map((d, i) => {d})} 셀 색이 진할수록 SR 발생량이 많습니다. ) } const s = StyleSheet.create({ container: { flex: 1, backgroundColor: COLORS.bg, padding: 12 }, title: { fontSize: 16, fontWeight: '800', color: COLORS.text, marginBottom: 12 }, hourRow: { flexDirection: 'row', marginBottom: 4 }, hourLabel: { fontSize: 9, color: COLORS.muted, textAlign: 'center' }, dayRow: { flexDirection: 'row', marginBottom: 2 }, cell: { width: 34, height: 34, borderRadius: 4, marginRight: 2, alignItems: 'center', justifyContent: 'center' }, cellVal: { fontSize: 9, color: '#fff', fontWeight: '700' }, legend: { flexDirection: 'row', flexWrap: 'wrap', gap: 8, marginTop: 12 }, dayLabel: { fontSize: 12, color: COLORS.muted }, note: { fontSize: 11, color: COLORS.muted, marginTop: 8 }, })