Skip to content

Commit 880fe5a

Browse files
committed
added profile image to dashboard
1 parent a2deca9 commit 880fe5a

4 files changed

Lines changed: 39 additions & 57 deletions

File tree

nextstep-frontend/src/components/NewPost.tsx

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ const NewPostModal: React.FC<NewPostModalProps> = ({ open, onClose, onPostCreate
4545
const [content, setContent] = useState<string>("")
4646
const [isSubmitting, setIsSubmitting] = useState(false)
4747
const [error, setError] = useState<string | null>(null)
48-
const [resumeData, setResumeData] = useState<any>(null)
4948
const [resumeFile, setResumeFile] = useState<File | null>(null)
50-
const [isLoadingResume, setIsLoadingResume] = useState(false)
51-
const fileInputRef = useRef<HTMLInputElement>(null)
5249
const editorRef = useRef<any>(null)
5350
const auth = getUserAuth();
5451
const [mountedEditor, setMountedEditor] = useState(false)
@@ -148,7 +145,6 @@ const NewPostModal: React.FC<NewPostModalProps> = ({ open, onClose, onPostCreate
148145
setTitle("")
149146
setContent("<p> I wanted to share.... </p>")
150147
setError(null)
151-
setResumeData(null)
152148
setResumeFile(null)
153149
}
154150
}, [open, withResume])
@@ -174,7 +170,6 @@ const NewPostModal: React.FC<NewPostModalProps> = ({ open, onClose, onPostCreate
174170

175171
const fetchResumeData = async () => {
176172
try {
177-
setIsLoadingResume(true)
178173
const resumeResponse = await api.get("/resume")
179174

180175
if (resumeResponse.data && resumeResponse.data.rawContentLink) {
@@ -187,54 +182,13 @@ const NewPostModal: React.FC<NewPostModalProps> = ({ open, onClose, onPostCreate
187182
type: "application/pdf",
188183
})
189184

190-
setResumeData(resumeResponse.data)
191185
setResumeFile(resumeFileObj)
192186
} else {
193187
setError("No resume found. Please upload a resume first.")
194188
}
195189
} catch (err) {
196190
console.error("Failed to fetch resume data:", err)
197191
setError("Failed to load resume. Please try again later.")
198-
} finally {
199-
setIsLoadingResume(false)
200-
}
201-
}
202-
203-
const handleFroalaImageUpload = async (file: File) => {
204-
try {
205-
const formData = new FormData()
206-
formData.append("file", file)
207-
208-
const response = await api.post("/resource/image", formData, {
209-
headers: {
210-
"Content-Type": "multipart/form-data",
211-
Authorization: `Bearer ${auth.accessToken}`,
212-
},
213-
})
214-
215-
return JSON.stringify({ link: response.data.url })
216-
} catch (error) {
217-
console.error("Error uploading image:", error)
218-
throw error
219-
}
220-
}
221-
222-
const handleFroalaFileUpload = async (file: File) => {
223-
try {
224-
const formData = new FormData()
225-
formData.append("file", file)
226-
227-
const response = await api.post("/resource/file", formData, {
228-
headers: {
229-
"Content-Type": "multipart/form-data",
230-
Authorization: `Bearer ${auth.accessToken}`,
231-
},
232-
})
233-
234-
return JSON.stringify({ link: response.data.url, name: file.name })
235-
} catch (error) {
236-
console.error("Error uploading file:", error)
237-
throw error
238192
}
239193
}
240194

nextstep-frontend/src/pages/Feed.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,6 @@ const Feed: React.FC = () => {
149149
setSavedPosts((prev) => (prev.includes(postId) ? prev.filter((id) => id !== postId) : [...prev, postId]))
150150
}
151151

152-
const formatContent = (content: string) => {
153-
// Strip HTML tags for preview
154-
const strippedContent = content.replace(/<[^>]*>?/gm, "")
155-
return strippedContent.length > 150 ? strippedContent.substring(0, 150) + "..." : strippedContent
156-
}
157152

158153
const formatDate = (dateString: string) => {
159154
if (!dateString) return ""

nextstep-frontend/src/pages/MainDashboard.tsx

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@ import {
3939
Business,
4040
CheckCircle,
4141
InsertDriveFile,
42+
Delete,
4243
} from "@mui/icons-material"
4344
import { connectToGitHub, initiateGitHubOAuth, fetchRepoLanguages, handleGitHubOAuth } from "../handlers/githubAuth"
4445
import api from "../serverApi"
4546
import LinkedinJobs from "../components/LinkedinJobs"
4647
import { motion } from "framer-motion"
48+
import { getUserAuth } from "../handlers/userAuth"
4749

4850
const roles = [
4951
"Software Engineer",
@@ -72,7 +74,7 @@ const skillsList = [
7274
]
7375

7476
const MainDashboard: React.FC = () => {
75-
const theme = useTheme()
77+
const theme = useTheme();
7678
const [aboutMe, setAboutMe] = useState(() => localStorage.getItem("aboutMe") || "")
7779
const [skills, setSkills] = useState<string[]>(() => JSON.parse(localStorage.getItem("skills") || "[]"))
7880
const [newSkill, setNewSkill] = useState("")
@@ -87,6 +89,9 @@ const MainDashboard: React.FC = () => {
8789
const [roleMatch, setRoleMatch] = useState<string>("")
8890
const [resumeFileName, setResumeFileName] = useState<string>("")
8991

92+
// Profile image state
93+
const [image, setImage] = useState<string | null>(null)
94+
9095
// Skills toggle
9196
const [showAllSkills, setShowAllSkills] = useState(false)
9297
const SKILL_DISPLAY_LIMIT = 4
@@ -186,6 +191,22 @@ const MainDashboard: React.FC = () => {
186191
}
187192
}
188193

194+
useEffect(() => {
195+
const fetchProfileImage = async () => {
196+
try {
197+
const response = await api.get(`/resource/image/${getUserAuth().imageFilename}`, {
198+
responseType: 'blob',
199+
});
200+
const imageUrl = URL.createObjectURL(response.data as Blob);
201+
setImage(imageUrl);
202+
} catch (error) {
203+
console.log('Error fetching profile image.');
204+
setImage(null);
205+
}
206+
};
207+
getUserAuth().imageFilename && fetchProfileImage();
208+
}, []);
209+
189210
// Upload & parse resume
190211
const handleResumeUpload = async (e: React.ChangeEvent<HTMLInputElement>) => {
191212

@@ -267,6 +288,10 @@ const MainDashboard: React.FC = () => {
267288

268289
const profileCompletion = calculateProfileCompletion()
269290

291+
const handleRemoveAllSkills = () => {
292+
setSkills([]);
293+
};
294+
270295
return (
271296
<Box sx={{ minHeight: "100vh", py: 4 }}>
272297
<Container maxWidth="xl">
@@ -357,7 +382,7 @@ const MainDashboard: React.FC = () => {
357382
{/* Upload Section */}
358383
<Box sx={{ display: "flex", justifyContent: "space-between", alignItems: "center", mb: 3 }}>
359384
<Box sx={{ display: "flex", alignItems: "center" }}>
360-
<Avatar
385+
{ !image ? <Avatar
361386
sx={{
362387
bgcolor: alpha(theme.palette.primary.main, 0.1),
363388
color: theme.palette.primary.main,
@@ -367,7 +392,10 @@ const MainDashboard: React.FC = () => {
367392
}}
368393
>
369394
<PersonIcon sx={{ fontSize: 28 }} />
370-
</Avatar>
395+
</Avatar> :
396+
<Avatar src={image} alt="Profile" style={{ width: 56, height: 56, marginTop: '16px', objectFit: 'cover', margin:7 }} />
397+
398+
}
371399
<Box>
372400
<Typography variant="h5" fontWeight={700} sx={{ mb: 0.5 }}>
373401
About Me
@@ -463,6 +491,7 @@ const MainDashboard: React.FC = () => {
463491
border: `1px solid ${alpha(theme.palette.divider, 0.1)}`,
464492
boxShadow: `0 8px 32px ${alpha(theme.palette.common.black, 0.1)}`,
465493
transition: "all 0.3s ease",
494+
position: 'relative', // Add position relative
466495
"&:hover": {
467496
transform: "translateY(-4px)",
468497
boxShadow: `0 12px 48px ${alpha(theme.palette.common.black, 0.15)}`,
@@ -491,7 +520,11 @@ const MainDashboard: React.FC = () => {
491520
</Typography>
492521
</Box>
493522
</Box>
494-
523+
<Tooltip title="Remove all skills" arrow>
524+
<Button size="small" onClick={handleRemoveAllSkills} sx={{ mb: 2, position: 'absolute', top: 8, right: 8 }}>
525+
<Delete/>
526+
</Button>
527+
</Tooltip>
495528
<Stack direction="row" spacing={1} sx={{ flexWrap: "wrap", mb: 2, gap: 1 }}>
496529
{(showAllSkills ? skills : skills.slice(0, SKILL_DISPLAY_LIMIT)).map((skill, index) => (
497530
<Chip

nextstep-frontend/src/pages/Profile.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useState, useEffect } from 'react';
22
import { Container, Typography, Box, Button, Alert, TextField, Collapse } from '@mui/material';
33
import { ExpandMore, ExpandLess } from '@mui/icons-material';
4-
import {getUserAuth} from "../handlers/userAuth.ts";
4+
import {getUserAuth, setUserAuth} from "../handlers/userAuth.ts";
55
import api from "../serverApi.ts";
66
import {UserProfile} from "../models/UserProfile.ts";
77
import defaultProfileImage from '../../assets/defaultProfileImage.jpg';
@@ -36,6 +36,7 @@ const Profile: React.FC = () => {
3636
const response = await api.get(`/user/${getUserAuth().userId}`);
3737
const userProfile = response.data as UserProfile;
3838
// setProfile(userProfile);
39+
setUserAuth({...auth, imageFilename: userProfile.imageFilename})
3940
setUserName(userProfile.username);
4041
setEmail(userProfile.email);
4142
return userProfile;
@@ -67,7 +68,6 @@ const Profile: React.FC = () => {
6768
},
6869
});
6970

70-
// setUserAuth({...auth, imageFilename: (response.data as LoginResponse).imageFilename})
7171
if (response.status === 201) {
7272
setSuccess(true);
7373
setError('');

0 commit comments

Comments
 (0)