Created
September 1, 2023 03:57
-
-
Save luarakerlen/0072bbd7332bddadf1a679f4b401d8e2 to your computer and use it in GitHub Desktop.
chameleon-challenge
This file contains hidden or 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: '[email protected]' }; | |
// users are like authors and profiles like commentors | |
// open a modal with commentor info when clicked | |
// ... | |
export const ActiveProfiles({ profiles, onLaunchProfile }) => { | |
var active = []; | |
const ONE_DAY = 24*60*1000; | |
const ONE_DAY_AGO = new Date(new Date().getTime()-ONE_DAY).toISOString(); | |
active = profiles.filter(function(profile) { | |
return !profile.disabled && profile['last_seen_time'] > ONE_DAY_AGO; | |
}); | |
const isCurrentUser = active.length === 1 && active[0].email === window.currentUser.email; | |
return ( | |
<div> | |
{ !isCurrentUser && | |
active.map(function(a) { | |
return <div onClick={() => onLaunchProfile(a.name, a.email)}>{a.name} - {a.email}</div> | |
})} | |
</div> | |
) | |
} |
This file contains hidden or 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: '[email protected]' }; | |
// users are like authors and profiles like commentors | |
// open a modal with commentor info when clicked | |
... | |
export const ActiveProfiles({ profiles, onLaunchProfile }) => { | |
var active = []; | |
// I believe it's better if you use a filter function instead of a for loop, because it's more declarative and easier to read. | |
for(i=0; i < profiles.length; i++) { | |
// Maybe you can use a constant for the 24 hours and for the date, so it's easier to change it later and to undertand the code. | |
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]); | |
} | |
} | |
// I think it's better to create a constant and to use a ternary operator to show the active profiles or not, | |
// because it's more declarative and easier to read. | |
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