@@ -10,7 +10,6 @@ import { useTranslation } from 'react-i18next'
1010
1111import { useMemory } from '@store/useMemory'
1212import { useStorage } from '@store/useStorage'
13- import { apolloClient } from '@services/apollo'
1413import { Header } from '@components/dialogs/Header'
1514import { Footer } from '@components/dialogs/Footer'
1615import { Img } from '@components/Img'
@@ -89,42 +88,27 @@ function Weather({ gameplay_condition, ...props }) {
8988 )
9089}
9190
92- const WeatherMemo = React . memo (
93- Weather ,
94- ( prev , next ) => prev . gameplay_condition === next . gameplay_condition ,
95- )
96-
97- export function ActiveWeather ( ) {
91+ /**
92+ * @param {{ weatherData: import('@rm/types').Weather[] } } props
93+ */
94+ export function ActiveWeather ( { weatherData } ) {
9895 const weatherEnabled = useStorage ( ( s ) => s . filters ?. weather ?. enabled ?? false )
9996 const location = useStorage ( ( s ) => s . location )
10097 const zoom = useStorage ( ( s ) => s . zoom )
10198 const allowedZoom = useMemory ( ( s ) => s . config . general . activeWeatherZoom )
10299
103- const [ active , setActive ] = React . useState (
104- /** @type {import('@rm/types').Weather | null } */ ( null ) ,
100+ const active = React . useMemo (
101+ ( ) =>
102+ zoom > allowedZoom
103+ ? weatherData . find (
104+ ( cell ) =>
105+ Array . isArray ( cell ?. polygon ) &&
106+ booleanPointInPolygon ( point ( location ) , polygon ( [ cell . polygon ] ) ) ,
107+ ) || null
108+ : null ,
109+ [ allowedZoom , location , weatherData , zoom ] ,
105110 )
106111
107- React . useEffect ( ( ) => {
108- if ( zoom > allowedZoom ) {
109- const weatherCache = Object . values ( apolloClient . cache . extract ( ) ) . find (
110- ( x ) =>
111- x . __typename === 'Weather' &&
112- // @ts -ignore
113- booleanPointInPolygon ( point ( location ) , polygon ( [ x . polygon ] ) ) ,
114- )
115- if (
116- weatherCache &&
117- 'gameplay_condition' in weatherCache &&
118- weatherCache ?. gameplay_condition !== active ?. gameplay_condition
119- ) {
120- // @ts -ignore
121- setActive ( weatherCache )
122- }
123- } else {
124- setActive ( null )
125- }
126- } , [ location , zoom , allowedZoom ] )
127-
128112 if ( ! weatherEnabled || ! active ) return null
129- return < WeatherMemo { ...active } />
113+ return < Weather { ...active } />
130114}
0 commit comments