Skip to content

Commit

Permalink
refactor: setup files path and placement
Browse files Browse the repository at this point in the history
  • Loading branch information
AlkenD committed Sep 11, 2024
1 parent aa482fc commit d9a3f1b
Show file tree
Hide file tree
Showing 4 changed files with 204 additions and 196 deletions.
54 changes: 27 additions & 27 deletions src/renderer/src/components/layouts/SetupLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import setupBackground from '../../assets/images/setupBackground.png'
import SetupTracker from '../ui/SetupTracker'
import { motion } from 'framer-motion'
import { useState } from 'react'
import ServerSetupForm from '../setup/forms/ServerSetupForm'
import CreateUsersForm from '../setup/forms/CreateUsersForm'
import CreateCollectionsForm from '../setup/forms/CreateCollectionsForm'
import setupBackground from "../../assets/images/setupBackground.png";
import { motion } from "framer-motion";
import { useState } from "react";
import ServerSetupForm from "../setup/forms/ServerSetupForm";
import CreateUsersForm from "../setup/forms/CreateUsersForm";
import CreateCollectionsForm from "../setup/forms/CreateCollectionsForm";
import SetupComponent from "../setup";

const SetupLayout = () => {
const [activeIndex, setActiveIndex] = useState(1)
const [complete, setComplete] = useState(false)
const [activeIndex, setActiveIndex] = useState(1);
const [complete, setComplete] = useState(false);

const setupItems = [
{
index: 1,
form: <ServerSetupForm />
form: <ServerSetupForm />,
},
{
index: 2,
form: <CreateUsersForm />
form: <CreateUsersForm />,
},
{
index: 3,
form: <CreateCollectionsForm />
}
]
form: <CreateCollectionsForm />,
},
];

return (
<div
Expand All @@ -35,35 +35,35 @@ const SetupLayout = () => {
initial={{
opacity: 0,
width: 0,
height: 0
height: 0,
}}
animate={{
borderTopRightRadius: complete ? 6 : 800,
borderBottomRightRadius: complete ? 6 : 800,
borderBottomLeftRadius: complete ? 8 : 0,
width: complete ? '100%' : 'calc(100% - 340px)',
height: 'calc(100% + 128px)',
opacity: 1
width: complete ? "100%" : "calc(100% - 340px)",
height: "calc(100% + 128px)",
opacity: 1,
}}
transition={{
type: 'spring',
bounce: 0.2
type: "spring",
bounce: 0.2,
}}
className="absolute bg-gradient-to-t from-black to-neutral-800 -mt-32"
/>
<motion.div
initial={{
opacity: 0
opacity: 0,
}}
animate={{
opacity: 1
opacity: 1,
}}
exit={{
opacity: 0
opacity: 0,
}}
className="absolute top-0 left-0 h-full w-full"
>
<SetupTracker
<SetupComponent
items={setupItems}
activeIndex={activeIndex}
setActiveIndex={setActiveIndex}
Expand All @@ -72,7 +72,7 @@ const SetupLayout = () => {
/>
</motion.div>
</div>
)
}
);
};

export default SetupLayout
export default SetupLayout;
175 changes: 175 additions & 0 deletions src/renderer/src/components/setup/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
import { AnimatePresence, motion } from "framer-motion";
import { useState, useEffect } from "react";
import LogsComponent from "@renderer/components/setup/LogsComponent";
import Icon from "../ui/Icon";
import Button from "../ui/Button/Button";

