|
1 | 1 | "use client"; |
2 | 2 | import ComplexityGraph from "@/app/components/ui/graph"; |
| 3 | +import { useEffect, useState } from "react"; |
3 | 4 |
|
4 | 5 | const content = () => { |
| 6 | + const [theme, setTheme] = useState('light'); |
| 7 | + const [mounted, setMounted] = useState(false); |
| 8 | + |
| 9 | + useEffect(() => { |
| 10 | + const updateTheme = () => { |
| 11 | + const savedTheme = localStorage.getItem('theme') || 'light'; |
| 12 | + setTheme(savedTheme); |
| 13 | + }; |
| 14 | + |
| 15 | + updateTheme(); |
| 16 | + setMounted(true); |
| 17 | + |
| 18 | + window.addEventListener('storage', updateTheme); |
| 19 | + window.addEventListener('themeChange', updateTheme); |
| 20 | + |
| 21 | + return () => { |
| 22 | + window.removeEventListener('storage', updateTheme); |
| 23 | + window.removeEventListener('themeChange', updateTheme); |
| 24 | + }; |
| 25 | + }, []); |
| 26 | + |
5 | 27 | const paragraph = [ |
6 | 28 | `Merge Sort is an efficient, stable, comparison-based sorting algorithm that follows the divide-and-conquer approach. It works by recursively dividing the unsorted list into sublists until each sublist contains a single element, then repeatedly merges these sublists to produce new sorted sublists until there is only one sorted list remaining.`, |
7 | 29 | `The log n factor comes from the division steps, while the n factor comes from the merge steps.`, |
@@ -66,12 +88,19 @@ const content = () => { |
66 | 88 | <main className="max-w-7xl mx-auto grid grid-cols-1 md:grid-cols-5 md:gap-4"> |
67 | 89 | <div className="col-span-1"> |
68 | 90 | <div className="hidden md:block"> |
69 | | - <iframe |
70 | | - src="https://hw.glich.co/resources/embed/daily/dsa" |
71 | | - width="100%" |
72 | | - height="400" |
73 | | - title="Daily DSA Challenge" |
74 | | - ></iframe> |
| 91 | + {mounted && ( |
| 92 | + <iframe |
| 93 | + key={theme} |
| 94 | + src={ |
| 95 | + theme === "dark" |
| 96 | + ? "https://hw.glich.co/resources/embed/daily/dsa?theme=dark" |
| 97 | + : "https://hw.glich.co/resources/embed/daily/dsa?theme=light" |
| 98 | + } |
| 99 | + width="100%" |
| 100 | + height="400" |
| 101 | + title="Daily DSA Challenge" |
| 102 | + ></iframe> |
| 103 | + )} |
75 | 104 | </div> |
76 | 105 | <div className="flex justify-center"> |
77 | 106 | <span className="text-xs hidden md:block"> |
@@ -230,6 +259,35 @@ const content = () => { |
230 | 259 | </div> |
231 | 260 | </section> |
232 | 261 | </article> |
| 262 | + |
| 263 | + {/* Mobile iframe at bottom */} |
| 264 | + <div className="block md:hidden w-full"> |
| 265 | + {mounted && ( |
| 266 | + <iframe |
| 267 | + key={theme} |
| 268 | + src={ |
| 269 | + theme === "dark" |
| 270 | + ? "https://hw.glich.co/resources/embed/daily/dsa?theme=dark" |
| 271 | + : "https://hw.glich.co/resources/embed/daily/dsa?theme=light" |
| 272 | + } |
| 273 | + width="100%" |
| 274 | + height="320" |
| 275 | + title="Daily DSA Challenge" |
| 276 | + ></iframe> |
| 277 | + )} |
| 278 | + <div className="flex justify-center pb-8"> |
| 279 | + <span className="text-xs"> |
| 280 | + Powered by{" "} |
| 281 | + <a |
| 282 | + href="https://hw.glich.co/resources/daily" |
| 283 | + target="_blank" |
| 284 | + className="underline hover:text-blue-500 duration-300" |
| 285 | + > |
| 286 | + Hello World |
| 287 | + </a> |
| 288 | + </span> |
| 289 | + </div> |
| 290 | + </div> |
233 | 291 | </main> |
234 | 292 | ); |
235 | 293 | }; |
|
0 commit comments