Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
kemboi590 committed Jul 26, 2023
1 parent 845b2f2 commit 6bc5470
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
38 changes: 30 additions & 8 deletions src/pages/Profile/Profile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useNavigate } from "react-router-dom";
import placeholder from "../../Images/placeholder.png";
import Loading from "../../components/Loading/Loading";
import { BlobServiceClient } from "@azure/storage-blob";
import { MdDelete } from "react-icons/md";
import { MdDelete } from "react-icons/md";
import { toast } from "react-toastify";
import "react-toastify/dist/ReactToastify.css";
import { toastStyles } from "../../toastConfig";
Expand Down Expand Up @@ -35,8 +35,11 @@ function Profile() {
const fetchImages = async () => {
try {
setLoading(true);
const blobServiceClient = new BlobServiceClient(`https://${account}.blob.core.windows.net`);
const containerClient = blobServiceClient.getContainerClient(containerName);
const blobServiceClient = new BlobServiceClient(
`https://${account}.blob.core.windows.net`
);
const containerClient =
blobServiceClient.getContainerClient(containerName);
const blobItems = containerClient.listBlobsFlat();

let urls = []; //returns an array of objects with name and url
Expand All @@ -48,7 +51,9 @@ function Profile() {
setLoading(false);

// Find the URL for the specific user and set it to the state
const userImage = urls.find((url) => url.name === `${userData.user_id}.png`);
const userImage = urls.find(
(url) => url.name === `${userData.user_id}.png`
);
if (userImage) {
setUserImageUrl(userImage.url);
} else {
Expand All @@ -72,7 +77,8 @@ function Profile() {
`https://${account}.blob.core.windows.net/?${sasToken}` // Use the SAS token to authenticate
);
//blobService Client is a class that allows us to interact with the blob storage
const containerClient = blobServiceClient.getContainerClient(containerName); // Get the container client used to interact with the container
const containerClient =
blobServiceClient.getContainerClient(containerName); // Get the container client used to interact with the container
const blobClient = containerClient.getBlockBlobClient(blobName); // Get the blob client used to interact with the blob
const result = await blobClient.uploadData(file, {
blobHTTPHeaders: { blobContentType: file.type },
Expand All @@ -89,7 +95,9 @@ function Profile() {
};

const deleteImage = async (blobName) => {
const blobServiceClient = new BlobServiceClient(`https://${account}.blob.core.windows.net/?${sasToken}`);
const blobServiceClient = new BlobServiceClient(
`https://${account}.blob.core.windows.net/?${sasToken}`
);
const containerClient = blobServiceClient.getContainerClient(containerName);
const blobClient = containerClient.getBlockBlobClient(blobName);
try {
Expand All @@ -114,7 +122,17 @@ function Profile() {
<div className="user_img">
<form>
<div className="file_upload">
{file ? <img className="" src={URL.createObjectURL(file)} alt="no pic" /> : userImageUrl ? <img className="" src={userImageUrl} alt="profile pic" /> : <img className="displayImg" src={placeholder} alt="nopic" />}
{file ? (
<img
className=""
src={URL.createObjectURL(file)}
alt="no pic"
/>
) : userImageUrl ? (
<img className="" src={userImageUrl} alt="profile pic" />
) : (
<img className="displayImg" src={placeholder} alt="nopic" />
)}
</div>

<div className="upload-form_inputs">
Expand All @@ -123,7 +141,11 @@ function Profile() {
id="fileInput"
onChange={(e) => setFile(e.target.files[0])} // set the file to the state.
/>
<button type="submit" onClick={handleSubmit} className="uploadimage">
<button
type="submit"
onClick={handleSubmit}
className="uploadimage"
>
Save
</button>

Expand Down
2 changes: 1 addition & 1 deletion src/pages/Tasks/UpdateComment/UpdateComment.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from "react";
import React, { useEffect, useState } from "react";
import "./updatecomment.css";
import { IoSend } from "react-icons/io5";
import Axios from "axios";
Expand Down

0 comments on commit 6bc5470

Please sign in to comment.