11import { weatherStore , type TemperatureUnit } from '@/zustand/weatherStore'
22import { Calendar03SolidIcon } from '@assets/icons/icons'
3+ import Btn from '@components/Button'
34import Gradient from '@components/Gradient'
45import type { Daily } from '@screens/Weather/types'
56import { Icons } from '@screens/Weather/utils'
67import { F , Medium , Regular } from '@utils/fonts'
78import type { Theme } from '@utils/types'
89import { getDay , tempConverter } from '@utils/utils'
9- import React , { useEffect , useMemo } from 'react'
10+ import React , { useMemo } from 'react'
1011import { View } from 'react-native'
1112import Animated , { FadeIn } from 'react-native-reanimated'
1213import WeatherLabel , { Underline } from './WeatherLabel'
@@ -25,40 +26,54 @@ export default function DailyForecast({ color, daily, theme }: WeatherForecastPr
2526 const currentTemp = weatherStore ( ( state ) => state . currentWeather ?. current . temp )
2627 const weeklyMinMax = useMemo ( ( ) => calculateWeeklyMinMax ( daily ) , [ daily ] )
2728 const dotPosition = useMemo ( ( ) => calculateDotPosition ( currentTemp , daily && daily [ 0 ] ) , [ currentTemp , daily ] )
28- const data = daily
29+ const [ is7Day , setIs7Day ] = React . useState ( false )
30+
31+ const data = useMemo ( ( ) => {
32+ if ( is7Day ) return daily
33+ else return daily ?. slice ( 0 , 3 )
34+ } , [ daily , is7Day ] )
2935
3036 // useEffect(() => {
3137 // const timer = screenDelay(() => setData(daily))
3238 // return () => clearTimeout(timer)
3339 // }, [daily])
3440
3541 return (
36- < Animated . View className = 'px-4' entering = { FadeIn . duration ( 700 ) . delay ( 100 ) } >
37- < View className = 'rounded-3xl bg-black/10 pb-2' >
38- < WeatherLabel color = { color } label = '7-Day Forecast' Icon = { Calendar03SolidIcon } />
39- < Underline />
40- { ! data && < View style = { { height : 56 * 5.855 } } > </ View > }
41- < View >
42- { data ?. map ( ( d , i ) => {
43- return (
44- < DailyWeather
45- day = { i === 0 ? 'Today' : getDay ( d . dt || new Date ( ) . getTime ( ) ) }
46- dotPosition = { i === 0 ? dotPosition : null }
47- key = { i }
48- d = { d }
49- currentUnit = { currentUnit }
50- min = { weeklyMinMax . min }
51- max = { weeklyMinMax . max }
52- theme = { theme }
53- />
54- )
55- } ) }
42+ < >
43+ < Animated . View className = 'px-4' entering = { FadeIn . duration ( 700 ) . delay ( 100 ) } >
44+ < View className = 'rounded-3xl bg-black/10 pb-2' >
45+ < WeatherLabel color = { color } label = '7-Day Forecast' Icon = { Calendar03SolidIcon } />
46+ < Underline />
47+ { ! data && < View style = { { height : 56 * 5.855 } } > </ View > }
48+ < View >
49+ { data ?. map ( ( d , i ) => {
50+ return (
51+ < DailyWeather
52+ day = { i === 0 ? 'Today' : getDay ( d . dt || new Date ( ) . getTime ( ) ) }
53+ dotPosition = { i === 0 ? dotPosition : null }
54+ key = { i }
55+ d = { d }
56+ currentUnit = { currentUnit }
57+ min = { weeklyMinMax . min }
58+ max = { weeklyMinMax . max }
59+ theme = { theme }
60+ />
61+ )
62+ } ) }
63+ </ View >
64+ < Regular className = 'mb-1 mt-3 px-5 text-center opacity-60' style = { [ color , F . F9 ] } >
65+ Percentage represents the probability of precipitation.
66+ </ Regular >
67+ < View className = 'mb-2 mt-2 px-4' >
68+ < Btn
69+ title = { is7Day ? '3-Day Forecast' : '7-Day Forecast' }
70+ onPress = { ( ) => setIs7Day ( ! is7Day ) }
71+ className = 'bg-white/10'
72+ />
73+ </ View >
5674 </ View >
57- < Regular className = 'mb-1 mt-3 px-5 text-center opacity-60' style = { [ color , F . F9 ] } >
58- Percentage represents the probability of precipitation.
59- </ Regular >
60- </ View >
61- </ Animated . View >
75+ </ Animated . View >
76+ </ >
6277 )
6378}
6479
0 commit comments