Skip to content

Commit

Permalink
Sjekker nå YR for nedboerType neste 6 timer for å avgjøre om det er r…
Browse files Browse the repository at this point in the history
…egn eller snø som skal vises på innlogging

#deploy-test-frontend
  • Loading branch information
stigus committed Nov 2, 2023
1 parent 59e0af5 commit e91c3cd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 (
Expand All @@ -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) => (
<div key={idx} className="rain" />
{Array.from(Array(70).keys()).map((idx) => (
<div key={idx} className="snowflake" />
))}
</>
)
} else if (month === 11 || month === 0 || month === 1) {
} else {
return (
<>
{Array.from(Array(70).keys()).map((idx) => (
<div key={idx} className="snowflake" />
{Array.from(Array(3 * _.round(millimeterNedboer) * 10).keys()).map((idx) => (
<div key={idx} className="rain" />
))}
</>
)
}
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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<any, Error>(fyrstikkAlleenForecastUrl, fetcher, {
dedupingInterval: 60000,
Expand All @@ -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,
}
Expand Down

0 comments on commit e91c3cd

Please sign in to comment.