Skip to content

Commit c9916ef

Browse files
committed
use placeholder popup in AccountBottomBar
1 parent 791beab commit c9916ef

File tree

2 files changed

+155
-1
lines changed

2 files changed

+155
-1
lines changed

src/components/AccountBottomBar.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {IoMdAddCircleOutline} from "react-icons/io";
66
import { useProject } from 'providers/Project/projectHooks';
77
import { isUUUID } from "../util/url";
88
import useMousePosition from '../hooks/useMousePosition';
9+
import AutoTemplatePopup from 'components/AutoTemplatePopup'
910
import { Feedback as FeedbackRoot } from 'layout/Feedback';
1011
import { FeedbackActions } from 'layout/FeedbackActions';
1112
import { SidebarItemInsert } from 'layout/SidebarItemInsert';
@@ -149,7 +150,7 @@ const IdentifierList: React.FC<TypeListProps> = ({
149150
{types[identifier] == "Link" &&
150151
<BottomBarItemInsert onClick={ async () => {
151152
const res = await mutator.createTransactionTemplate("", `New Transaction`)
152-
navigate(`/${projectPath}?type=tx&id=${res.data?.createTransactionTemplate?.id}&storage=${selectedResourceAccount + 1 || 'none'}`)
153+
navigate(`/${projectPath}?type=tx&id=${res.data?.createTransactionTemplate?.id}&storage=${selectedResourceAccount || 'none'}`)
153154
}}>
154155
<IoMdAddCircleOutline size="20px" />
155156
</BottomBarItemInsert>
@@ -320,6 +321,8 @@ const AccountState: React.FC<{
320321
const AccountBottomBar: React.FC = () => {
321322
const { project, isLoading, selectedResourceAccount } = useProject();
322323

324+
const [showTemplatePopup, toggleShowTemplatePopup] = useState< boolean >(false)
325+
323326
const storageMap: { [account: string]: number} = {
324327
"0x01": 0,
325328
"0x02": 1,
@@ -340,6 +343,10 @@ const AccountBottomBar: React.FC = () => {
340343
return <FeedbackActions />;
341344
}}
342345
/>
346+
<AutoTemplatePopup visible={showTemplatePopup} triggerClose={()=>{
347+
toggleShowTemplatePopup(false)
348+
}}/>
349+
343350
</>
344351
)}
345352
</FeedbackRoot>
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
import React, { useState, useRef, useEffect } from 'react';
2+
import { uniqueNamesGenerator, adjectives, colors, } from 'unique-names-generator';
3+
import { FaSyncAlt } from 'react-icons/fa';
4+
import { useProject } from 'providers/Project/projectHooks';
5+
import { default as FlowButton } from 'components/Button';
6+
7+
import {
8+
FullScreenContainer,
9+
PopupContainer,
10+
PopupHeader,
11+
WhiteOverlay,
12+
SpaceBetween,
13+
} from 'components/Common';
14+
15+
import { createZip } from '../util/generator';
16+
17+
import {
18+
Input,
19+
InputBlock, InputIcon,
20+
Label,
21+
} from 'components/Arguments/SingleArgument/styles';
22+
23+
const generateProjectName = () => {
24+
const prefix: string = uniqueNamesGenerator({
25+
dictionaries: [colors, adjectives],
26+
separator: '-',
27+
length: 2,
28+
})
29+
30+
return `${prefix}-playground`
31+
}
32+
33+
const AutoTemplatePopup: React.FC<{
34+
visible: boolean;
35+
triggerClose?: (e: React.SyntheticEvent) => any;
36+
}> = ({ visible, triggerClose }) => {
37+
const { project } = useProject();
38+
const [processing, setProcessing] = useState(false);
39+
const [projectName, setProjectName] = useState(generateProjectName());
40+
const [folderName, setFolderName] = useState('cadence');
41+
42+
const regenerateProjectName = () => {
43+
const newName = generateProjectName()
44+
setProjectName(newName)
45+
}
46+
47+
const firstInput = useRef<HTMLInputElement>(null!);
48+
49+
useEffect(() => {
50+
firstInput.current.focus();
51+
}, [firstInput.current]);
52+
53+
const containerFrames = {
54+
visible: {
55+
display: 'flex',
56+
opacity: 1,
57+
transition: {
58+
staggerChildren: 0.1,
59+
},
60+
zIndex: 20,
61+
},
62+
hidden: {
63+
opacity: 0,
64+
transition: {
65+
when: 'afterChildren',
66+
staggerChildren: 0,
67+
staggerDirection: -1,
68+
},
69+
zIndex: -1,
70+
},
71+
};
72+
73+
const spring = {
74+
type: 'spring',
75+
damping: 11,
76+
stiffness: 120,
77+
};
78+
79+
const popupFrames = {
80+
visible: {
81+
opacity: 1,
82+
y: 0,
83+
transition: spring,
84+
},
85+
hidden: {
86+
opacity: 0,
87+
y: -200,
88+
transition: {
89+
ease: [1, 0.5, 0, 0]
90+
},
91+
},
92+
};
93+
94+
return (
95+
<FullScreenContainer
96+
elevation={15}
97+
initial="hidden"
98+
animate={visible ? 'visible' : 'hidden'}
99+
variants={containerFrames}
100+
>
101+
<PopupContainer width="350px" variants={popupFrames}>
102+
<PopupHeader mb="20px" color="#575E89" lineColor="#B4BEFC">
103+
Export Project
104+
</PopupHeader>
105+
<InputBlock mb={'12px'}>
106+
<Label>Project Name</Label>
107+
<Input
108+
ref={firstInput}
109+
value={projectName}
110+
onChange={event => setProjectName(event.target.value)}
111+
/>
112+
<InputIcon icon={<FaSyncAlt/>} onClick={regenerateProjectName}/>
113+
</InputBlock>
114+
<InputBlock mb={'30px'}>
115+
<Label>Cadence Folder</Label>
116+
<Input
117+
value={folderName}
118+
onChange={event => setFolderName(event.target.value)}
119+
/>
120+
</InputBlock>
121+
{processing ? (
122+
<p>Processing...</p>
123+
) : (
124+
<SpaceBetween>
125+
<FlowButton className="grey modal" onClick={triggerClose}>
126+
Close
127+
</FlowButton>
128+
<FlowButton
129+
className="violet modal"
130+
onClick={async () => {
131+
setProcessing(true);
132+
await createZip(folderName, projectName, project);
133+
setProcessing(false);
134+
triggerClose(null);
135+
}}
136+
>
137+
Export
138+
</FlowButton>
139+
</SpaceBetween>
140+
)}
141+
</PopupContainer>
142+
<WhiteOverlay onClick={triggerClose} />
143+
</FullScreenContainer>
144+
);
145+
};
146+
147+
export default AutoTemplatePopup;

0 commit comments

Comments
 (0)