-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ability to load colors via searchParams
- Loading branch information
1 parent
b3a71e0
commit 1435cec
Showing
4 changed files
with
85 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
"use client"; | ||
|
||
import { colorHelper } from "@/lib/colorHelper"; | ||
import { useColorStore } from "@/store/store"; | ||
import { AnimatePresence, motion } from "framer-motion"; | ||
import { useSearchParams } from "next/navigation"; | ||
import { useEffect, useState } from "react"; | ||
|
||
function ExistingColorsOverwritter({ searchParams }) { | ||
const { updateBaseColor } = useColorStore(); | ||
const colors = searchParams.colors; | ||
const [loading, setLoading] = useState(colors ? true : false); | ||
useEffect(() => { | ||
if (!colors) return; | ||
const colorArray = colors.split(","); | ||
const baseColors = { | ||
primary: colorHelper.toRaw(colorArray[0]), | ||
secondary: colorHelper.toRaw(colorArray[1]), | ||
accent: colorHelper.toRaw(colorArray[2]), | ||
}; | ||
setTimeout(() => { | ||
updateBaseColor("primary", baseColors.primary); | ||
updateBaseColor("secondary", baseColors.secondary); | ||
updateBaseColor("accent", baseColors.accent); | ||
setLoading(false); | ||
}, 200); | ||
}, []); | ||
return ( | ||
<AnimatePresence> | ||
{loading && ( | ||
<motion.div | ||
initial={{ opacity: 1 }} | ||
animate={{ opacity: 1 }} | ||
exit={{ opacity: 0, transition: { delay: 0.3 } }} | ||
className="fixed left-0 top-0 z-50 flex h-screen w-screen items-center justify-center bg-background" | ||
> | ||
<div className="flex flex-col items-center space-y-4"> | ||
<div className="text-primary">Loading</div> | ||
<div className="flex space-x-2"> | ||
<div className="h-4 w-4 animate-bounce rounded-full bg-primary transition-colors"></div> | ||
<div className="h-4 w-4 animate-bounce rounded-full bg-secondary transition-colors"></div> | ||
<div className="h-4 w-4 animate-bounce rounded-full bg-accent transition-colors"></div> | ||
</div> | ||
</div> | ||
</motion.div> | ||
)} | ||
</AnimatePresence> | ||
); | ||
} | ||
|
||
export default ExistingColorsOverwritter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters