Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

refactor(web): pass narrowed authenticated user to onReact in toolbar reactions

GhaZy674dc511bef8
diff --git a/apps/web/__tests__/unit/toolbar-reactions.test.ts b/apps/web/__tests__/unit/toolbar-reactions.test.ts
index 1281e29ee..c76ca2ba6 100644
--- a/apps/web/__tests__/unit/toolbar-reactions.test.ts
+++ b/apps/web/__tests__/unit/toolbar-reactions.test.ts
@@ -78,6 +78,6 @@ describe("toolbar reactions", () => {
expect(onRequireAuth).not.toHaveBeenCalled();
expect(onReact).toHaveBeenCalledOnce();
- expect(onReact).toHaveBeenCalledWith("πŸ™Œ");
+ expect(onReact).toHaveBeenCalledWith("πŸ™Œ", { id: "user-123" });
});
});
diff --git a/apps/web/app/s/[videoId]/_components/Toolbar.tsx b/apps/web/app/s/[videoId]/_components/Toolbar.tsx
index 47a903a16..64420f05d 100644
--- a/apps/web/app/s/[videoId]/_components/Toolbar.tsx
+++ b/apps/web/app/s/[videoId]/_components/Toolbar.tsx
@@ -91,7 +91,7 @@ export const Toolbar = ({
canReact,
user,
onRequireAuth: () => setShowAuthOverlay(true),
- onReact: async (chosenEmoji) => {
+ onReact: async (chosenEmoji, authedUser) => {
const videoElement = document.querySelector(
"video",
) as HTMLVideoElement;
@@ -100,9 +100,9 @@ export const Toolbar = ({
: videoElement?.currentTime || 0;
const optimisticComment: CommentType = {
id: `temp-${Date.now()}` as Comment.CommentId,
- authorId: user?.id ?? "",
- authorName: user?.name ?? null,
- authorImage: user?.imageUrl ?? null,
+ authorId: authedUser.id,
+ authorName: authedUser.name,
+ authorImage: authedUser.imageUrl,
content: chosenEmoji,
createdAt: new Date(),
videoId: data.id,
@@ -122,7 +122,7 @@ export const Toolbar = ({
const newCommentData = await newComment({
content: chosenEmoji,
videoId: data.id,
- authorImage: user?.imageUrl ?? null,
+ authorImage: authedUser.imageUrl,
parentCommentId: "" as Comment.CommentId,
type: "emoji",
timestamp: currentTime,
diff --git a/apps/web/app/s/[videoId]/_components/toolbar-reactions.ts b/apps/web/app/s/[videoId]/_components/toolbar-reactions.ts
index 666da216d..99a1ff379 100644
--- a/apps/web/app/s/[videoId]/_components/toolbar-reactions.ts
+++ b/apps/web/app/s/[videoId]/_components/toolbar-reactions.ts
@@ -30,25 +30,25 @@ export const REACTIONS: readonly ReactionDefinition[] = [
},
];
-export interface HandleEmojiReactionParams {
+export interface HandleEmojiReactionParams<TUser> {
emoji: string;
canReact: boolean;
- user: { id: string } | null | undefined;
+ user: TUser | null | undefined;
onRequireAuth: () => void;
- onReact: (emoji: string) => void | Promise<void>;
+ onReact: (emoji: string, user: TUser) => void | Promise<void>;
}
-export function handleEmojiReaction({
+export function handleEmojiReaction<TUser>({
emoji,
canReact,
user,
onRequireAuth,
onReact,
-}: HandleEmojiReactionParams): void {
+}: HandleEmojiReactionParams<TUser>): void {
if (!canReact) return;
if (!user) {
onRequireAuth();
return;
}
- void onReact(emoji);
+ void onReact(emoji, user);
}