Skip to content

Commit f24ef4b

Browse files
committed
cleanup
1 parent 3cb68c8 commit f24ef4b

File tree

5 files changed

+21
-28
lines changed

5 files changed

+21
-28
lines changed

apps/web/app/s/[videoId]/Share.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,6 @@ export const Share = ({
307307
<Toolbar
308308
onOptimisticComment={handleOptimisticComment}
309309
onCommentSuccess={handleCommentSuccess}
310-
playerRef={playerRef}
311310
data={data}
312311
user={user}
313312
/>
@@ -345,7 +344,6 @@ export const Share = ({
345344
onCommentSuccess={handleCommentSuccess}
346345
data={data}
347346
user={user}
348-
playerRef={playerRef}
349347
/>
350348
</div>
351349
</div>

apps/web/app/s/[videoId]/_components/Sidebar.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { comments as commentsSchema, videos } from "@cap/database/schema";
33
import { classNames } from "@cap/utils";
44
import type { Video } from "@cap/web-domain";
55
import { AnimatePresence, motion } from "framer-motion";
6-
import { forwardRef, type RefObject, Suspense, useState } from "react";
6+
import { forwardRef, Suspense, useState } from "react";
77
import { Activity } from "./tabs/Activity";
88
import { Settings } from "./tabs/Settings";
99
import { Summary } from "./tabs/Summary";
@@ -31,7 +31,6 @@ interface SidebarProps {
3131
views: MaybePromise<number>;
3232
onSeek?: (time: number) => void;
3333
videoId: Video.VideoId;
34-
playerRef: RefObject<HTMLVideoElement | null>;
3534
aiData?: {
3635
title?: string | null;
3736
summary?: string | null;
@@ -76,7 +75,6 @@ export const Sidebar = forwardRef<{ scrollToBottom: () => void }, SidebarProps>(
7675
handleCommentSuccess,
7776
setOptimisticComments,
7877
views,
79-
playerRef,
8078
onSeek,
8179
videoId,
8280
aiData,
@@ -135,7 +133,6 @@ export const Sidebar = forwardRef<{ scrollToBottom: () => void }, SidebarProps>(
135133
isOwnerOrMember={isOwnerOrMember}
136134
onSeek={onSeek}
137135
videoId={videoId}
138-
playerRef={playerRef}
139136
/>
140137
</Suspense>
141138
);

apps/web/app/s/[videoId]/_components/Toolbar.tsx

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,7 @@ import type { userSelectProps } from "@cap/database/auth/session";
22
import type { videos } from "@cap/database/schema";
33
import { Button } from "@cap/ui";
44
import { AnimatePresence, motion } from "motion/react";
5-
import {
6-
type RefObject,
7-
startTransition,
8-
useCallback,
9-
useEffect,
10-
useState,
11-
} from "react";
5+
import { startTransition, useCallback, useEffect, useState } from "react";
126
import { newComment } from "@/actions/videos/new-comment";
137
import type { CommentType } from "../Share";
148
import { AuthOverlay } from "./AuthOverlay";
@@ -21,22 +15,20 @@ interface ToolbarProps {
2115
user: typeof userSelectProps | null;
2216
onOptimisticComment?: (comment: CommentType) => void;
2317
onCommentSuccess?: (comment: CommentType) => void;
24-
playerRef: RefObject<HTMLVideoElement | null>;
2518
}
2619

2720
export const Toolbar = ({
2821
data,
2922
user,
3023
onOptimisticComment,
3124
onCommentSuccess,
32-
playerRef,
3325
}: ToolbarProps) => {
3426
const [commentBoxOpen, setCommentBoxOpen] = useState(false);
3527
const [comment, setComment] = useState("");
3628
const [showAuthOverlay, setShowAuthOverlay] = useState(false);
37-
const videoElement = playerRef.current;
3829

3930
const handleEmojiClick = async (emoji: string) => {
31+
const videoElement = document.querySelector("video") as HTMLVideoElement;
4032
const currentTime = videoElement?.currentTime || 0;
4133
const optimisticComment: CommentType = {
4234
id: `temp-${Date.now()}`,
@@ -77,6 +69,7 @@ export const Toolbar = ({
7769
if (comment.length === 0) {
7870
return;
7971
}
72+
const videoElement = document.querySelector("video") as HTMLVideoElement;
8073
const currentTime = videoElement?.currentTime || 0;
8174
const optimisticComment: CommentType = {
8275
id: `temp-${Date.now()}`,
@@ -147,6 +140,9 @@ export const Toolbar = ({
147140
setShowAuthOverlay(true);
148141
return;
149142
}
143+
const videoElement = document.querySelector(
144+
"video",
145+
) as HTMLVideoElement;
150146
if (videoElement) {
151147
videoElement.pause();
152148
}
@@ -158,13 +154,14 @@ export const Toolbar = ({
158154
return () => {
159155
window.removeEventListener("keydown", handleKeyPress);
160156
};
161-
}, [commentBoxOpen, user, videoElement]);
157+
}, [commentBoxOpen, user]);
162158

163159
const handleCommentClick = () => {
164160
if (!user) {
165161
setShowAuthOverlay(true);
166162
return;
167163
}
164+
const videoElement = document.querySelector("video") as HTMLVideoElement;
168165
if (videoElement) {
169166
videoElement.pause();
170167
}
@@ -219,9 +216,14 @@ export const Toolbar = ({
219216
handleCommentSubmit();
220217
}}
221218
>
222-
{videoElement && videoElement.currentTime > 0
223-
? `Comment at ${videoElement.currentTime.toFixed(2)}`
224-
: "Comment"}
219+
{(() => {
220+
const videoElement = document.querySelector(
221+
"video",
222+
) as HTMLVideoElement;
223+
return videoElement && videoElement.currentTime > 0
224+
? `Comment at ${videoElement.currentTime.toFixed(2)}`
225+
: "Comment";
226+
})()}
225227
</MotionButton>
226228
<MotionButton
227229
variant="gray"

apps/web/app/s/[videoId]/_components/tabs/Activity/Comments.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
type ComponentProps,
88
forwardRef,
99
type PropsWithChildren,
10-
type RefObject,
1110
startTransition,
1211
useCallback,
1312
useEffect,
@@ -34,15 +33,13 @@ export const Comments = Object.assign(
3433
handleCommentSuccess: (comment: CommentType) => void;
3534
onSeek?: (time: number) => void;
3635
setShowAuthOverlay: (v: boolean) => void;
37-
playerRef: RefObject<HTMLVideoElement | null>;
3836
}
3937
>((props, ref) => {
4038
const {
4139
optimisticComments,
4240
setOptimisticComments,
4341
setComments,
4442
handleCommentSuccess,
45-
playerRef,
4643
onSeek,
4744
} = props;
4845
const commentParams = useSearchParams().get("comment");
@@ -78,7 +75,8 @@ export const Comments = Object.assign(
7875

7976
const handleNewComment = async (content: string) => {
8077
// Get current video time from the video element
81-
const currentTime = playerRef?.current?.currentTime || 0;
78+
const videoElement = document.querySelector("video") as HTMLVideoElement;
79+
const currentTime = videoElement?.currentTime || 0;
8280

8381
const optimisticComment: CommentType = {
8482
id: `temp-${Date.now()}`,
@@ -114,7 +112,8 @@ export const Comments = Object.assign(
114112

115113
const handleReply = async (content: string) => {
116114
if (!replyingTo) return;
117-
const currentTime = playerRef?.current?.currentTime || 0;
115+
const videoElement = document.querySelector("video") as HTMLVideoElement;
116+
const currentTime = videoElement?.currentTime || 0;
118117

119118
const parentComment = optimisticComments.find((c) => c.id === replyingTo);
120119
const actualParentId = parentComment?.parentCommentId

apps/web/app/s/[videoId]/_components/tabs/Activity/index.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ interface ActivityProps {
2727
optimisticComments: CommentType[];
2828
setOptimisticComments: (newComment: CommentType) => void;
2929
isOwnerOrMember: boolean;
30-
playerRef: RefObject<HTMLVideoElement | null>;
3130
}
3231

3332
export const Activity = Object.assign(
@@ -37,7 +36,6 @@ export const Activity = Object.assign(
3736
user,
3837
videoId,
3938
isOwnerOrMember,
40-
playerRef,
4139
comments,
4240
handleCommentSuccess,
4341
optimisticComments,
@@ -73,7 +71,6 @@ export const Activity = Object.assign(
7371
videoId={videoId}
7472
setShowAuthOverlay={setShowAuthOverlay}
7573
onSeek={props.onSeek}
76-
playerRef={playerRef}
7774
/>
7875
)}
7976
</Activity.Shell>

0 commit comments

Comments
 (0)