-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jatin get profile images from website #2714
Open
JatinAgrawal94
wants to merge
11
commits into
development
Choose a base branch
from
jatin_get_profile_images_from_website
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
50a3438
modal created for viewing suggested user profile images
JatinAgrawal94 3dd142f
made some changes to userprofile.jsx
JatinAgrawal94 60908b9
fixed profile images not displaying error
JatinAgrawal94 782836c
Merge branch 'development' into jatin_get_profile_images_from_website
JatinAgrawal94 882f21d
fixed console errors
JatinAgrawal94 2bba483
fixed some console errors related to userprofile.jsx
JatinAgrawal94 218362f
fixed issues
JatinAgrawal94 63dbb67
Merge branch 'development' into jatin_get_profile_images_from_website
JatinAgrawal94 51d4b4b
fixed lint errors
JatinAgrawal94 af614fb
Merge branch 'development' into jatin_get_profile_images_from_website
JatinAgrawal94 51a21f0
resolved lint issues
JatinAgrawal94 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/components/UserProfile/UserProfileModal/confirmRemoveModal.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from "react"; | ||
import { Modal, ModalHeader, ModalBody, Button } from "reactstrap"; | ||
|
||
const ConfirmRemoveModal = ({ isOpen, toggleModal, confirmRemove }) => { | ||
return ( | ||
<Modal isOpen={isOpen} toggle={toggleModal}> | ||
<ModalHeader toggle={toggleModal}>Remove Profile Image</ModalHeader> | ||
<ModalBody> | ||
<p>Are you sure you want to remove the selected profile image?</p> | ||
<div className="button-group"> | ||
<Button color="secondary" onClick={toggleModal} className="modal-button"> | ||
Cancel | ||
</Button> | ||
<Button | ||
color="danger" | ||
onClick={confirmRemove} | ||
className="modal-button" | ||
style={{ marginLeft: '10px' }} | ||
> | ||
Confirm | ||
</Button> | ||
</div> | ||
</ModalBody> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default ConfirmRemoveModal; |
110 changes: 110 additions & 0 deletions
110
src/components/UserProfile/UserProfileModal/suggestedProfileModal.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import React, { useState } from "react"; | ||
import { Modal, ModalHeader, ModalBody, Button } from "reactstrap"; | ||
import './UserProfileModal.css'; // For custom styling | ||
import axios from "axios"; | ||
import { ENDPOINTS } from "utils/URL"; | ||
import { toast } from "react-toastify"; | ||
import { useEffect } from "react"; | ||
|
||
const ProfileImageModal = ({ isOpen, toggleModal, userProfile }) => { | ||
|
||
const [selectedImage, setSelectedImage] = useState(null); | ||
const suggestedProfilePics=userProfile.suggestedProfilePics; | ||
const [allImages,setAllImages]=useState(suggestedProfilePics); | ||
const [flag,setFlag]=useState(false) | ||
// Function to handle image selection | ||
|
||
const handleImageSelect = (image) => { | ||
setSelectedImage(image); // Store the selected image info | ||
}; | ||
|
||
|
||
async function imageUrlToPngBase64(url) { | ||
try { | ||
// Fetch the image as a buffer | ||
const response = await axios.get(url, { responseType: "arraybuffer" }); | ||
|
||
if (response.status !== 200) { | ||
throw new Error(`Failed to fetch the image: ${response.statusText}`); | ||
} | ||
|
||
const imageBuffer = Buffer.from(response.data); | ||
|
||
// Convert the image to PNG format using sharp | ||
const pngBuffer = await sharp(imageBuffer).png().toBuffer(); | ||
|
||
// Convert the PNG buffer to a base64 string | ||
const base64Png = pngBuffer.toString("base64"); | ||
|
||
return `data:image/png;base64,${base64Png}`;; | ||
} catch (error) { | ||
console.error(`An error occurred: ${error.message}`); | ||
return null; | ||
} | ||
} | ||
|
||
useEffect(()=>{ | ||
if(suggestedProfilePics.length!==0 && allImages[0].nitro_src===undefined){ | ||
console.log("Inside"); | ||
var values=allImages; | ||
for(let i=0;i<values.length;i++){ | ||
imageUrlToPngBase64(values[i].src).then((resolve)=>{ | ||
values[i].nitro_src=resolve; | ||
}) | ||
} | ||
setAllImages(values) | ||
setFlag(true) | ||
} | ||
},[allImages]) | ||
|
||
const updateProfileImage= async ()=>{ | ||
try { | ||
await axios.put(ENDPOINTS.USERS_UPDATE_PROFILE_FROM_WEBSITE,{'selectedImage':selectedImage,'user_id':userProfile._id}) | ||
toast.success("Profile Image Updated") | ||
} | ||
catch (error) { | ||
console.log(error) | ||
toast.error("Image Update Failed") | ||
} | ||
} | ||
|
||
return ( | ||
<Modal isOpen={isOpen} toggle={toggleModal}> | ||
<ModalHeader toggle={toggleModal}>Select a Profile Image</ModalHeader> | ||
<ModalBody> | ||
<div className="suggestedProfileLinks scrollable-container"> | ||
{suggestedProfilePics.map((image, index) => ( | ||
<div | ||
key={index} | ||
className={`suggestedProfileTile ${selectedImage === image ? 'selected' : ''}`} | ||
onClick={() => handleImageSelect(image)} | ||
> | ||
<img src={flag?image.nitro_src:image.nitro_src} alt={image.alt} /> | ||
{/* <p>{image.title!==undefined && image.title.trim()!==""?image.title:image.alt.split(" ").slice(0, 3).join(" ")}</p> */} | ||
</div> | ||
))} | ||
</div> | ||
|
||
<div className="button-group"> | ||
<Button color="secondary" onClick={toggleModal} className="modal-button"> | ||
Close | ||
</Button> | ||
<Button | ||
color="primary" | ||
onClick={() => { | ||
if (selectedImage) { | ||
toggleModal(); // Close the modal after setting the image | ||
updateProfileImage() | ||
} | ||
}} | ||
className="modal-button" | ||
> | ||
Set Image | ||
</Button> | ||
</div> | ||
</ModalBody> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default ProfileImageModal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of == use ===