feat: Add uploadFlow function to import from JSON button
This commit is contained in:
parent
da703d65e3
commit
bfc8ad8e30
2 changed files with 22 additions and 11 deletions
|
|
@ -1,14 +1,15 @@
|
||||||
import { useState } from "react";
|
import { Fragment, useState } from "react";
|
||||||
import IconComponent from "../genericIconComponent";
|
import IconComponent from "../genericIconComponent";
|
||||||
import { Button } from "../ui/button";
|
import { Button } from "../ui/button";
|
||||||
import { dropdownButtonPropsType } from "../../types/components";
|
import { dropdownButtonPropsType } from "../../types/components";
|
||||||
|
import { Transition } from "@headlessui/react";
|
||||||
|
|
||||||
export default function DropdownButton({
|
export default function DropdownButton({
|
||||||
firstButtonName,
|
firstButtonName,
|
||||||
onFirstBtnClick,
|
onFirstBtnClick,
|
||||||
options,
|
options,
|
||||||
}: dropdownButtonPropsType): JSX.Element {
|
}: dropdownButtonPropsType): JSX.Element {
|
||||||
const [showOptions, setShowOptions] = useState(false);
|
const [showOptions, setShowOptions] = useState<boolean>(false);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="align-center relative flex">
|
<div className="align-center relative flex">
|
||||||
|
|
@ -36,20 +37,29 @@ export default function DropdownButton({
|
||||||
)}
|
)}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
{showOptions && (
|
<Transition
|
||||||
<div className="absolute top-10 w-full">
|
show={showOptions}
|
||||||
{options.map(({ name, onBtnClick }) => (
|
leave="transition ease-in duration-100"
|
||||||
|
leaveFrom="opacity-100"
|
||||||
|
leaveTo="opacity-0"
|
||||||
|
as={Fragment}
|
||||||
|
enter="transition ease-in duration-100"
|
||||||
|
enterFrom="opacity-0"
|
||||||
|
enterTo="opacity-100"
|
||||||
|
>
|
||||||
|
<div className="absolute top-10 w-full bg-background pb-0.5 pr-0.5 pl-0.5 rounded-lg shadow-lg ">
|
||||||
|
{options.map(({ name, onBtnClick }, index) => (
|
||||||
<Button
|
<Button
|
||||||
className="w-full"
|
className="w-full mt-1"
|
||||||
variant="primary"
|
variant="primary"
|
||||||
onClick={onBtnClick}
|
onClick={onBtnClick}
|
||||||
key={name}
|
key={index}
|
||||||
>
|
>
|
||||||
{name}
|
{name}
|
||||||
</Button>
|
</Button>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
)}
|
</Transition>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,9 @@ import { USER_PROJECTS_HEADER } from "../../constants/constants";
|
||||||
import { TabsContext } from "../../contexts/tabsContext";
|
import { TabsContext } from "../../contexts/tabsContext";
|
||||||
import DropdownButton from "../../components/DropdownButtonComponent";
|
import DropdownButton from "../../components/DropdownButtonComponent";
|
||||||
export default function HomePage(): JSX.Element {
|
export default function HomePage(): JSX.Element {
|
||||||
const { flows, setTabId, downloadFlows, uploadFlows, addFlow, removeFlow } =
|
const { flows, setTabId, downloadFlows, uploadFlows, addFlow, removeFlow, uploadFlow } =
|
||||||
useContext(TabsContext);
|
useContext(TabsContext);
|
||||||
|
const dropdownOptions = [{name: "Import from JSON", onBtnClick: () => uploadFlow(true)}]
|
||||||
|
|
||||||
// Set a null id
|
// Set a null id
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -53,12 +54,12 @@ export default function HomePage(): JSX.Element {
|
||||||
navigate("/flow/" + id);
|
navigate("/flow/" + id);
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
options={[{name: "Import from JSON", onBtnClick: () => console.log('imported')}]}
|
options={dropdownOptions}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<span className="main-page-description-text">
|
<span className="main-page-description-text">
|
||||||
Manage your personal projects. Download or upload your collection.
|
Manage your personal projects. Download or upload your collection.
|
||||||
</span>
|
</span>
|
||||||
<div className="main-page-flows-display">
|
<div className="main-page-flows-display">
|
||||||
{flows.map((flow, idx) => (
|
{flows.map((flow, idx) => (
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue