diff --git a/backend/src/models/Response.ts b/backend/src/models/Response.ts index 87a5992aa..86683f19c 100644 --- a/backend/src/models/Response.ts +++ b/backend/src/models/Response.ts @@ -37,6 +37,7 @@ export const ReactionKind = { LIKE: 'like', DISLIKE: 'dislike', CELEBRATE: 'celebrate', + HEART: 'heart', } as const export type ReactionKindKeys = (typeof ReactionKind)[keyof typeof ReactionKind] diff --git a/backend/src/routes.ts b/backend/src/routes.ts index e5a2023e6..3ac492758 100644 --- a/backend/src/routes.ts +++ b/backend/src/routes.ts @@ -169,7 +169,6 @@ server.patch('/api/v2/schema/:schemaId', ...patchSchema) server.delete('/api/v2/schema/:schemaId', ...deleteSchema) server.get('/api/v2/reviews', ...getReviews) - server.get('/api/v2/responses', ...getResponses) server.patch('/api/v2/response/:responseId', ...patchResponse) server.patch('/api/v2/response/:responseId/reaction/:kind', ...patchResponseReaction) diff --git a/backend/test/routes/entities/getEntityLookup.spec.ts b/backend/test/routes/entities/getEntityLookup.spec.ts index b99bd7d08..484d6938b 100644 --- a/backend/test/routes/entities/getEntityLookup.spec.ts +++ b/backend/test/routes/entities/getEntityLookup.spec.ts @@ -22,9 +22,6 @@ vi.mock('../../../src/utils/entity.js', async () => ({ describe('routes > entities > getEntityLookup', () => { test('200 > ok', async () => { - vi.mock('../../../src/services/model.js', () => ({ - getModelById: vi.fn(() => ({ _id: 'test' })), - })) const res = await testGet(`/api/v2/entity/userdn/lookup`) expect(res.statusCode).toBe(200) diff --git a/frontend/actions/user.ts b/frontend/actions/user.ts index 46d2f9291..72bd4d233 100644 --- a/frontend/actions/user.ts +++ b/frontend/actions/user.ts @@ -63,6 +63,10 @@ export function useGetUserInformation(dn: string) { } } +export function getUserInformation(dn: string) { + return fetch(`/api/v2/entity/${dn}/lookup`, { method: 'get' }) +} + interface GetUserTokensResponse { tokens: TokenInterface[] } diff --git a/frontend/src/reviews/ReactionButtons.tsx b/frontend/src/reviews/ReactionButtons.tsx index 00ed9f4ca..958498c28 100644 --- a/frontend/src/reviews/ReactionButtons.tsx +++ b/frontend/src/reviews/ReactionButtons.tsx @@ -1,4 +1,10 @@ -import { Celebration, InsertEmoticon, ThumbDown, ThumbUp } from '@mui/icons-material' +import { + CelebrationTwoTone, + FavoriteTwoTone, + InsertEmoticon, + ThumbDownTwoTone, + ThumbUpTwoTone, +} from '@mui/icons-material' import { IconButton, Popover, Stack } from '@mui/material' import { patchResponseReaction } from 'actions/response' import { useGetCurrentUser } from 'actions/user' @@ -47,7 +53,7 @@ export default function ReactionButtons({ response, mutateResponses, onError }: activeReactions.push( } + icon={} users={reaction.users} onReactionClick={handleReactionClick} />, @@ -57,7 +63,17 @@ export default function ReactionButtons({ response, mutateResponses, onError }: activeReactions.push( } + icon={} + users={reaction.users} + onReactionClick={handleReactionClick} + />, + ) + break + case ReactionKind.HEART: + activeReactions.push( + } users={reaction.users} onReactionClick={handleReactionClick} />, @@ -67,7 +83,7 @@ export default function ReactionButtons({ response, mutateResponses, onError }: activeReactions.push( } + icon={} users={reaction.users} onReactionClick={handleReactionClick} />, @@ -91,7 +107,7 @@ export default function ReactionButtons({ response, mutateResponses, onError }: return ( <> {isCurrentUserLoading && } - + setAnchorEl(event.currentTarget)}> @@ -112,13 +128,19 @@ export default function ReactionButtons({ response, mutateResponses, onError }: > handleReactionClick(ReactionKind.LIKE)}> - + handleReactionClick(ReactionKind.DISLIKE)}> - + + + handleReactionClick(ReactionKind.HEART)}> + handleReactionClick(ReactionKind.CELEBRATE)}> - + diff --git a/frontend/src/reviews/ReactionDisplay.tsx b/frontend/src/reviews/ReactionDisplay.tsx index 236dcd2ea..1ea9bc6e6 100644 --- a/frontend/src/reviews/ReactionDisplay.tsx +++ b/frontend/src/reviews/ReactionDisplay.tsx @@ -1,5 +1,6 @@ import { Button, Tooltip } from '@mui/material' -import { ReactNode, useMemo } from 'react' +import { getUserInformation } from 'actions/user' +import { ReactNode, useEffect, useState } from 'react' import { ReactionKindKeys } from 'types/types' import { plural } from 'utils/stringUtils' @@ -11,28 +12,34 @@ type ReactionDisplayProps = { } export default function ReactionDisplay({ kind, icon, users, onReactionClick }: ReactionDisplayProps) { - const title = useMemo(() => { - let text = '' - if (users.length > 3) { - text = `${users[0]}, ${users[1]}, ${users[2]} + ${users.length - 3} more` - } else { - users.forEach((user, index) => { - text += `${user}` - if (index !== users.length - 1) { - text += ', ' - } - }) + const [usersToDisplay, setUsersToDisplay] = useState('') + + useEffect(() => { + async function fetchData() { + if (!usersToDisplay) { + setUsersToDisplay( + `${users + .slice(0, 3) + .map(async (user) => { + const response = await getUserInformation(user) + if (response.ok) { + const responseBody = await response.json() + return responseBody.entity.name + } + }) + .join(', ')} ${users.length > 3 ? ` and ${users.length - 3} others` : ''}`, + ) + } } - return text - }, [users]) + fetchData() + }, [users, usersToDisplay]) return ( - +