Skip to content

Commit 4049c6c

Browse files
authored
Merge pull request #18 from TryShape/issue-17-user-shape-backend
Issue 17 user shape backend
2 parents 2e5ce7f + 6b0eaa9 commit 4049c6c

6 files changed

Lines changed: 181 additions & 137 deletions

File tree

components/core/App.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import dynamic from "next/dynamic";
55
import { harperFetch } from "../../utils/HarperFetch";
66

77
// Dummy Shape Data
8-
import { shapes } from "../../data/shapes";
8+
// import { shapes } from "../../data/shapes";
99

1010
// loader
1111
import Loader from "react-loader-spinner";
@@ -16,16 +16,28 @@ import { ShapeList, Header } from '..';
1616
const App = (props) => {
1717
const [data, setData] = useState([]);
1818
const [loading, setLoading] = useState(true);
19+
const { user } = props;
1920

2021
useEffect(async () => {
2122
setData([]);
2223
setLoading(true);
2324

24-
// fetching the shape data
25-
/*const shapes = await harperFetch({
26-
operation: "sql",
27-
sql: "SELECT * FROM tryshape.shapes",
28-
});*/
25+
let shapes = [];
26+
27+
if(user.length === 0) {
28+
// User is not logged In
29+
shapes = await harperFetch({
30+
operation: "sql",
31+
sql: "SELECT * from tryshape.shapes as s where s.private = false",
32+
});
33+
} else {
34+
// User is logged in. Let's fetch the private shape and pther public shapes.
35+
shapes = await harperFetch({
36+
operation: "sql",
37+
sql: `SELECT * from tryshape.shapes WHERE createdBy = '${user.email}' OR private = false`,
38+
});
39+
}
40+
2941
console.log(shapes);
3042
let modifiedShapes = shapes.map((shape, index) => {
3143
shape.showAdvanced = false;
@@ -36,7 +48,7 @@ const App = (props) => {
3648

3749
await setData(modifiedShapes);
3850
setLoading(false);
39-
}, []);
51+
}, [user]);
4052

4153

4254

components/core/SignInModal.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ import Modal from "react-bootstrap/Modal";
1111

1212
// sign In providers
1313
import { githubProvider, googleProvider } from "../../utils/Auth/auth-methods";
14+
15+
// auth
1416
import socialMediaAuth from "../../utils/Auth/auth";
1517

1618
const SignInModal = ({ open, setOpen }) => {
19+
1720
const handleOnClick = async (provider) => {
1821
const res = await socialMediaAuth(provider);
1922
await setOpen(false);

components/utils/Header.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { FaShapes } from "react-icons/fa";
1616
import Button from "react-bootstrap/Button";
1717

1818
const Header = ({ setOpen, user, setUser }) => {
19-
console.log(user);
19+
// console.log(user);
2020
// sign out function
2121
const signOut = () => {
2222
auth()

components/utils/ShapeList.js

Lines changed: 88 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
import React, { useState } from "react";
2+
3+
// Styled Component
4+
import styled from "styled-components";
5+
6+
// dynamic from Next.js
27
import dynamic from "next/dynamic";
38

49
// Toast
@@ -16,28 +21,91 @@ import { toPng } from 'html-to-image';
1621
// downloadjs
1722
import download from 'downloadjs';
1823

24+
// icons
25+
import { FiCopy, FiDownload, FiHeart, FiLock } from 'react-icons/fi';
26+
1927
// Shape Listing Styled-Componentns
20-
import {
21-
ShapeCards,
22-
ShapeCard,
23-
ShapeName,
24-
ShapePallete,
25-
ShapeDetailsItems,
26-
ShapeCardSwitch,
27-
ShapeActions,
28-
ShapeCardHeader,
29-
CopyIcon,
30-
DownloadIcon,
31-
LikeIcon,
32-
} from './StyledComponents';
28+
const ShapeCards = styled.div`
29+
display: flex;
30+
flex-wrap: wrap;
31+
justify-content: center;
32+
align-items: center;
33+
`;
34+
35+
const ShapeCard = styled.div`
36+
width: 400px;
37+
min-height: 456px;
38+
border: 1px solid #ececec;
39+
border-radius: 4px;
40+
padding: 5px;
41+
margin: 5px;
42+
background-color: #ebebeb;
43+
`;
44+
45+
const ShapeActions = styled.div`
46+
float: right;
47+
`;
48+
49+
const ShapeName = styled.span`
50+
font-weight: bold;
51+
font-size: 20px;
52+
`;
53+
54+
const Playground = styled.div`
55+
width: 100%;
56+
`;
57+
58+
const ShapeDetails = styled.ul`
59+
background-color: #ebebeb;
60+
border-radius: 4px;
61+
padding: 10px;
62+
width: 100%;
63+
`;
64+
65+
const ShapeDetailsItems = styled.li`
66+
word-wrap: break-word;
67+
`;
68+
69+
const ShapePallete = styled.div`
70+
margin-top: 5px;
71+
`;
72+
73+
const ShapeCardHeader = styled.div`
74+
padding: 5px;
75+
margin: 5px;
76+
`;
77+
78+
const ShapeCardSwitch = styled.div`
79+
margin: 5px auto auto 9px;
80+
`;
81+
82+
const CopyIcon = styled(FiCopy)`
83+
cursor: pointer;
84+
&:hover {
85+
color: #f71b76;
86+
}
87+
`;
88+
89+
const DownloadIcon = styled(FiDownload)`
90+
cursor: pointer;
91+
&:hover {
92+
color: #f71b76;
93+
}
94+
`;
95+
96+
const LikeIcon = styled(FiHeart)`
97+
cursor: pointer;
98+
&:hover {
99+
color: #f71b6f;
100+
}
101+
`;
33102

34103
const ShapeList = ({ data }) => {
35104

36105
const [shapes, setShapes] = useState(data);
37106

38107
const handleSwicth = (shapeName) => {
39-
console.log(shapeName);
40-
108+
41109
let modifiedShapes = shapes.map((shape, index) => {
42110
if (shape.name === shapeName) {
43111
return {
@@ -47,7 +115,6 @@ const ShapeList = ({ data }) => {
47115
}
48116
return shape;
49117
});
50-
console.log(modifiedShapes);
51118
setShapes(...[modifiedShapes]);
52119
};
53120

@@ -84,6 +151,7 @@ const ShapeList = ({ data }) => {
84151
<ShapeCard>
85152
<ShapeCardHeader>
86153
<ShapeName>{shape.name}</ShapeName>
154+
{shape.private && <FiLock />}
87155
<ShapeActions>
88156
<span title="Like">
89157
<LikeIcon size={24} />
@@ -111,6 +179,10 @@ const ShapeList = ({ data }) => {
111179
showShadow={shape.showAdvanced}
112180
/>
113181

182+
<div>
183+
<span>Created By {shape.createdBy} at {shape['__createdtime__']}</span>
184+
</div>
185+
114186
<ShapeCardSwitch>
115187
<label htmlFor={`${getShapeFileName(shape.name)}-form`}>
116188
<span>Show Clip-Path Info</span>{" "}

components/utils/StyledComponents.js

Lines changed: 0 additions & 92 deletions
This file was deleted.

0 commit comments

Comments
 (0)