Merge branch 'reactions-modal' into 'develop'

Reactions modal fixes

See merge request soapbox-pub/soapbox-fe!1516
This commit is contained in:
marcin mikołajczak 2022-06-10 16:14:32 +00:00
commit 76bdb3b148
4 changed files with 30 additions and 15 deletions

View File

@ -9,7 +9,7 @@ import { getAcct } from 'soapbox/utils/accounts';
import { displayFqn } from 'soapbox/utils/state'; import { displayFqn } from 'soapbox/utils/state';
import RelativeTimestamp from './relative_timestamp'; import RelativeTimestamp from './relative_timestamp';
import { Avatar, HStack, Icon, IconButton, Text } from './ui'; import { Avatar, Emoji, HStack, Icon, IconButton, Text } from './ui';
import type { Account as AccountEntity } from 'soapbox/types/entities'; import type { Account as AccountEntity } from 'soapbox/types/entities';
@ -60,6 +60,7 @@ interface IAccount {
withDate?: boolean, withDate?: boolean,
withRelationship?: boolean, withRelationship?: boolean,
showEdit?: boolean, showEdit?: boolean,
emoji?: string,
} }
const Account = ({ const Account = ({
@ -80,6 +81,7 @@ const Account = ({
withDate = false, withDate = false,
withRelationship = true, withRelationship = true,
showEdit = false, showEdit = false,
emoji,
}: IAccount) => { }: IAccount) => {
const overflowRef = React.useRef<HTMLDivElement>(null); const overflowRef = React.useRef<HTMLDivElement>(null);
const actionRef = React.useRef<HTMLDivElement>(null); const actionRef = React.useRef<HTMLDivElement>(null);
@ -160,7 +162,7 @@ const Account = ({
<HStack alignItems='center' space={3} grow> <HStack alignItems='center' space={3} grow>
<ProfilePopper <ProfilePopper
condition={showProfileHoverCard} condition={showProfileHoverCard}
wrapper={(children) => <HoverRefWrapper accountId={account.id} inline>{children}</HoverRefWrapper>} wrapper={(children) => <HoverRefWrapper className='relative' accountId={account.id} inline>{children}</HoverRefWrapper>}
> >
<LinkEl <LinkEl
to={`/@${account.acct}`} to={`/@${account.acct}`}
@ -168,6 +170,12 @@ const Account = ({
onClick={(event: React.MouseEvent) => event.stopPropagation()} onClick={(event: React.MouseEvent) => event.stopPropagation()}
> >
<Avatar src={account.avatar} size={avatarSize} /> <Avatar src={account.avatar} size={avatarSize} />
{emoji && (
<Emoji
className='w-5 h-5 absolute -bottom-1.5 -right-1.5'
emoji={emoji}
/>
)}
</LinkEl> </LinkEl>
</ProfilePopper> </ProfilePopper>

View File

@ -1,3 +1,4 @@
import classNames from 'classnames';
import { debounce } from 'lodash'; import { debounce } from 'lodash';
import React, { useRef } from 'react'; import React, { useRef } from 'react';
import { useDispatch } from 'react-redux'; import { useDispatch } from 'react-redux';
@ -15,10 +16,11 @@ const showProfileHoverCard = debounce((dispatch, ref, accountId) => {
interface IHoverRefWrapper { interface IHoverRefWrapper {
accountId: string, accountId: string,
inline: boolean, inline: boolean,
className?: string,
} }
/** Makes a profile hover card appear when the wrapped element is hovered. */ /** Makes a profile hover card appear when the wrapped element is hovered. */
export const HoverRefWrapper: React.FC<IHoverRefWrapper> = ({ accountId, children, inline = false }) => { export const HoverRefWrapper: React.FC<IHoverRefWrapper> = ({ accountId, children, inline = false, className }) => {
const dispatch = useDispatch(); const dispatch = useDispatch();
const ref = useRef<HTMLDivElement>(null); const ref = useRef<HTMLDivElement>(null);
const Elem: keyof JSX.IntrinsicElements = inline ? 'span' : 'div'; const Elem: keyof JSX.IntrinsicElements = inline ? 'span' : 'div';
@ -42,7 +44,7 @@ export const HoverRefWrapper: React.FC<IHoverRefWrapper> = ({ accountId, childre
return ( return (
<Elem <Elem
ref={ref} ref={ref}
className='hover-ref-wrapper' className={classNames('hover-ref-wrapper', className)}
onMouseEnter={handleMouseEnter} onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave} onMouseLeave={handleMouseLeave}
onClick={handleClick} onClick={handleClick}

View File

@ -101,7 +101,7 @@ const AnimatedTab: React.FC<IAnimatedTab> = ({ index, ...props }) => {
}; };
/** Structure to represent a tab. */ /** Structure to represent a tab. */
type Item = { export type Item = {
/** Tab text. */ /** Tab text. */
text: React.ReactNode, text: React.ReactNode,
/** Tab tooltip text. */ /** Tab tooltip text. */

View File

@ -3,12 +3,13 @@ import React, { useEffect, useState } from 'react';
import { FormattedMessage, defineMessages, useIntl } from 'react-intl'; import { FormattedMessage, defineMessages, useIntl } from 'react-intl';
import { fetchFavourites, fetchReactions } from 'soapbox/actions/interactions'; import { fetchFavourites, fetchReactions } from 'soapbox/actions/interactions';
import FilterBar from 'soapbox/components/filter_bar';
import ScrollableList from 'soapbox/components/scrollable_list'; import ScrollableList from 'soapbox/components/scrollable_list';
import { Modal, Spinner } from 'soapbox/components/ui'; import { Emoji, Modal, Spinner, Tabs } from 'soapbox/components/ui';
import AccountContainer from 'soapbox/containers/account_container'; import AccountContainer from 'soapbox/containers/account_container';
import { useAppDispatch, useAppSelector } from 'soapbox/hooks'; import { useAppDispatch, useAppSelector } from 'soapbox/hooks';
import type { Item } from 'soapbox/components/ui/tabs/tabs';
const messages = defineMessages({ const messages = defineMessages({
close: { id: 'lightbox.close', defaultMessage: 'Close' }, close: { id: 'lightbox.close', defaultMessage: 'Close' },
all: { id: 'reactions.all', defaultMessage: 'All' }, all: { id: 'reactions.all', defaultMessage: 'All' },
@ -24,14 +25,14 @@ const ReactionsModal: React.FC<IReactionsModal> = ({ onClose, statusId, reaction
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const intl = useIntl(); const intl = useIntl();
const [reaction, setReaction] = useState(initialReaction); const [reaction, setReaction] = useState(initialReaction);
const reactions = useAppSelector<Array<{ const reactions = useAppSelector<ImmutableList<{
accounts: Array<string>, accounts: Array<string>,
count: number, count: number,
name: string, name: string,
}>>((state) => { }>>((state) => {
const favourites = state.user_lists.getIn(['favourited_by', statusId]); const favourites = state.user_lists.getIn(['favourited_by', statusId]);
const reactions = state.user_lists.getIn(['reactions', statusId]); const reactions = state.user_lists.getIn(['reactions', statusId]);
return favourites && reactions && ImmutableList(favourites ? [{ accounts: favourites, count: favourites.size, name: '👍' }] : []).concat(reactions || []); return favourites && reactions && ImmutableList(favourites.size ? [{ accounts: favourites, count: favourites.size, name: '👍' }] : []).concat(reactions || []);
}); });
const fetchData = () => { const fetchData = () => {
@ -44,7 +45,7 @@ const ReactionsModal: React.FC<IReactionsModal> = ({ onClose, statusId, reaction
}; };
const renderFilterBar = () => { const renderFilterBar = () => {
const items = [ const items: Array<Item> = [
{ {
text: intl.formatMessage(messages.all), text: intl.formatMessage(messages.all),
action: () => setReaction(''), action: () => setReaction(''),
@ -54,13 +55,16 @@ const ReactionsModal: React.FC<IReactionsModal> = ({ onClose, statusId, reaction
reactions.forEach(reaction => items.push( reactions.forEach(reaction => items.push(
{ {
text: `${reaction.name} ${reaction.count}`, text: <div className='flex items-center gap-1'>
<Emoji className='w-4 h-4' emoji={reaction.name} />
{reaction.count}
</div>,
action: () => setReaction(reaction.name), action: () => setReaction(reaction.name),
name: reaction.name, name: reaction.name,
}, },
)); ));
return <FilterBar className='reaction__filter-bar' items={items} active={reaction || 'all'} />; return <Tabs items={items} activeItem={reaction || 'all'} />;
}; };
useEffect(() => { useEffect(() => {
@ -69,7 +73,7 @@ const ReactionsModal: React.FC<IReactionsModal> = ({ onClose, statusId, reaction
const accounts = reactions && (reaction const accounts = reactions && (reaction
? reactions.find(({ name }) => name === reaction)?.accounts.map(account => ({ id: account, reaction: reaction })) ? reactions.find(({ name }) => name === reaction)?.accounts.map(account => ({ id: account, reaction: reaction }))
: reactions.map(({ accounts, name }) => accounts.map(account => ({ id: account, reaction: name }))).flat()); : reactions.map(({ accounts, name }) => accounts.map(account => ({ id: account, reaction: name }))).flatten()) as Array<{ id: string, reaction: string }>;
let body; let body;
@ -79,14 +83,15 @@ const ReactionsModal: React.FC<IReactionsModal> = ({ onClose, statusId, reaction
const emptyMessage = <FormattedMessage id='status.reactions.empty' defaultMessage='No one has reacted to this post yet. When someone does, they will show up here.' />; const emptyMessage = <FormattedMessage id='status.reactions.empty' defaultMessage='No one has reacted to this post yet. When someone does, they will show up here.' />;
body = (<> body = (<>
{reactions.length > 0 && renderFilterBar()} {reactions.size > 0 && renderFilterBar()}
<ScrollableList <ScrollableList
scrollKey='reactions' scrollKey='reactions'
emptyMessage={emptyMessage} emptyMessage={emptyMessage}
className='mt-4'
itemClassName='pb-3' itemClassName='pb-3'
> >
{accounts.map((account) => {accounts.map((account) =>
<AccountContainer key={`${account.id}-${account.reaction}`} id={account.id} /* reaction={account.reaction} */ />, <AccountContainer key={`${account.id}-${account.reaction}`} id={account.id} emoji={account.reaction} />,
)} )}
</ScrollableList> </ScrollableList>
</>); </>);