added night iamge
This commit is contained in:
@@ -1,10 +1,24 @@
|
|||||||
|
import { useEffect } from "react"; // ...existing code...
|
||||||
import { useMrtStore } from "_store/pilot/MrtStore";
|
import { useMrtStore } from "_store/pilot/MrtStore";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import DAY_BASE_IMG from "./images/Base_NoScreen_Day.png";
|
import DAY_BASE_IMG from "./images/Base_NoScreen_Day.png";
|
||||||
import NIGHT_BASE_IMG from "./images/Base_NoScreen_Night.png";
|
import NIGHT_BASE_IMG from "./images/Base_NoScreen_Night.png";
|
||||||
|
|
||||||
export const MrtBase = () => {
|
export const MrtBase = () => {
|
||||||
const { nightMode } = useMrtStore((state) => state);
|
const { nightMode, setNightMode } = useMrtStore((state) => state);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const checkNightMode = () => {
|
||||||
|
const currentHour = new Date().getHours();
|
||||||
|
setNightMode(currentHour >= 22 || currentHour < 8);
|
||||||
|
};
|
||||||
|
|
||||||
|
checkNightMode(); // Initial check
|
||||||
|
const intervalId = setInterval(checkNightMode, 60000); // Check every minute
|
||||||
|
|
||||||
|
return () => clearInterval(intervalId); // Cleanup on unmount
|
||||||
|
}, [setNightMode]); // ...existing code...
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Image
|
<Image
|
||||||
src={nightMode ? NIGHT_BASE_IMG : DAY_BASE_IMG}
|
src={nightMode ? NIGHT_BASE_IMG : DAY_BASE_IMG}
|
||||||
|
|||||||
Reference in New Issue
Block a user