Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
feat(web): wire activity tab for media comments
Richie McIlroy7f1ca79efbfa
diff --git a/apps/web/app/s/[videoId]/_components/tabs/Activity/ActivityComposer.tsx b/apps/web/app/s/[videoId]/_components/tabs/Activity/ActivityComposer.tsxnew file mode 100644index 000000000..54928fab3--- /dev/null+++ b/apps/web/app/s/[videoId]/_components/tabs/Activity/ActivityComposer.tsx@@ -0,0 +1,171 @@+"use client";++import type { Video } from "@cap/web-domain";+import dynamic from "next/dynamic";+import { useCallback, useState } from "react";+import { useCurrentUser } from "@/app/Layout/AuthContext";+import { SignedImageUrl } from "@/components/SignedImageUrl";+import type { CommentType } from "../../../Share";+import { useOptionalPlayback } from "../../playback/PlaybackContext";+import type { RecordIntentKind } from "../../timeline/TimelineComposer";+import CommentInput from "./CommentInput";++// Same deal as the timeline: capture and upload code only loads once someone+// presses record.+const RecorderSurface = dynamic(+ () => import("../../timeline/recording/RecorderSurface"),+ { ssr: false },+);++const RECORD_OPTIONS: { kind: RecordIntentKind; label: string }[] = [+ { kind: "screen", label: "Record screen" },+ { kind: "camera", label: "Record camera" },+ { kind: "voice", label: "Record voice note" },+];++interface ActivityComposerProps {+ videoId: Video.VideoId;+ /** Whose video this is, for the placeholder. */+ ownerName?: string | null;+ disabled?: boolean;+ onSubmit: (content: string) => void;+ setShowAuthOverlay: (show: boolean) => void;+ /** Owner is on Pro and the viewer is signed in; the upload path re-checks. */+ canRecordMedia?: boolean;+ onOptimisticComment?: (comment: CommentType) => void;+ onCommentSuccess?: (comment: CommentType) => void;+}++/**+ * The panel's composer, pinned above the comment list. Leading with it (rather+ * than parking it under the scroll) means the primary action is the first thing+ * in the sidebar and an empty panel reads as an invitation.+ */+export function ActivityComposer({+ videoId,+ ownerName,+ disabled,+ onSubmit,+ setShowAuthOverlay,+ canRecordMedia = false,+ onOptimisticComment,+ onCommentSuccess,+}: ActivityComposerProps) {+ const user = useCurrentUser();+ const playback = useOptionalPlayback();+ const [recordIntent, setRecordIntent] = useState<{+ kind: RecordIntentKind;+ t: number;+ } | null>(null);++ const startRecording = useCallback(+ (kind: RecordIntentKind) => {+ // Anchor to wherever the viewer is watching, same as a text comment,+ // and get out of the way of whatever they are about to record.+ const t = playback?.getCurrentTime() ?? 0;+ playback?.pause();+ setRecordIntent({ kind, t });+ },+ [playback],+ );++ // Signed out: the same shape as the real composer rather than a solid+ // sign-in bar, so the panel still opens on an invitation to write.+ if (!user) {+ return (+ <button+ type="button"+ onClick={() => setShowAuthOverlay(true)}+ className="flex w-full items-center gap-2 p-2 text-left rounded-lg border transition-colors bg-gray-1 border-gray-5 hover:border-gray-6"+ >+ <span className="flex justify-center items-center rounded-full size-7 shrink-0 bg-gray-4 text-gray-10">+ <svg viewBox="0 0 16 16" className="size-4 fill-current" aria-hidden>+ <title>Viewer</title>+ <path d="M8 8a3 3 0 1 0 0-6 3 3 0 0 0 0 6Zm0 1.2c-2.6 0-4.8 1.5-4.8 3.3 0 .6.5 1 1.1 1h7.4c.6 0 1.1-.4 1.1-1 0-1.8-2.2-3.3-4.8-3.3Z" />+ </svg>+ </span>+ <span className="flex-1 text-sm truncate text-gray-8">+ {ownerName ? `Respond to ${ownerName}...` : "Leave a comment"}+ </span>+ <span className="text-xs font-medium shrink-0 text-blue-9">+ Sign in+ </span>+ </button>+ );+ }++ return (+ <>+ <CommentInput+ collapsible+ onSubmit={onSubmit}+ disabled={disabled}+ placeholder={+ ownerName ? `Respond to ${ownerName}...` : "Leave a comment"+ }+ buttonLabel="Comment"+ avatar={+ <SignedImageUrl+ image={user.imageUrl}+ name={user.name ?? "You"}+ className="size-7 rounded-full"+ letterClass="text-[11px] font-medium"+ />+ }+ actions={+ canRecordMedia+ ? RECORD_OPTIONS.map((option) => (+ <button+ key={option.kind}+ type="button"+ aria-label={option.label}+ title={option.label}+ disabled={disabled}+ onClick={() => startRecording(option.kind)}+ className="flex size-8 items-center justify-center rounded-lg text-gray-10 transition-colors hover:bg-gray-3 hover:text-gray-12 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-9 disabled:opacity-50"+ >+ <RecordIcon kind={option.kind} />+ </button>+ ))+ : null+ }+ />++ {recordIntent && (+ <RecorderSurface+ kind={recordIntent.kind}+ timestamp={recordIntent.t}+ videoId={videoId}+ onOptimisticComment={onOptimisticComment}+ onCommentSuccess={onCommentSuccess}+ onClose={() => setRecordIntent(null)}+ />+ )}+ </>+ );+}++function RecordIcon({ kind }: { kind: RecordIntentKind }) {+ if (kind === "voice") {+ return (+ <svg viewBox="0 0 16 16" className="size-4 fill-current" aria-hidden>+ <title>Voice</title>+ <path d="M8 2a2 2 0 0 0-2 2v4a2 2 0 1 0 4 0V4a2 2 0 0 0-2-2ZM4.4 7.4a.6.6 0 0 0-1.2 0 4.8 4.8 0 0 0 4.2 4.76V13.4H5.8a.6.6 0 1 0 0 1.2h4.4a.6.6 0 1 0 0-1.2H8.6v-1.24a4.8 4.8 0 0 0 4.2-4.76.6.6 0 1 0-1.2 0 3.6 3.6 0 1 1-7.2 0Z" />+ </svg>+ );+ }+ if (kind === "camera") {+ return (+ <svg viewBox="0 0 16 16" className="size-4 fill-current" aria-hidden>+ <title>Camera</title>+ <path d="M2.5 4A1.5 1.5 0 0 0 1 5.5v5A1.5 1.5 0 0 0 2.5 12h6A1.5 1.5 0 0 0 10 10.5v-5A1.5 1.5 0 0 0 8.5 4h-6Zm9.2 2.4 2.6-1.5c.3-.2.7 0 .7.4v5.4c0 .4-.4.6-.7.4l-2.6-1.5V6.4Z" />+ </svg>+ );+ }+ return (+ <svg viewBox="0 0 16 16" className="size-4 fill-current" aria-hidden>+ <title>Screen</title>+ <path d="M2 4a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V4Zm3.2 9.4h5.6a.6.6 0 1 1 0 1.2H5.2a.6.6 0 1 1 0-1.2Z" />+ </svg>+ );+}diff --git a/apps/web/app/s/[videoId]/_components/tabs/Activity/Comment.tsx b/apps/web/app/s/[videoId]/_components/tabs/Activity/Comment.tsxindex b59227ee0..8739153ec 100644--- a/apps/web/app/s/[videoId]/_components/tabs/Activity/Comment.tsx+++ b/apps/web/app/s/[videoId]/_components/tabs/Activity/Comment.tsx@@ -4,7 +4,7 @@ import { faReply, faTrash } from "@fortawesome/free-solid-svg-icons";import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";import clsx from "clsx";-import { motion } from "framer-motion";+import { motion } from "motion/react";import { useSearchParams } from "next/navigation";import type React from "react";import { useCurrentUser } from "@/app/Layout/AuthContext";@@ -12,6 +12,8 @@ import { LinkifiedText } from "@/components/LinkifiedText";import { SignedImageUrl } from "@/components/SignedImageUrl";import { Tooltip } from "@/components/Tooltip";import type { CommentType } from "../../../Share";+import { MediaCommentBody } from "../../media-comment/MediaCommentBody";+import { isMediaComment } from "../../media-comment/media-comment-types";import CommentInput from "./CommentInput";import { formatTimeAgo, formatTimestamp } from "./utils";@@ -127,9 +129,20 @@ const CommentComponent: React.FC<{)}</div></div>- <p className="mt-2 text-sm text-gray-11">- <LinkifiedText text={comment.content} />- </p>+ {isMediaComment(comment) ? (+ <div className="mt-2 space-y-2">+ <MediaCommentBody comment={comment} compact />+ {comment.content && (+ <p className="text-sm text-gray-11">+ <LinkifiedText text={comment.content} />+ </p>+ )}+ </div>+ ) : (+ <p className="mt-2 text-sm text-gray-11">+ <LinkifiedText text={comment.content} />+ </p>+ )}<div className="flex items-center pt-2 mt-2.5 space-x-3 border-t border-gray-3">{user && !isReplying && canReply && (<Tooltip content="Reply">diff --git a/apps/web/app/s/[videoId]/_components/tabs/Activity/CommentInput.tsx b/apps/web/app/s/[videoId]/_components/tabs/Activity/CommentInput.tsxindex 7e6caa0f9..089132a4f 100644--- a/apps/web/app/s/[videoId]/_components/tabs/Activity/CommentInput.tsx+++ b/apps/web/app/s/[videoId]/_components/tabs/Activity/CommentInput.tsx@@ -1,6 +1,6 @@import { Button } from "@cap/ui";import type React from "react";-import { useEffect, useRef, useState } from "react";+import { type ReactNode, useEffect, useRef, useState } from "react";interface CommentInputProps {onSubmit?: (content: string) => void;@@ -10,6 +10,16 @@ interface CommentInputProps {buttonLabel?: string;autoFocus?: boolean;disabled?: boolean;+ /** Rendered to the left of the field, e.g. the viewer's avatar. */+ avatar?: ReactNode;+ /** Rendered to the right of the field, e.g. the record buttons. */+ actions?: ReactNode;+ /**+ * Idles as a single line and only grows (and reveals its submit button) once+ * it has focus or content. The panel composer uses this so sitting at the top+ * of the sidebar costs one row; replies keep the always-open form.+ */+ collapsible?: boolean;}const CommentInput: React.FC<CommentInputProps> = ({@@ -20,8 +30,12 @@ const CommentInput: React.FC<CommentInputProps> = ({buttonLabel = "Reply",autoFocus = false,disabled,+ avatar,+ actions,+ collapsible = false,}) => {const [content, setContent] = useState("");+ const [focused, setFocused] = useState(false);const inputRef = useRef<HTMLTextAreaElement>(null);useEffect(() => {@@ -30,6 +44,8 @@ const CommentInput: React.FC<CommentInputProps> = ({}}, [autoFocus]);+ const expanded = !collapsible || focused || content.length > 0;+const handleSubmit = (e?: React.FormEvent) => {e?.preventDefault();if (content.trim()) {@@ -48,31 +64,50 @@ const CommentInput: React.FC<CommentInputProps> = ({return (<div className="flex items-start space-x-3"><div className="flex-1">- <div className="p-2 rounded-lg border bg-gray-1 border-gray-5">- <textarea- ref={inputRef}- value={content}- disabled={disabled}- onChange={(e) => setContent(e.target.value)}- onKeyDown={handleKeyDown}- placeholder={placeholder || "Leave a comment..."}- className="w-full placeholder:text-gray-8 text-sm leading-[22px] text-gray-12 bg-transparent focus:outline-none"- />- <div className="flex items-center mt-2 space-x-2">- <Button- size="xs"- variant="primary"- onClick={() => handleSubmit()}- disabled={!content}- >- {buttonLabel}- </Button>- {showCancelButton && onCancel && (- <Button size="xs" variant="outline" onClick={onCancel}>- Cancel- </Button>+ <div className="flex items-start gap-2 p-2 rounded-lg border bg-gray-1 border-gray-5 focus-within:border-gray-6">+ {avatar && <div className="shrink-0">{avatar}</div>}+ <div className="flex-1 min-w-0">+ <textarea+ ref={inputRef}+ value={content}+ disabled={disabled}+ rows={expanded ? 2 : 1}+ onChange={(e) => setContent(e.target.value)}+ onKeyDown={handleKeyDown}+ onFocus={() => setFocused(true)}+ onBlur={() => setFocused(false)}+ placeholder={placeholder || "Leave a comment..."}+ className="w-full resize-none placeholder:text-gray-8 text-sm leading-[22px] text-gray-12 bg-transparent focus:outline-none"+ />+ {expanded && (+ <div className="flex items-center mt-2 space-x-2">+ <Button+ size="xs"+ variant="primary"+ onClick={() => handleSubmit()}+ disabled={!content}+ >+ {buttonLabel}+ </Button>+ {showCancelButton && onCancel && (+ <Button size="xs" variant="outline" onClick={onCancel}>+ Cancel+ </Button>+ )}+ </div>)}</div>+ {/* preventDefault on the way down: the field is often focused when+ one of these is pressed, and a blur first would collapse the row+ out from under the click. */}+ {actions && (+ <div+ className="flex shrink-0 items-center gap-0.5"+ onPointerDown={(event) => event.preventDefault()}+ >+ {actions}+ </div>+ )}</div></div></div>diff --git a/apps/web/app/s/[videoId]/_components/tabs/Activity/Comments.tsx b/apps/web/app/s/[videoId]/_components/tabs/Activity/Comments.tsxindex 57e98a4ba..b2f546ac3 100644--- a/apps/web/app/s/[videoId]/_components/tabs/Activity/Comments.tsx+++ b/apps/web/app/s/[videoId]/_components/tabs/Activity/Comments.tsx@@ -1,11 +1,9 @@-import { Button } from "@cap/ui";import { Comment, User, type Video } from "@cap/web-domain";import { faCommentSlash } from "@fortawesome/free-solid-svg-icons";import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";import { useSearchParams } from "next/navigation";import type React from "react";import {- type ComponentProps,forwardRef,type PropsWithChildren,startTransition,@@ -19,8 +17,8 @@ import { deleteComment } from "@/actions/videos/delete-comment";import { newComment } from "@/actions/videos/new-comment";import { useCurrentUser } from "@/app/Layout/AuthContext";import type { CommentType } from "../../../Share";+import { ActivityComposer } from "./ActivityComposer";import CommentComponent from "./Comment";-import CommentInput from "./CommentInput";import EmptyState from "./EmptyState";export const Comments = Object.assign(@@ -35,6 +33,8 @@ export const Comments = Object.assign(onSeek?: (time: number) => void;setShowAuthOverlay: (v: boolean) => void;commentsDisabled: boolean;+ ownerName?: string | null;+ canRecordMedia?: boolean;}>((props, ref) => {const {@@ -97,6 +97,9 @@ export const Comments = Object.assign(type: "text",timestamp: currentTime,updatedAt: new Date(),+ mediaKey: null,+ mediaDuration: null,+ mediaMeta: null,sending: true,};@@ -142,6 +145,9 @@ export const Comments = Object.assign(type: "text",timestamp: currentTime,updatedAt: new Date(),+ mediaKey: null,+ mediaDuration: null,+ mediaMeta: null,sending: true,};@@ -202,6 +208,15 @@ export const Comments = Object.assign(}}setShowAuthOverlay={props.setShowAuthOverlay}commentsContainerRef={commentsContainerRef}+ videoId={props.videoId}+ ownerName={props.ownerName}+ canRecordMedia={props.canRecordMedia}+ onOptimisticComment={(comment) => {+ startTransition(() => {+ setOptimisticComments(comment);+ });+ }}+ onCommentSuccess={handleCommentSuccess}>{commentsDisabled ? (<div className="p-4 space-y-6 h-full">@@ -242,46 +257,44 @@ export const Comments = Object.assign(Shell: (props: PropsWithChildren<{setShowAuthOverlay: (v: boolean) => void;- commentInputProps?: Omit<- ComponentProps<typeof CommentInput>,- "user" | "placholder" | "buttonLabel"- >;+ commentInputProps?: {+ onSubmit?: (content: string) => void;+ disabled?: boolean;+ };commentsContainerRef?: React.RefObject<HTMLDivElement | null>;+ videoId?: Video.VideoId;+ /** Whose video this is, for the composer's placeholder. */+ ownerName?: string | null;+ canRecordMedia?: boolean;+ onOptimisticComment?: (comment: CommentType) => void;+ onCommentSuccess?: (comment: CommentType) => void;}>,- ) => {- const user = useCurrentUser();+ ) => (+ <>+ <div+ ref={props.commentsContainerRef}+ className="overflow-y-auto flex-1 min-h-0"+ >+ {props.children}+ </div>- return (- <>- <div- ref={props.commentsContainerRef}- className="overflow-y-auto flex-1 min-h-0"- >- {props.children}+ {!props.commentInputProps?.disabled && props.videoId && (+ <div className="flex-none p-2 border-t border-gray-5 bg-gray-2">+ <ActivityComposer+ videoId={props.videoId}+ ownerName={props.ownerName}+ onSubmit={(content) =>+ props.commentInputProps?.onSubmit?.(content)+ }+ setShowAuthOverlay={props.setShowAuthOverlay}+ canRecordMedia={props.canRecordMedia}+ onOptimisticComment={props.onOptimisticComment}+ onCommentSuccess={props.onCommentSuccess}+ /></div>-- {!props.commentInputProps?.disabled && (- <div className="flex-none p-2 border-t border-gray-5 bg-gray-2">- {user ? (- <CommentInput- {...props.commentInputProps}- placeholder="Leave a comment"- buttonLabel="Comment"- />- ) : (- <Button- className="min-w-full"- variant="primary"- onClick={() => props.setShowAuthOverlay(true)}- >- Sign in to leave a comment- </Button>- )}- </div>- )}- </>- );- },+ )}+ </>+ ),Skeleton: (props: { setShowAuthOverlay: (v: boolean) => void }) => (<Comments.Shell {...props} commentInputProps={{ disabled: true }} />),diff --git a/apps/web/app/s/[videoId]/_components/tabs/Activity/EmptyState.tsx b/apps/web/app/s/[videoId]/_components/tabs/Activity/EmptyState.tsxindex 4d1b09359..d4a30493f 100644--- a/apps/web/app/s/[videoId]/_components/tabs/Activity/EmptyState.tsx+++ b/apps/web/app/s/[videoId]/_components/tabs/Activity/EmptyState.tsx@@ -1,4 +1,3 @@-import { LoadingSpinner } from "@cap/ui";import type { FontAwesomeIconProps } from "@fortawesome/react-fontawesome";import type { ReactElement } from "react";import React from "react";@@ -11,23 +10,51 @@ const EmptyState = ({icon?: ReactElement<FontAwesomeIconProps>;}) => (<div className="flex flex-col justify-center items-center p-8 h-full text-center animate-in fade-in">- {!commentsDisabled && <LoadingSpinner />}- {icon && (- <div className="mb-4">- {React.cloneElement(icon, { className: "text-gray-12 size-8" })}- </div>- )}+ <div className="mb-4">+ {icon ? (+ React.cloneElement(icon, { className: "text-gray-12 size-8" })+ ) : (+ <CommentGlyph />+ )}+ </div><div className="space-y-1"><h3 className="text-base font-medium text-gray-12">- {commentsDisabled ? "Disabled" : "No comments yet"}+ {commentsDisabled ? "Disabled" : "Be the first to comment"}</h3><p className="text-sm text-gray-10">- {commentsDisabled- ? "Comments are disabled for this video"- : "Be the first to share your thoughts!"}+ {commentsDisabled ? (+ "Comments are disabled for this video"+ ) : (+ <>+ Hit{" "}+ <kbd className="rounded border border-gray-5 bg-gray-2 px-1 font-sans text-[11px] text-gray-11">+ C+ </kbd>{" "}+ or use the box below.+ </>+ )}</p></div></div>);+/** Stands in for the list that isn't there yet. Muted: an empty panel should+ * read as an invitation, not as a state that failed to load. */+const CommentGlyph = () => (+ <svg+ viewBox="0 0 32 32"+ className="size-8 text-gray-8"+ fill="none"+ stroke="currentColor"+ strokeWidth="1.6"+ strokeLinecap="round"+ strokeLinejoin="round"+ aria-hidden+ >+ <title>No comments yet</title>+ <path d="M5 8.5A2.5 2.5 0 0 1 7.5 6h17A2.5 2.5 0 0 1 27 8.5v11a2.5 2.5 0 0 1-2.5 2.5H14l-6 4.5V22H7.5A2.5 2.5 0 0 1 5 19.5v-11Z" />+ <path d="M11 11.5h10M11 16h6" />+ </svg>+);+export default EmptyState;diff --git a/apps/web/app/s/[videoId]/_components/tabs/Activity/index.tsx b/apps/web/app/s/[videoId]/_components/tabs/Activity/index.tsxindex 9e4b3e322..696454853 100644--- a/apps/web/app/s/[videoId]/_components/tabs/Activity/index.tsx+++ b/apps/web/app/s/[videoId]/_components/tabs/Activity/index.tsx@@ -22,6 +22,10 @@ interface ActivityProps {isOwnerOrMember: boolean;isOwner: boolean;commentsDisabled: boolean;+ /** Whose video this is, for the composer's placeholder. */+ ownerName?: string | null;+ /** Owner is on Pro and the viewer is signed in; uploads re-check server-side. */+ canRecordMedia?: boolean;}export const Activity = Object.assign(@@ -37,6 +41,8 @@ export const Activity = Object.assign(setOptimisticComments,setComments,commentsDisabled,+ ownerName,+ canRecordMedia,...props},ref,@@ -67,6 +73,8 @@ export const Activity = Object.assign(setShowAuthOverlay={setShowAuthOverlay}onSeek={props.onSeek}commentsDisabled={commentsDisabled}+ ownerName={ownerName}+ canRecordMedia={canRecordMedia}/>)}</Activity.Shell>