const ProgressAnimate = ({ index, activeIndex, onClick, complete }) => {
const [shouldBounce, setShouldBounce] = useState(false);

useEffect(() => {
if (index === activeIndex) {
setShouldBounce(true);
const timer = setTimeout(() => setShouldBounce(false), 100);
return () => clearTimeout(timer);
}
}, [index, activeIndex]);

const isActive = index === activeIndex;
const isActiveOrPast = index <= activeIndex;

return (
<button
onClick={onClick}
className={`flex flex-col items-center space-y-2 cursor-default ${complete && "pointer-events-none opacity-20"}`}
>
<motion.div
variants={{
idle: { height: 0 },
active: { height: "24px" },
}}
animate={isActive ? "active" : "idle"}
className={`rounded-xl w-[2px] pointer-events-none ${isActiveOrPast ? "bg-emerald-400" : "bg-white"}`}
></motion.div>
<motion.div
className={`h-6 w-6 rounded-full font-semibold flex items-center cursor-pointer justify-center ${isActiveOrPast ? "bg-emerald-400" : "bg-white"}`}
variants={{
idle: { scale: 1 },
bounce: { scale: 1.2 },
}}
animate={shouldBounce ? "bounce" : "idle"}
transition={{
type: "spring",
}}
>
{complete ? <Icon name="check" stroke={3.5} /> : index}
</motion.div>
</button>
);
};

const SetupComponent = ({
complete,
setComplete,
activeIndex,
setActiveIndex,
items,
}) => {
const [showBackButton, setShowBackButton] = useState(activeIndex > 1);

useEffect(() => {
setShowBackButton(activeIndex > 1);
}, [activeIndex]);

const getCurrentForm = () => {
const currentItem = items.find((item) => item.index === activeIndex);
return currentItem ? currentItem.form : null;
};

const handleNext = () => {
if (activeIndex < items.length) {
setActiveIndex((prevIndex) => prevIndex + 1);
} else if (activeIndex === items.length) {
setComplete(true);
}
};

const handleBack = () => {
if (activeIndex > 1) {
setActiveIndex((prevIndex) => prevIndex - 1);
}
};

return (
<>
<div className="absolute left-6 top-0 bottom-0 my-auto h-fit space-y-2 flex flex-col items-center text-black text-xs font-semibold">
{items.map((item) => (
<ProgressAnimate
key={item.index}
index={item.index}
activeIndex={activeIndex}
onClick={() => {
setComplete(false);
setActiveIndex(item.index);
}}
complete={complete}
/>
))}
</div>
<AnimatePresence mode="wait">
{complete ? (
<motion.div
key="logs"
initial={{
opacity: 0,
}}
animate={{
opacity: 1,
}}
exit={{
opacity: 0,
}}
className="w-full h-full"
>
<LogsComponent />
</motion.div>
) : (
<motion.div
key="forms"
initial={{
opacity: 0,
}}
animate={{
opacity: 1,
}}
exit={{
opacity: 0,
}}
className="w-[820px] flex items-center justify-center h-[calc(100%-64px)] space-y-4"
>
<div className="h-fit w-[280px] space-y-4">
<AnimatePresence mode="wait">{getCurrentForm()}</AnimatePresence>
<div className="w-full h-px bg-gradient-to-r from-transparent via-emerald-400 to-transparent"></div>
<div className="flex items-center w-full">
<AnimatePresence>
{showBackButton && (
<motion.div
key="back"
initial={{ opacity: 0, width: 0, marginRight: 0 }}
animate={{ opacity: 1, width: "100%", marginRight: 16 }}
exit={{ opacity: 0, width: 0, marginRight: 0 }}
>
<Button
variant="ghostWhite"
fullWidth
label="Back"
onClick={handleBack}
/>
</motion.div>
)}
<motion.div
key="next"
initial={{ opacity: 0, width: 0 }}
animate={{
opacity: 1,
width: "100%",
}}
exit={{ opacity: 0, width: 0 }}
>
<Button
fullWidth
label={activeIndex === items.length ? "Done" : "Next"}
onClick={handleNext}
/>
</motion.div>
</AnimatePresence>
</div>
</div>
</motion.div>
)}
</AnimatePresence>
</>
);
};

export default SetupComponent;
Loading

0 comments on commit d9a3f1b

Please sign in to comment.