Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions final/client/src/components/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@ const offset = 97; // letter A's charcode is 97
const avatars = [dog1, dog2, dog3];
const maxIndex = avatars.length - 1;
function pickAvatarByEmail(email) {
const charCode = email.toLowerCase().charCodeAt(0) - offset;
const percentile = Math.max(0, Math.min(max, charCode)) / max;
return avatars[Math.round(maxIndex * percentile)];
let chosenIndex = 0;
if (email) {
const charCode = email.toLowerCase().charCodeAt(0) - offset;
const percentile = Math.max(0, Math.min(max, charCode)) / max;
chosenIndex = Math.round(maxIndex * percentile);
}
return avatars[chosenIndex];
}

export default function Header({ image, children = 'Space Explorer' }) {
const email = atob(localStorage.getItem('token'));
const token = localStorage.getItem('token');
const email = token ? atob(token) : '';
const avatar = image || pickAvatarByEmail(email);
return (
<Container>
Expand Down
13 changes: 9 additions & 4 deletions start/client/src/components/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@ const offset = 97; // letter A's charcode is 97
const avatars = [dog1, dog2, dog3];
const maxIndex = avatars.length - 1;
function pickAvatarByEmail(email) {
const charCode = email.toLowerCase().charCodeAt(0) - offset;
const percentile = Math.max(0, Math.min(max, charCode)) / max;
return avatars[Math.round(maxIndex * percentile)];
let chosenIndex = 0;
if (email) {
const charCode = email.toLowerCase().charCodeAt(0) - offset;
const percentile = Math.max(0, Math.min(max, charCode)) / max;
chosenIndex = Math.round(maxIndex * percentile);
}
return avatars[chosenIndex];
}

export default function Header({ image, children = 'Space Explorer' }) {
const email = atob(localStorage.getItem('token'));
const token = localStorage.getItem('token');
const email = token ? atob(token) : '';
const avatar = image || pickAvatarByEmail(email);
return (
<Container>
Expand Down