|
3 | 3 | </template> |
4 | 4 |
|
5 | 5 | <script setup lang="ts"> |
6 | | -import { ref, onMounted, onUnmounted, watch } from 'vue' |
7 | | -import { usePreferredDark } from '@vueuse/core' // VueUse composable to detect dark mode |
| 6 | +import { ref, onMounted, onUnmounted, watch, watchEffect} from 'vue' |
| 7 | +import { useColorMode } from '@vueuse/core' // VueUse composable to detect dark mode |
| 8 | +
|
| 9 | +const props = defineProps<{ |
| 10 | + isDarkMode: string |
| 11 | +}>() |
8 | 12 |
|
9 | 13 | const globeContainer = ref<HTMLElement | null>(null) |
10 | 14 | let Globe: any |
11 | 15 | let globeInstance: any = null |
12 | 16 |
|
13 | | -// Detect dark mode |
14 | | -const isDarkMode = usePreferredDark() |
| 17 | +// Function to update globe texture |
| 18 | +const updateGlobeTexture = () => { |
| 19 | + if (globeInstance) { |
| 20 | + const newTextureUrl = props.isDarkMode === 'dark' |
| 21 | + ? '//unpkg.com/three-globe/example/img/earth-night.jpg' |
| 22 | + : '//unpkg.com/three-globe/example/img/earth-day.jpg'; |
| 23 | + console.log('Updating globe texture to:', newTextureUrl); |
| 24 | + globeInstance.globeImageUrl(newTextureUrl); |
| 25 | + } else { |
| 26 | + console.warn('globeInstance is not initialized yet.'); |
| 27 | + } |
| 28 | +} |
15 | 29 |
|
16 | 30 | // Import Globe.gl dynamically only on client-side |
17 | 31 | onMounted(async () => { |
18 | | - Globe = (await import('globe.gl')).default |
19 | | - initGlobe() |
20 | | -}) |
21 | | -
|
22 | | -// Watch for changes in dark mode and update globe texture |
23 | | -watch(isDarkMode, (newVal) => { |
24 | | - if (globeInstance) { |
25 | | - globeInstance.globeImageUrl(newVal |
26 | | - ? '//unpkg.com/three-globe/example/img/earth-night.jpg' |
27 | | - : '//unpkg.com/three-globe/example/img/earth-day.jpg') |
28 | | - } |
29 | | -}) |
| 32 | + Globe = (await import('globe.gl')).default; |
| 33 | + initGlobe(); |
| 34 | + updateGlobeTexture(); |
| 35 | +}); |
30 | 36 |
|
31 | 37 | // Constants for arc animation |
32 | 38 | const ARC_REL_LEN = 0.4 |
@@ -151,8 +157,8 @@ const initGlobe = () => { |
151 | 157 | if (!globeContainer.value) return |
152 | 158 | // @ts-ignore |
153 | 159 | globeInstance = new Globe() |
154 | | - .globeImageUrl(isDarkMode.value |
155 | | - ? '//unpkg.com/three-globe/example/img/earth-night.jpg' |
| 160 | + .globeImageUrl(props.isDarkMode === 'dark' |
| 161 | + ? '//unpkg.com/three-globe/example/img/earth-night.jpg' |
156 | 162 | : '//unpkg.com/three-globe/example/img/earth-day.jpg') |
157 | 163 | .backgroundColor('rgba(0,0,0,0)') |
158 | 164 | .width(globeContainer.value.offsetWidth) |
@@ -188,6 +194,10 @@ const initGlobe = () => { |
188 | 194 | // Regular emission interval |
189 | 195 | const interval = setInterval(emitArcs, FLIGHT_TIME * 1.5) |
190 | 196 | globeInstance.__interval = interval |
| 197 | +
|
| 198 | + console.log('Globe initialized with texture:', props.isDarkMode |
| 199 | + ? '//unpkg.com/three-globe/example/img/earth-night.jpg' |
| 200 | + : '//unpkg.com/three-globe/example/img/earth-day.jpg') |
191 | 201 | } |
192 | 202 |
|
193 | 203 | onUnmounted(() => { |
|
0 commit comments