Skip to content

Commit 390085d

Browse files
committed
✨(frontend) add UI support for reaction limit on comments
Prevent users from adding more reactions once the per-message limit has been exceeded. It Disables reaction buttons when limit is reached Signed-off-by: Mohamed El Amine BOUKERFA <boukerfa.ma@gmail.com>
1 parent 862bc86 commit 390085d

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

src/frontend/apps/impress/src/core/config/api/useConfig.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export interface ConfigResponse {
4848
MEDIA_BASE_URL?: string;
4949
POSTHOG_KEY?: PostHogConf;
5050
SENTRY_DSN?: string;
51+
REACTIONS_MAX_PER_COMMENT: number;
5152
TRASHBIN_CUTOFF_DAYS?: number;
5253
theme_customization?: ThemeCustomization;
5354
}

src/frontend/apps/impress/src/features/docs/doc-editor/components/comments/DocsThreadStoreAuth.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export class DocsThreadStoreAuth extends ThreadStoreAuth {
66
constructor(
77
private readonly userId: string,
88
public canSee: boolean,
9+
private readonly maxReactions: number = 10,
910
) {
1011
super();
1112
}
@@ -68,13 +69,27 @@ export class DocsThreadStoreAuth extends ThreadStoreAuth {
6869
}
6970

7071
if (!emoji) {
71-
return true;
72+
return comment.reactions.length < this.maxReactions;
7273
}
7374

74-
return !comment.reactions.some(
75+
const hasReactedWithEmoji = comment.reactions.some(
7576
(reaction) =>
7677
reaction.emoji === emoji && reaction.userIds.includes(this.userId),
7778
);
79+
80+
if (hasReactedWithEmoji) {
81+
return false;
82+
}
83+
84+
const reactionExists = comment.reactions.some(
85+
(reaction) => reaction.emoji === emoji,
86+
);
87+
88+
if (reactionExists) {
89+
return true;
90+
}
91+
92+
return comment.reactions.length < this.maxReactions;
7893
}
7994

8095
canDeleteReaction(comment: ClientCommentData, emoji?: string): boolean {

src/frontend/apps/impress/src/features/docs/doc-editor/components/comments/useComments.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useTranslation } from 'react-i18next';
44
import { useCunninghamTheme } from '@/cunningham';
55
import { User, avatarUrlFromName } from '@/features/auth';
66
import { Doc, useProviderStore } from '@/features/docs/doc-management';
7+
import { useConfig } from '@/core';
78

89
import { DocsThreadStore } from './DocsThreadStore';
910
import { DocsThreadStoreAuth } from './DocsThreadStoreAuth';
@@ -16,6 +17,7 @@ export function useComments(
1617
const { provider } = useProviderStore();
1718
const { t } = useTranslation();
1819
const { themeTokens } = useCunninghamTheme();
20+
const { data: config } = useConfig();
1921

2022
const threadStore = useMemo(() => {
2123
return new DocsThreadStore(
@@ -24,9 +26,16 @@ export function useComments(
2426
new DocsThreadStoreAuth(
2527
encodeURIComponent(user?.full_name || ''),
2628
canComment,
29+
config?.REACTIONS_MAX_PER_COMMENT,
2730
),
2831
);
29-
}, [docId, canComment, provider?.awareness, user?.full_name]);
32+
}, [
33+
docId,
34+
canComment,
35+
provider?.awareness,
36+
user?.full_name,
37+
config?.REACTIONS_MAX_PER_COMMENT,
38+
]);
3039

3140
useEffect(() => {
3241
return () => {

0 commit comments

Comments
 (0)