Created
June 28, 2023 08:22
-
-
Save Big-Silver/55ffbd36f2fb90f379a81e69c92ed54b to your computer and use it in GitHub Desktop.
Chameleon Technical exercise - Frontend Engineer
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
window.currentUser = { id: '19', name: 'Jane', email: 'jane@chameleon.io' }; | |
// users are like authors and profiles like commentors | |
// open a modal with commentor info when clicked | |
// PR Comments | |
// - The ActiveProfile arrow function is missing an "=" between "ActiveProfiles" and "({ profiles, onLaunchProfile }" | |
// - Use let instead of var | |
// - Instead of `active.length = 0`, just set back active to an empty array (i.e active = []` | |
// - Format the return section to fall on multiple lines for easy readability | |
// - Conditionally return and render a "No active profile" component if the active array is empty. | |
... | |
export const ActiveProfiles({ profiles, onLaunchProfile }) => { | |
var active = []; | |
for(i=0; i < profiles.length; i++) { | |
if(!profiles[i].disabled && profiles[i]['last_seen_time'] > new Date(new Date().getTime()-(24*60*1000)).toISOString()) { // within the last 24 hours | |
active.push(profiles[i]); | |
} | |
} | |
if(active.length == 1 && active[0].email === window.currentUser.email) { | |
active.length = 0; | |
} | |
return ( | |
<div> | |
{active.map(function(a) { return <div onClick={() => onLaunchProfile(a.name, a.email)}>{a.name} - {a.email}</div> })} | |
</div> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment