From e91c3cd615863173ca1189bcc0845fa7ca1ca86e Mon Sep 17 00:00:00 2001 From: stigus Date: Thu, 2 Nov 2023 10:36:03 +0100 Subject: [PATCH] =?UTF-8?q?Sjekker=20n=C3=A5=20YR=20for=20nedboerType=20ne?= =?UTF-8?q?ste=206=20timer=20for=20=C3=A5=20avgj=C3=B8re=20om=20det=20er?= =?UTF-8?q?=20regn=20eller=20sn=C3=B8=20som=20skal=20vises=20p=C3=A5=20inn?= =?UTF-8?q?logging=20#deploy-test-frontend?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/ui/background/Background.tsx | 21 +++++++++---------- .../main/js/src/utils/hooks/useWeather.tsx | 8 +++++++ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/apps/dolly-frontend/src/main/js/src/components/ui/background/Background.tsx b/apps/dolly-frontend/src/main/js/src/components/ui/background/Background.tsx index 4f4e1ddde38..c7fb579746b 100644 --- a/apps/dolly-frontend/src/main/js/src/components/ui/background/Background.tsx +++ b/apps/dolly-frontend/src/main/js/src/components/ui/background/Background.tsx @@ -20,7 +20,7 @@ import Faarikaal from '@/components/ui/background/backgrounds/Faarikaal.svg' import '@/snow.scss' import '@/rain.scss' import '@/flowers.scss' -import { useWeatherFyrstikkAlleen } from '@/utils/hooks/useWeather' +import { NEDBOER_TYPE, useWeatherFyrstikkAlleen } from '@/utils/hooks/useWeather' import * as _ from 'lodash-es' const month = new Date().getMonth() @@ -66,7 +66,7 @@ const DefaultBackground = styled.div` }}; ` -const animateNedboer = (millimeterNedboer: number) => { +const animateNedboer = (millimeterNedboer: number, nedBoerType: NEDBOER_TYPE) => { const month = new Date().getMonth() if (month >= 2 && month <= 4) { return ( @@ -76,29 +76,28 @@ const animateNedboer = (millimeterNedboer: number) => { ))} ) - } else if (month >= 5 && month <= 10) { + } else if (nedBoerType === NEDBOER_TYPE.SNOW) { return ( <> - {Array.from(Array(3 * _.round(millimeterNedboer) * 10).keys()).map((idx) => ( -
+ {Array.from(Array(70).keys()).map((idx) => ( +
))} ) - } else if (month === 11 || month === 0 || month === 1) { + } else { return ( <> - {Array.from(Array(70).keys()).map((idx) => ( -
+ {Array.from(Array(3 * _.round(millimeterNedboer) * 10).keys()).map((idx) => ( +
))} ) } - return null } export const Background = (props: any) => { - const { millimeterNedboer = 0 } = useWeatherFyrstikkAlleen() - const nedboer = animateNedboer(millimeterNedboer) + const { millimeterNedboer = 0, nedBoerType } = useWeatherFyrstikkAlleen() + const nedboer = animateNedboer(millimeterNedboer, nedBoerType) return ( <> {!isEaster && nedboer} diff --git a/apps/dolly-frontend/src/main/js/src/utils/hooks/useWeather.tsx b/apps/dolly-frontend/src/main/js/src/utils/hooks/useWeather.tsx index 3f9a21628e0..d1e25795b74 100644 --- a/apps/dolly-frontend/src/main/js/src/utils/hooks/useWeather.tsx +++ b/apps/dolly-frontend/src/main/js/src/utils/hooks/useWeather.tsx @@ -4,6 +4,11 @@ import { fetcher } from '@/api' const fyrstikkAlleenForecastUrl = 'https://api.met.no/weatherapi/locationforecast/2.0/compact?lat=59.91254828924253&lon=10.796522002335804' +export enum NEDBOER_TYPE { + SNOW, + RAIN, +} + export const useWeatherFyrstikkAlleen = () => { const { data, isLoading, error } = useSWR(fyrstikkAlleenForecastUrl, fetcher, { dedupingInterval: 60000, @@ -12,8 +17,11 @@ export const useWeatherFyrstikkAlleen = () => { const millimeterNedboer = data?.properties?.timeseries?.[0]?.data?.next_6_hours?.details?.precipitation_amount + const nedBoerType = data?.properties?.timeseries?.[0]?.data?.next_6_hours?.summary?.symbol_code + return { millimeterNedboer: millimeterNedboer ? millimeterNedboer * 10 : 0, + nedBoerType: nedBoerType?.includes('snow') ? NEDBOER_TYPE.SNOW : NEDBOER_TYPE.RAIN, loading: isLoading, error: error, }