From 948f126f15bbf95ed5300b2ba40afbab6d874e0f Mon Sep 17 00:00:00 2001 From: Violet Date: Fri, 2 Dec 2022 00:39:21 -0500 Subject: [PATCH 1/2] reduced snowfall for fun while temp range is > 10 --- src/features/shared/Snowfall.jsx | 48 +++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/src/features/shared/Snowfall.jsx b/src/features/shared/Snowfall.jsx index ac64295..86b582f 100644 --- a/src/features/shared/Snowfall.jsx +++ b/src/features/shared/Snowfall.jsx @@ -6,8 +6,54 @@ import { } from "../../constants/themeIds"; import { useSelector } from "react-redux"; import GetTheme from "../../themes/ThemeProvider"; +import { useState } from "react"; +import { useEffect } from "react"; export default function SnowfallWrapper() { + const [snowflakeCount, setSnowflakeCount] = useState(150); + const [isSnowReducerRunning, setIsSnowReducerRunning] = useState(false); + + const isHeatOn = useSelector((state) => state.deviceInteraction.isHeatOn); + + const currentTargetTemperature = useSelector( + (state) => state.deviceInteraction.targetTemperature + ); + + const currentTemperature = useSelector( + (state) => state.deviceInteraction.currentTemperature + ); + + useEffect(() => { + let intervalId; + if (isSnowReducerRunning) { + intervalId = setInterval(() => { + reduceStorm(); + }, 400); + } + + return () => clearInterval(intervalId); + }, [isSnowReducerRunning]); + + const reduceStorm = () => { + setSnowflakeCount((currentCount) => { + const newSnowflakeCount = currentCount - 5; + if (newSnowflakeCount < 10) return 10; + return newSnowflakeCount; + }); + }; + + useEffect(() => { + if ( + isHeatOn && + Math.abs(currentTargetTemperature - currentTemperature) > 5 + ) { + setIsSnowReducerRunning(true); + } else { + setIsSnowReducerRunning(false); + setSnowflakeCount(150); + } + }, [isHeatOn, currentTargetTemperature, currentTemperature]); + const theme = useSelector( (state) => state.settings.config?.currentTheme || GetTheme().themeId ); @@ -30,7 +76,7 @@ export default function SnowfallWrapper() { return ; case funId: return ( - + /* Date: Sat, 3 Dec 2022 17:39:00 -0500 Subject: [PATCH 2/2] tweaked snow reduction rate --- src/features/shared/Snowfall.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/features/shared/Snowfall.jsx b/src/features/shared/Snowfall.jsx index 202cd80..a1e99f2 100644 --- a/src/features/shared/Snowfall.jsx +++ b/src/features/shared/Snowfall.jsx @@ -30,7 +30,7 @@ export default function SnowfallWrapper() { if (isSnowReducerRunning) { intervalId = setInterval(() => { reduceStorm(); - }, 400); + }, 125); } return () => clearInterval(intervalId); @@ -38,7 +38,7 @@ export default function SnowfallWrapper() { const reduceStorm = () => { setSnowflakeCount((currentCount) => { - const newSnowflakeCount = currentCount - 5; + const newSnowflakeCount = currentCount - 1; if (newSnowflakeCount < 10) return 10; return newSnowflakeCount; });