generated from Codaisseur/react-redux-jwt-bootstrap-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathProjectPage.js
159 lines (144 loc) · 5.6 KB
/
ProjectPage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import React, { useEffect, useState } from "react";
import { useParams, Link } from "react-router-dom";
import { Grid, Typography, Chip, Button, Paper } from "@material-ui/core";
import Comment from "../../components/Comment/Comment.js";
import "./ProjectPage.css";
import Carousel from "react-material-ui-carousel";
import Item from "../../components/CarouselItem/CarouselItem";
import Loading from "../../components/Loading";
import { useDispatch, useSelector } from "react-redux";
import { getProject } from "../../store/projects/action";
import FavoriteIcon from "@material-ui/icons/Favorite";
import FavoriteBorderIcon from "@material-ui/icons/FavoriteBorder";
import CommentIcon from "@material-ui/icons/Comment";
import { selectProjectViewed } from "../../store/projects/selector";
import { selectUser } from "../../store/user/selectors";
import { likeClick } from "../../store/user/actions";
import StorageIcon from "@material-ui/icons/Storage";
import WebIcon from "@material-ui/icons/Web";
import GitHubIcon from "@material-ui/icons/GitHub";
import LinkedInIcon from "@material-ui/icons/LinkedIn";
import CarouselComponent from "../../components/CarouselItem/CarouselItem";
import YouTubeIcon from "@material-ui/icons/YouTube";
export default function ProfilePage() {
const { id } = useParams();
const parsedId = parseInt(id);
const dispatch = useDispatch();
const [comments, setComments] = useState(false);
const heartClick = () => {
dispatch(likeClick(parsedId));
dispatch(getProject(parsedId));
};
const commentClick = () => {
setComments(comments ? "" : <Comment id={parsedId} />);
};
useEffect(() => {
dispatch(getProject(parsedId));
}, []);
const projectViewed = useSelector(selectProjectViewed);
const user = useSelector(selectUser);
const likeCheck =
projectViewed &&
projectViewed.project.likes.find((l) => l.userId === user.id);
return !projectViewed ? (
<Loading />
) : (
<div className="root">
<Grid className="project-grid" container justify="center" spacing={4}>
<Grid item container justify="center" xs={12}>
<Grid item xs={3}>
<br />
<Typography>Posted by:</Typography>
<h2>{projectViewed.user.name}</h2>
<Link to={`/profile/${projectViewed.user.id}`}>
<img
className="profileimage"
src={projectViewed.user.userImg}
></img>
</Link>
<Typography>
<GitHubIcon />
<a href={projectViewed.user.githubLink}>GitHub</a>
</Typography>
<Typography>
<LinkedInIcon />
<a href={projectViewed.user.linkedinLink}>LinkedIn</a>
</Typography>
<Typography>
<WebIcon />
<a href={projectViewed.project.feLink}>Front-end repo</a>
</Typography>
<Typography>
<StorageIcon />
<a href={projectViewed.project.beLink}>Back-end repo</a>
</Typography>
<Typography>
<YouTubeIcon />
<a href={projectViewed.project.ytUrl}>Youtube Link</a>
</Typography>
</Grid>
<Grid
item
container
justify="center"
alignItems="center"
direction="column"
spacing={5}
xs={8}
><Paper className="post-article">
<Grid item xs>
<h1 className="title">{projectViewed.project.projectName}</h1>
</Grid>
<Grid item xs>
{projectViewed.project.tags.map((t, id) => {
return (
<Chip className="tags-grid" key={id + 1} variant="outlined" label={t.tagName} />
);
})}
</Grid>
<img
className="projectimage"
src={projectViewed.project.projectImg}
></img>
<Typography className="project-desc">{projectViewed.project.projectDesc}</Typography>
<div style={{ backgroundColor: "#fff" }}>
{projectViewed.project.likes.length}
{likeCheck ? (
<Button onClick={heartClick}>
<FavoriteIcon color="secondary" fontSize="large" />
</Button>
) : (
<Button onClick={heartClick}>
<FavoriteBorderIcon color="secondary" fontSize="large" />
</Button>
)}
{projectViewed.project.comments.length}
{!user.token ? (
<Button
onClick={() => {
alert("You are not logged in!");
}}
>
<CommentIcon color="secondary" fontSize="large" />
</Button>
) : (
<Button onClick={commentClick}>
<CommentIcon color="secondary" fontSize="large" />
</Button>
)}
</div>
{comments}
<CarouselComponent
array={projectViewed.project.resources}
name="title"
description="resourceDes"
linkName="link"
image="resourceImg"
/>
</Paper>
</Grid>
</Grid>
</Grid>
</div>
);
}