-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'enhancement-user-image-service' into staging
- Loading branch information
Showing
4 changed files
with
71 additions
and
38 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,49 @@ | ||
import React from "react"; | ||
import React, { useEffect, useState } from "react"; | ||
import PropTypes from "prop-types"; | ||
import { Avatar } from "@material-ui/core"; | ||
|
||
export default function UserAvatar({ name, ...avatarProps }){ | ||
return( | ||
<Avatar {...avatarProps}> | ||
export default function UserAvatar({ name, alias }) { | ||
const [userImageURL, setUserImageURL] = useState(""); | ||
|
||
// Load User Image from ECNDB | ||
useEffect(_ => { | ||
(async function getUserImage() { | ||
if (alias === "") { | ||
return null; | ||
} | ||
|
||
const userImageResponse = await fetch(`https://engineering.purdue.edu/ECN/PersonPhotos/getPhoto?json=1&alias=${alias}`); | ||
|
||
if (userImageResponse.status !== 200) { | ||
console.error(`Failed to load user image from ECNDB. Got code ${userImageResponse.status} (${userImageResponse.statusText})`); | ||
return null; | ||
} | ||
|
||
let userImageData = await userImageResponse.json(); | ||
if (userImageData.imagePath === "") { | ||
return null; | ||
} | ||
|
||
setUserImageURL(`https://engineering.purdue.edu/${userImageData.imagePath}`); | ||
return null; | ||
})(); | ||
}, [alias]) | ||
|
||
return ( | ||
<Avatar src={userImageURL}> | ||
{name === "" ? null : name.charAt(0)} | ||
</Avatar> | ||
); | ||
}; | ||
|
||
UserAvatar.propTypes = { | ||
/** The name of the user. */ | ||
"name": PropTypes.string | ||
"name": PropTypes.string, | ||
/** The user's career account alias. */ | ||
"alias": PropTypes.string | ||
}; | ||
|
||
UserAvatar.defaultProps = { | ||
"name": "" | ||
"name": "", | ||
"alias": "", | ||
}; |