fix: user actions

This commit is contained in:
cha0s 2020-07-18 23:51:59 -05:00
parent e2eb517687
commit c1c3bed5f5
2 changed files with 43 additions and 29 deletions

View File

@ -4,6 +4,7 @@ import React from 'react';
import {useSelector} from 'react-redux'; import {useSelector} from 'react-redux';
import {channelUsersSelector} from '~/common/state/chat'; import {channelUsersSelector} from '~/common/state/chat';
import {redditUsernameSelector} from '~/common/state/user';
import {usernamesSelector} from '~/common/state/usernames'; import {usernamesSelector} from '~/common/state/usernames';
import useChannel from '~/client/hooks/useChannel'; import useChannel from '~/client/hooks/useChannel';
@ -13,43 +14,51 @@ import Channel from './channel';
export default function ChatRightUsers() { export default function ChatRightUsers() {
const channel = useChannel(); const channel = useChannel();
const ids = useSelector((state) => channelUsersSelector(state, channel)); const ids = useSelector((state) => channelUsersSelector(state, channel));
const redditUsername = useSelector(redditUsernameSelector);
const usernames = useSelector(usernamesSelector); const usernames = useSelector(usernamesSelector);
const list = ids.map((id) => usernames[id]).sort(); const list = ids.map((id) => usernames[id]).sort();
const usersActions = [
{
icon: '❤️',
label: 'Favorite',
onClick: () => {},
},
{
icon: '🚫',
label: 'Unfriend',
onClick: () => {},
},
{
icon: '☢️',
label: 'Block',
onClick: () => {},
},
];
return ( return (
<div <div
className="chat--rightUsers" className="chat--rightUsers"
> >
<h2 className="users__chatsTitle">Who's here</h2> <h2 className="users__chatsTitle">Who's here</h2>
<ul className="users__chatsList"> <ul className="users__chatsList">
{list.map((username) => ( {list.map((username) => {
<li const isLinked = (
className="users__item" redditUsername !== username
> && '/r/anonymous' !== channel
<Channel );
actions={usersActions} const userActions = [];
href={`/chat/u/${username}`} if (isLinked) {
name={username} userActions.push({
prefix="/u/" icon: '',
/> label: 'Add friend',
</li> onClick: () => {},
))} });
userActions.push({
icon: '☢️',
label: 'Block',
onClick: () => {},
});
}
// {
// icon: '',
// label: 'Favorite',
// onClick: () => {},
// },
return (
<li
className="users__item"
>
<Channel
actions={userActions}
href={isLinked ? `/chat/u/${username}` : null}
name={username}
prefix="/u/"
/>
</li>
);
})}
</ul> </ul>
</div> </div>
); );

View File

@ -45,6 +45,11 @@ export const activeFriendshipSelector = createSelector(
(friendship) => Object.values(friendship).filter(({state}) => 'active' === state), (friendship) => Object.values(friendship).filter(({state}) => 'active' === state),
); );
export const isAnonymousSelector = createSelector(
[userSelector],
({isAnonymous}) => isAnonymous,
);
export const pendingFriendshipSelector = createSelector( export const pendingFriendshipSelector = createSelector(
friendshipSelector, friendshipSelector,
(friendship) => Object.values(friendship).filter(({state}) => 'pending' === state), (friendship) => Object.values(friendship).filter(({state}) => 'pending' === state),