Skip to content

Commit 99746cb

Browse files
committed
feat: Now refreshing the shapes once created
1 parent cfd0e61 commit 99746cb

3 files changed

Lines changed: 42 additions & 8 deletions

File tree

components/core/App.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,18 @@ const App = (props) => {
1818
const [loading, setLoading] = useState(true); // shapes loading
1919

2020
const [searchTerm, setSearchTerm] = useState(""); // search
21-
const [sort, setSort] = useState("popularity"); // sort
21+
const [sort, setSort] = useState("recent"); // sort
22+
23+
const [shapeAction, setShapeAction] = useState({
24+
'action': '',
25+
'payload': {}
26+
});
2227

2328
const { user } = props;
2429

2530
useEffect(async () => {
2631
setData([]);
2732
setLoading(true);
28-
2933
let shapes = [];
3034

3135
if(user.length === 0) {
@@ -84,18 +88,21 @@ const App = (props) => {
8488
});
8589

8690
console.log(shapes);
87-
91+
console.log({shapeAction});
8892
await setData(shapes);
93+
console.log(shapes);
8994
setLoading(false);
90-
}, [user]);
95+
}, [user, shapeAction]);
9196

9297
return (
9398
<>
9499
<Header {...props}
95100
searchTerm={searchTerm}
96101
setSearchTerm={setSearchTerm}
97102
sort={sort}
98-
setSort={setSort} />
103+
setSort={setSort}
104+
shapeAction={shapeAction}
105+
setShapeAction={setShapeAction} />
99106
{loading ? (
100107
<Loader
101108
style={{margin: '20% auto auto 42%'}}

components/core/CreateShape.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const CreateShape = (props) => {
2222
"edges": 4,
2323
"notes": "",
2424
"clipPathType": "polygon",
25-
"showShadow": false,
25+
"showShadow": true,
2626
"backgroundColor": "#d61284",
2727
"verticeCoordinates" : [
2828
{
@@ -258,6 +258,26 @@ const CreateShape = (props) => {
258258
}
259259
props.handleClose();
260260
toast.success(`Shape ${shapeInformation.name} created successfully.`);
261+
props.setShapeAction({
262+
...props.shapeAction,
263+
"action": "add",
264+
"payload": {
265+
"backgroundColor": shapeInformation.backgroundColor,
266+
"createdAt": null,
267+
"createdBy": props.user.email,
268+
"edges": shapeInformation.edges,
269+
"email": null,
270+
"email1": props.user.email,
271+
"formula": shapeInformation.formula,
272+
"likes": 0,
273+
"name": shapeInformation.name,
274+
"name1": props.user.displayName,
275+
"notes": shapeInformation.notes,
276+
"photoURL": props.user.photoURL,
277+
"private": shapeInformation.private,
278+
"type": shapeInformation.clipPathType
279+
}
280+
});
261281
}
262282

263283
return(

components/utils/Header.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ const Header = ({
137137
searchTerm,
138138
setSearchTerm,
139139
sort,
140-
setSort
140+
setSort,
141+
shapeAction,
142+
setShapeAction
141143
}) => {
142144

143145
const [searchterm, setSearchterm] = useState('');
@@ -233,7 +235,12 @@ const Header = ({
233235
<div>Sign In</div>
234236
</Button>
235237
)}
236-
<CreateShape show={showCreateShape} handleClose={closeModal} user={user} />
238+
<CreateShape
239+
show={showCreateShape}
240+
handleClose={closeModal}
241+
user={user}
242+
shapeAction={shapeAction}
243+
setShapeAction={setShapeAction} />
237244
</AppHeader>
238245
);
239246
};

0 commit comments

Comments
 (0)