Skip to content

Commit

Permalink
Individual reactions for meetings (#4271)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bestem0r committed Nov 22, 2023
1 parent 4bb84ce commit d76f248
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 2 deletions.
4 changes: 4 additions & 0 deletions app/actions/ReactionActions.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import callAPI from 'app/actions/callAPI';
import { Reaction } from './ActionTypes';
import type { ID } from 'app/models';
import type { CurrentUser } from 'app/store/models/User';
import type { Thunk } from 'app/types';

export function addReaction({
emoji,
user,
contentTarget,
unicodeString,
}: {
emoji: string;
user?: CurrentUser;
contentTarget: string;
unicodeString: string;
}): Thunk<void> {
Expand All @@ -24,6 +27,7 @@ export function addReaction({
},
meta: {
emoji,
user: user,
contentTarget,
unicodeString,
},
Expand Down
21 changes: 20 additions & 1 deletion app/components/LegoReactions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ import Reaction from 'app/components/Reactions/Reaction';
import type { ID } from 'app/store/models';
import type Emoji from 'app/store/models/Emoji';
import type { ReactionsGrouped } from 'app/store/models/Reaction';
import type { CurrentUser } from 'app/store/models/User';
import type { ContentTarget } from 'app/store/utils/contentTarget';

type Props = {
user: CurrentUser;
addReaction: (args: {
emoji: string;
user: CurrentUser;
contentTarget: ContentTarget;
unicodeString: string;
}) => Promise<void>;
Expand All @@ -21,6 +24,7 @@ type Props = {
parentEntity: {
contentTarget: ContentTarget;
reactionsGrouped?: ReactionsGrouped[];
reactions?: { author: { fullName: string }; emoji: string }[];
};
loggedIn: boolean;
};
Expand All @@ -32,6 +36,7 @@ export type EmojiWithReactionData = Emoji & {

const LegoReactions = (props: Props) => {
const {
user,
addReaction,
deleteReaction,
emojis,
Expand All @@ -58,24 +63,38 @@ const LegoReactions = (props: Props) => {
});
}

const usersByReaction = {};

if (parentEntity.reactions) {
for (const reaction of parentEntity.reactions) {
if (!usersByReaction[reaction.emoji]) {
usersByReaction[reaction.emoji] = [];
}
usersByReaction[reaction.emoji].push(reaction.author);
}
}

return (
<Reactions
emojis={mappedEmojis}
user={user}
fetchEmojis={fetchEmojis}
fetchingEmojis={fetchingEmojis}
addReaction={addReaction}
deleteReaction={deleteReaction}
contentTarget={parentEntity.contentTarget}
loggedIn={loggedIn}
>
{parentEntity.reactionsGrouped.map((reaction) => {
{parentEntity.reactionsGrouped?.map((reaction) => {
return (
<Reaction
key={`reaction-${reaction.emoji}`}
emoji={reaction.emoji}
count={reaction.count}
users={usersByReaction[reaction.emoji]}
unicodeString={reaction.unicodeString}
reactionId={reaction.reactionId}
user={user}
hasReacted={reaction.hasReacted}
canReact={loggedIn}
addReaction={addReaction}
Expand Down
21 changes: 20 additions & 1 deletion app/components/Reactions/Reaction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ import Emoji from 'app/components/Emoji';
import Tooltip from 'app/components/Tooltip';
import styles from './Reaction.css';
import type { ID } from 'app/store/models';
import type { CurrentUser } from 'app/store/models/User';
import type { ContentTarget } from 'app/store/utils/contentTarget';

type Props = {
className?: string;
user: CurrentUser;
emoji: string;
count: number;
users?: { fullName: string }[];
unicodeString: string;
addReaction: (args: {
emoji: string;
user: CurrentUser;
contentTarget: ContentTarget;
unicodeString?: string;
}) => Promise<void>;
Expand All @@ -30,8 +34,10 @@ type Props = {

const Reaction = ({
className,
user,
emoji,
count,
users,
unicodeString,
addReaction,
deleteReaction,
Expand All @@ -53,9 +59,20 @@ const Reaction = ({
return <></>;
}

let tooltipContent = '';
if (users && users.length > 0) {
tooltipContent += users
.filter((user) => user)
.map((user) => user.fullName)
.join(', ');
tooltipContent += ' reagerte med ';
}

tooltipContent += emoji;

return (
<>
<Tooltip content={emoji}>
<Tooltip content={tooltipContent}>
<Flex
gap={4}
justifyContent="center"
Expand All @@ -67,10 +84,12 @@ const Reaction = ({
hasReacted
? deleteReaction({
reactionId,
user: user,
contentTarget: contentTarget,
})
: addReaction({
emoji,
user: user,
contentTarget,
unicodeString,
})
Expand Down
5 changes: 5 additions & 0 deletions app/components/Reactions/ReactionPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ import ReactionPickerFooter from './ReactionPickerFooter';
import ReactionPickerHeader from './ReactionPickerHeader';
import type { EmojiWithReactionData } from 'app/components/LegoReactions';
import type { ID } from 'app/store/models';
import type { CurrentUser } from 'app/store/models/User';
import type { ContentTarget } from 'app/store/utils/contentTarget';

type Props = {
isLoading: boolean;
user: CurrentUser;
emojis: EmojiWithReactionData[];
addReaction: (args: {
emoji: string;
user: CurrentUser;
contentTarget: ContentTarget;
unicodeString: string;
}) => Promise<void>;
Expand Down Expand Up @@ -143,6 +146,7 @@ const searchEmojis = (

const ReactionPicker = ({
isLoading,
user,
emojis,
addReaction,
deleteReaction,
Expand Down Expand Up @@ -209,6 +213,7 @@ const ReactionPicker = ({
? categories[activeCategory].emojis
: []
}
user={user}
searchResults={searchResults}
addReaction={addReaction}
deleteReaction={deleteReaction}
Expand Down
5 changes: 5 additions & 0 deletions app/components/Reactions/ReactionPickerContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ import Emoji from 'app/components/Emoji';
import styles from './ReactionPickerContent.css';
import type { EmojiWithReactionData } from 'app/components/LegoReactions';
import type { ID } from 'app/store/models';
import type { CurrentUser } from 'app/store/models/User';
import type { ContentTarget } from 'app/store/utils/contentTarget';

type Props = {
emojis: EmojiWithReactionData[];
user: CurrentUser;
searchResults: EmojiWithReactionData[] | null;
addReaction: (args: {
emoji: string;
user: CurrentUser;
contentTarget: ContentTarget;
unicodeString: string;
}) => Promise<void>;
Expand All @@ -21,6 +24,7 @@ type Props = {

const ReactionPickerContent = ({
emojis,
user,
searchResults,
addReaction,
deleteReaction,
Expand Down Expand Up @@ -49,6 +53,7 @@ const ReactionPickerContent = ({
})
: addReaction({
emoji: emoji.shortCode,
user: user,
contentTarget,
unicodeString: emoji.unicodeString,
})
Expand Down
5 changes: 5 additions & 0 deletions app/components/Reactions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ import AddReactionEmoji from './assets/AddReactionEmoji';
import styles from './index.css';
import type { EmojiWithReactionData } from 'app/components/LegoReactions';
import type { ID } from 'app/models';
import type { CurrentUser } from 'app/store/models/User';
import type { ContentTarget } from 'app/store/utils/contentTarget';
import type { ReactNode, SyntheticEvent } from 'react';

type Props = {
user: CurrentUser;
children: ReactNode;
className?: string;
emojis: EmojiWithReactionData[];
fetchingEmojis: boolean;
addReaction: (args: {
emoji: string;
user: CurrentUser;
contentTarget: ContentTarget;
unicodeString: string;
}) => Promise<void>;
Expand All @@ -33,6 +36,7 @@ type Props = {
// app/components/LegoReactions.

const Reactions = ({
user,
children,
className,
emojis,
Expand Down Expand Up @@ -111,6 +115,7 @@ const Reactions = ({
<div className={styles.reactionPickerContainer}>
<ReactionPicker
emojis={emojis}
user={user}
isLoading={fetchingEmojis}
addReaction={addReaction}
deleteReaction={deleteReaction}
Expand Down
57 changes: 57 additions & 0 deletions app/reducers/__tests__/reactions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ describe('reducers', () => {
id: 3,
text: 'hello world',
name: 'welcome',
reactions: [
{
author: {
fullName: 'test',
},
emoji: ':joy:',
reactionId: 33,
unicodeString: '123',
},
],
reactionsGrouped: [
{
emoji: ':joy:',
Expand All @@ -32,6 +42,7 @@ describe('reducers', () => {
id: 4,
text: 'test',
name: 'test',
reactions: [],
reactionsGrouped: [],
},
},
Expand Down Expand Up @@ -59,6 +70,16 @@ describe('reducers', () => {
id: 3,
text: 'hello world',
name: 'welcome',
reactions: [
{
author: {
fullName: 'test',
},
emoji: ':joy:',
reactionId: 33,
unicodeString: '123',
},
],
reactionsGrouped: [
{
emoji: ':joy:',
Expand All @@ -72,6 +93,14 @@ describe('reducers', () => {
id: 4,
text: 'test',
name: 'test',
reactions: [
{
author: undefined,
emoji: ':joy:',
reactionId: 33,
unicodeString: '123',
},
],
reactionsGrouped: [
{
emoji: ':joy:',
Expand Down Expand Up @@ -108,6 +137,22 @@ describe('reducers', () => {
id: 3,
text: 'hello world',
name: 'welcome',
reactions: [
{
author: {
fullName: 'test',
},
emoji: ':joy:',
reactionId: 33,
unicodeString: '123',
},
{
author: undefined,
emoji: ':joy:',
reactionId: 33,
unicodeString: '123',
},
],
reactionsGrouped: [
{
emoji: ':joy:',
Expand All @@ -122,6 +167,7 @@ describe('reducers', () => {
id: 4,
text: 'test',
name: 'test',
reactions: [],
reactionsGrouped: [],
},
},
Expand All @@ -138,6 +184,16 @@ describe('reducers', () => {
id: 3,
text: 'hello world',
name: 'welcome',
reactions: [
{
author: {
fullName: 'test',
},
emoji: ':joy:',
reactionId: 33,
unicodeString: '123',
},
],
reactionsGrouped: [
{
emoji: ':joy:',
Expand Down Expand Up @@ -166,6 +222,7 @@ describe('reducers', () => {
id: 3,
text: 'hello world',
name: 'welcome',
reactions: [],
reactionsGrouped: [],
},
},
Expand Down

0 comments on commit d76f248

Please sign in to comment.