diff --git a/client/src/features/visualizer-threejs/VisualizerInstance.tsx b/client/src/features/visualizer-threejs/VisualizerInstance.tsx index e6f0f18b1..26688fbe7 100644 --- a/client/src/features/visualizer-threejs/VisualizerInstance.tsx +++ b/client/src/features/visualizer-threejs/VisualizerInstance.tsx @@ -6,12 +6,7 @@ import React, { useEffect, useRef } from "react"; import { RouteComponentProps } from "react-router-dom"; import * as THREE from "three"; import { Box3 } from "three"; -import { - ACCEPTED_BLOCK_COLORS, - PENDING_BLOCK_COLOR, - TIME_DIFF_COUNTER, - ZOOM_DEFAULT, -} from './constants' +import { ACCEPTED_BLOCK_COLORS, DIRECTIONAL_LIGHT_INTENSITY, PENDING_BLOCK_COLOR, TIME_DIFF_COUNTER, VISUALIZER_BACKGROUND, ZOOM_DEFAULT } from "./constants"; import Emitter from "./Emitter"; import { useTangleStore, useConfigStore } from "./store"; import { getGenerateY, randomIntFromInterval, timer } from "./utils"; @@ -24,6 +19,7 @@ import { NovaFeedClient } from "../../services/nova/novaFeedClient"; import { Wrapper } from "./wrapper/Wrapper"; import "./Visualizer.scss"; import { IFeedBlockMetadata } from "~/models/api/stardust/feed/IFeedBlockMetadata"; +import { useGetThemeMode } from '~/helpers/hooks/useGetThemeMode'; import { StardustFeedClient } from "~/services/stardust/stardustFeedClient"; const features = { @@ -40,6 +36,7 @@ const VisualizerInstance: React.FC> = }) => { const [networkConfig] = useNetworkConfig(network); const generateY = getGenerateY({ withRandom: true }); + const themeMode = useGetThemeMode() const [runListeners, setRunListeners] = React.useState(false); @@ -228,9 +225,9 @@ const VisualizerInstance: React.FC> = position={[0, 0, 1500]} zoom={ZOOM_DEFAULT} /> - + - + = { + [ThemeMode.Dark]: "#000000", + [ThemeMode.Light]: "#f2f2f2", +} // emitter diff --git a/client/src/features/visualizer-threejs/enums.ts b/client/src/features/visualizer-threejs/enums.ts new file mode 100644 index 000000000..360b12a6a --- /dev/null +++ b/client/src/features/visualizer-threejs/enums.ts @@ -0,0 +1,4 @@ +export enum ThemeMode { + Light = "light", + Dark = "dark" +} diff --git a/client/src/helpers/hooks/useGetThemeMode.ts b/client/src/helpers/hooks/useGetThemeMode.ts new file mode 100644 index 000000000..a7ba6cb5f --- /dev/null +++ b/client/src/helpers/hooks/useGetThemeMode.ts @@ -0,0 +1,30 @@ +import { useEffect, useState } from 'react' +import { ServiceFactory } from '~/factories/serviceFactory' +import { ThemeMode } from '~/features/visualizer-threejs/enums'; +import { SettingsService } from '~/services/settingsService' + +export function useGetThemeMode(): ThemeMode { + const [settingsService] = useState( + ServiceFactory.get('settings') + ) + + const [isDarkMode, setIsDarkMode] = useState( + settingsService.get().darkMode ?? null + ) + + const themeMode = isDarkMode ? ThemeMode.Dark : ThemeMode.Light + + function toggleDarkMode(event: Event): void { + const darkMode = (event as CustomEvent).detail.darkMode + setIsDarkMode(darkMode) + } + + useEffect(() => { + window.addEventListener('theme-change', toggleDarkMode) + return () => { + window.removeEventListener('theme-change', toggleDarkMode) + } + }, []) + + return themeMode +}