Skip to content

Commit 3be8fc8

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 <[email protected]>
1 parent 4d03ca9 commit 3be8fc8

4 files changed

Lines changed: 33 additions & 6 deletions

File tree

src/backend/core/api/viewsets.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2956,9 +2956,11 @@ class CommentViewSet(
29562956
permission_classes = [permissions.CommentPermission]
29572957
pagination_class = Pagination
29582958
serializer_class = serializers.CommentSerializer
2959-
queryset = models.Comment.objects.select_related("user").prefetch_related(
2960-
"reactions__users"
2961-
).all()
2959+
queryset = (
2960+
models.Comment.objects.select_related("user")
2961+
.prefetch_related("reactions__users")
2962+
.all()
2963+
)
29622964

29632965
def get_queryset(self):
29642966
"""Override to filter on related resource."""

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export interface ConfigResponse {
5656
MEDIA_BASE_URL?: string;
5757
POSTHOG_KEY?: PostHogConf;
5858
SENTRY_DSN?: string;
59+
REACTIONS_MAX_PER_COMMENT: number;
5960
TRASHBIN_CUTOFF_DAYS?: number;
6061
theme_customization?: ThemeCustomization;
6162
}

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,
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
@@ -5,6 +5,7 @@ import { useCunninghamTheme } from '@/cunningham';
55
import { User, avatarUrlFromName } from '@/features/auth';
66
import { useEditorStore } from '@/features/docs/doc-editor/stores';
77
import { Doc, useProviderStore } from '@/features/docs/doc-management';
8+
import { useConfig } from '@/core';
89

910
import { DocsThreadStore } from './DocsThreadStore';
1011
import { DocsThreadStoreAuth } from './DocsThreadStoreAuth';
@@ -18,6 +19,7 @@ export function useComments(
1819
const { t } = useTranslation();
1920
const { themeTokens } = useCunninghamTheme();
2021
const { setThreadStore } = useEditorStore();
22+
const { data: config } = useConfig();
2123

2224
const threadStore = useMemo(() => {
2325
return new DocsThreadStore(
@@ -26,9 +28,16 @@ export function useComments(
2628
new DocsThreadStoreAuth(
2729
encodeURIComponent(user?.full_name || ''),
2830
canComment,
31+
config?.REACTIONS_MAX_PER_COMMENT ?? 0,
2932
),
3033
);
31-
}, [docId, canComment, provider?.awareness, user?.full_name]);
34+
}, [
35+
docId,
36+
canComment,
37+
provider?.awareness,
38+
user?.full_name,
39+
config?.REACTIONS_MAX_PER_COMMENT,
40+
]);
3241

3342
useEffect(() => {
3443
if (canComment) {

0 commit comments

Comments
 (0)