Skip to content
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

Fix displayed email address when not being logged in #110

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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