Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: svg re-render on theme change #7

Merged
merged 1 commit into from
Oct 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
dist
dist
debug.log
16 changes: 10 additions & 6 deletions src/components/home.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { h } from 'preact';
import { useRef, useState } from 'preact/hooks'
import { h } from 'preact'
import { useRef, useState, useEffect } from 'preact/hooks'
import Canvas from './canvas'
import CustomBar from './customBar'
import Navbar from './nav'
Expand All @@ -25,8 +25,13 @@ function Home({ isDark, toggleDarkMode }) {
strokeColor: 'none',
})

const waveSvg = waveInit(wave)
const { height, width, xmlns, path } = waveSvg.svg
const [waveSvg, setWaveSvg] = useState(waveInit(wave))

useEffect(() => {
setWaveSvg(waveInit(wave))
}, [wave])

const { height, xmlns, path } = waveSvg.svg
const num_waves = path.length
const opac = OPACITY_ARR.slice(MAX_WAVES - num_waves)

Expand Down Expand Up @@ -77,7 +82,7 @@ function Home({ isDark, toggleDarkMode }) {

return (
<div className="relative h-screen dark:bg-darkish-black">
<Navbar isDark={isDark} toggleDarkMode={toggleDarkMode} color={bgColor}/>
<Navbar isDark={isDark} toggleDarkMode={toggleDarkMode} color={bgColor} />
<div
className="flex flex-col items-center justify-center h-screen p-0 dark:bg-darkish-black "
style={{ backgroundColor: isDark ? '#131e2b66' : `${bgColor}33` }}
Expand All @@ -103,7 +108,6 @@ function Home({ isDark, toggleDarkMode }) {
<div className="z-20 flex h-12 text-lg font-bold text-black footer dark:text-white">
Made with ❤ - by <a href="https://www.anup.tech" className="ml-2 underline"> Anup</a>
</div>

</div>
</div>
)
Expand Down