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

Reorder sidebar "people" list with "you" at the top. #6031

Merged
merged 9 commits into from
Apr 26, 2023
84 changes: 56 additions & 28 deletions src/react-components/room/PeopleSidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,54 @@ function getPersonName(person, intl) {
return person.profile.displayName + (person.isMe ? ` (${you})` : "");
}

function PersonListItem({ person, onSelectPerson }) {
const intl = useIntl();
const DeviceIcon = getDeviceIconComponent(person.context);
const VoiceIcon = getVoiceIconComponent(person.micPresence);

return (
<ButtonListItem className={styles.person} key={person.id} type="button" onClick={e => onSelectPerson(person, e)}>
{person.hand_raised && <HandRaisedIcon />}
{<DeviceIcon title={getDeviceLabel(person.context, intl)} />}
{!person.context.discord && VoiceIcon && <VoiceIcon title={getVoiceLabel(person.micPresence, intl)} />}
<p>{getPersonName(person, intl)}</p>
{person.roles.owner && (
<StarIcon
title={intl.formatMessage({ id: "people-sidebar.moderator-label", defaultMessage: "Moderator" })}
className={styles.moderatorIcon}
width={12}
height={12}
/>
)}
<p className={styles.presence}>{getPresenceMessage(person.presence, intl)}</p>
</ButtonListItem>
);
}

PersonListItem.propTypes = {
person: PropTypes.shape({
context: PropTypes.shape({
embed: PropTypes.bool,
hmd: PropTypes.bool,
mobile: PropTypes.bool,
discord: PropTypes.bool
}),
id: PropTypes.string.isRequired,
micPresence: PropTypes.shape({
muted: PropTypes.bool,
talking: PropTypes.bool
}),
presence: PropTypes.string.isRequired,
roles: PropTypes.shape({
creator: PropTypes.bool,
owner: PropTypes.bool,
signed_in: PropTypes.bool
}),
hand_raised: PropTypes.bool
}),
onSelectPerson: PropTypes.func
};

export function PeopleSidebar({
people,
onSelectPerson,
Expand All @@ -101,7 +149,8 @@ export function PeopleSidebar({
voiceChatEnabled,
isMod
}) {
const intl = useIntl();
const user = people.find(person => !!person.isMe);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this all could work fine, another take that might make the jsx less confusing is to alter the people array, something like this.

const me = people.find(person => !!person.isMe);
filteredPeople = people.filter(person => !person.isMe);
filteredPeople.unshift(me);

and then you can just loop through filteredPeople


return (
<Sidebar
title={
Expand All @@ -123,33 +172,12 @@ export function PeopleSidebar({
{!canVoiceChat && <PermissionNotification permission={"voice_chat"} />}
{!voiceChatEnabled && isMod && <PermissionNotification permission={"voice_chat"} isMod={true} />}
<List>
{people.map(person => {
const DeviceIcon = getDeviceIconComponent(person.context);
const VoiceIcon = getVoiceIconComponent(person.micPresence);

return (
<ButtonListItem
className={styles.person}
key={person.id}
type="button"
onClick={e => onSelectPerson(person, e)}
>
{person.hand_raised && <HandRaisedIcon />}
{<DeviceIcon title={getDeviceLabel(person.context, intl)} />}
{!person.context.discord && VoiceIcon && <VoiceIcon title={getVoiceLabel(person.micPresence, intl)} />}
<p>{getPersonName(person, intl)}</p>
{person.roles.owner && (
<StarIcon
title={intl.formatMessage({ id: "people-sidebar.moderator-label", defaultMessage: "Moderator" })}
className={styles.moderatorIcon}
width={12}
height={12}
/>
)}
<p className={styles.presence}>{getPresenceMessage(person.presence, intl)}</p>
</ButtonListItem>
);
})}
{user && <PersonListItem person={user} onSelectPerson={onSelectPerson} />}
{people
.filter(person => !person.isMe)
.map(person => (
<PersonListItem key={person.id} person={person} onSelectPerson={onSelectPerson} />
))}
</List>
</Sidebar>
);
Expand Down
Loading