Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Show pending recording & remove recordingStopped param

Richie McIlroy96e163524a63
diff --git a/apps/web/app/s/[videoId]/Share.tsx b/apps/web/app/s/[videoId]/Share.tsx
index 11bd42909..4e99bc2c5 100644
--- a/apps/web/app/s/[videoId]/Share.tsx
+++ b/apps/web/app/s/[videoId]/Share.tsx
@@ -358,6 +358,18 @@ export const Share = ({
const searchParams = useSearchParams();
const initialSeekDone = useRef(false);
+ useEffect(() => {
+ if (!searchParams.has("recordingStopped")) return;
+
+ const url = new URL(window.location.href);
+ url.searchParams.delete("recordingStopped");
+ window.history.replaceState(
+ window.history.state,
+ "",
+ `${url.pathname}${url.search}${url.hash}`,
+ );
+ }, [searchParams]);
+
const handleSeek = useCallback((time: number) => {
const v =
playerRef.current ??
diff --git a/apps/web/app/s/[videoId]/_components/PendingRecordingShare.tsx b/apps/web/app/s/[videoId]/_components/PendingRecordingShare.tsx
new file mode 100644
index 000000000..b8b61ec9f
--- /dev/null
+++ b/apps/web/app/s/[videoId]/_components/PendingRecordingShare.tsx
@@ -0,0 +1,46 @@
+"use client";
+
+import { LogoSpinner } from "@cap/ui";
+import { useRouter } from "next/navigation";
+import { useEffect, useState } from "react";
+
+const MAX_REFRESH_ATTEMPTS = 30;
+const REFRESH_INTERVAL_MS = 2000;
+
+export function PendingRecordingShare() {
+ const router = useRouter();
+ const [hasTimedOut, setHasTimedOut] = useState(false);
+
+ useEffect(() => {
+ let refreshCount = 0;
+ router.refresh();
+
+ const interval = window.setInterval(() => {
+ refreshCount += 1;
+
+ if (refreshCount >= MAX_REFRESH_ATTEMPTS) {
+ setHasTimedOut(true);
+ window.clearInterval(interval);
+ return;
+ }
+
+ router.refresh();
+ }, REFRESH_INTERVAL_MS);
+
+ return () => window.clearInterval(interval);
+ }, [router]);
+
+ return (
+ <div className="flex flex-col justify-center items-center p-4 min-h-screen text-center bg-gray-2">
+ <LogoSpinner className="mb-6 w-10 h-auto animate-spin" />
+ <h1 className="mb-2 text-2xl font-semibold text-gray-12">
+ Preparing your recording
+ </h1>
+ <p className="max-w-md text-gray-10">
+ {hasTimedOut
+ ? "This recording is taking longer than expected. Reload this page in a moment."
+ : "Your recording is being made available. This page will update automatically."}
+ </p>
+ </div>
+ );
+}
diff --git a/apps/web/app/s/[videoId]/page.tsx b/apps/web/app/s/[videoId]/page.tsx
index 54f88b547..687a4e0c6 100644
--- a/apps/web/app/s/[videoId]/page.tsx
+++ b/apps/web/app/s/[videoId]/page.tsx
@@ -1,5 +1,6 @@
import { db } from "@cap/database";
import { getCurrentUser } from "@cap/database/auth/session";
+import { nanoIdLength } from "@cap/database/helpers";
import {
comments,
organizationMembers,
@@ -60,11 +61,28 @@ import {
import { optionFromTOrFirst } from "@/utils/effect";
import { isAiGenerationEnabled } from "@/utils/flags";
import { PasswordOverlay } from "./_components/PasswordOverlay";
+import { PendingRecordingShare } from "./_components/PendingRecordingShare";
import { ShareHeader } from "./_components/ShareHeader";
import { Share } from "./Share";
import type { SharePageBranding } from "./types";
const VIEW_NOTIFICATION_DELAY_MS = 2 * 60 * 1000;
+const VIDEO_ID_PATTERN = /^[0-9abcdefghjkmnpqrstvwxyz]+$/;
+
+type ShareVideoSearchParams = {
+ [key: string]: string | string[] | undefined;
+};
+
+const isValidVideoIdParam = (videoId: string) =>
+ videoId.length === nanoIdLength && VIDEO_ID_PATTERN.test(videoId);
+
+const hasRecordingStoppedParam = (searchParams: ShareVideoSearchParams) => {
+ const recordingStoppedParam = Array.isArray(searchParams.recordingStopped)
+ ? searchParams.recordingStopped[0]
+ : searchParams.recordingStopped;
+
+ return recordingStoppedParam === "1" || recordingStoppedParam === "true";
+};
// Helper function to fetch shared spaces data for a video
async function getSharedSpacesForVideo(videoId: Video.VideoId) {
@@ -167,7 +185,10 @@ function PolicyDeniedView({ reason }: { reason?: string }) {
const renderPolicyDenied = (videoId: Video.VideoId, reason?: string) =>
Effect.succeed(<PolicyDeniedView key={videoId} reason={reason} />);
-const renderNoSuchElement = () => Effect.sync(() => notFound());
+const renderNoSuchElement = (awaitRecording: boolean) =>
+ awaitRecording
+ ? Effect.succeed(<PendingRecordingShare />)
+ : Effect.sync(() => notFound());
function getSharePageBranding(data: {
owner: { isPro: boolean };
@@ -199,17 +220,23 @@ function getSharePageBranding(data: {
return { type: "cap" };
}
-const getShareVideoPageCatchers = (videoId: Video.VideoId) => ({
+const getShareVideoPageCatchers = (
+ videoId: Video.VideoId,
+ awaitRecording: boolean,
+) => ({
PolicyDenied: (e: Policy.PolicyDeniedError) =>
renderPolicyDenied(videoId, e.reason),
- NoSuchElementException: renderNoSuchElement,
+ NoSuchElementException: () => renderNoSuchElement(awaitRecording),
});
export async function generateMetadata(
props: PageProps<"/s/[videoId]">,
): Promise<Metadata> {
const params = await props.params;
+ const searchParams = await props.searchParams;
const videoId = params.videoId as Video.VideoId;
+ const awaitRecording =
+ isValidVideoIdParam(videoId) && hasRecordingStoppedParam(searchParams);
const headersList = await headers();
const referrer =
@@ -224,7 +251,14 @@ export async function generateMetadata(
return Effect.flatMap(Videos, (v) => v.getByIdForViewing(videoId)).pipe(
Effect.map(
Option.match({
- onNone: () => notFound(),
+ onNone: () =>
+ awaitRecording
+ ? {
+ title: "Cap: Preparing Video",
+ description: "This recording is being made available.",
+ robots: "noindex, nofollow",
+ }
+ : notFound(),
onSome: ([video]) => {
const previewImageUrl = new URL(
`/api/video/preview?videoId=${videoId}&fallback=og`,
@@ -368,6 +402,8 @@ export default async function ShareVideoPage(props: PageProps<"/s/[videoId]">) {
const params = await props.params;
const searchParams = await props.searchParams;
const videoId = params.videoId as Video.VideoId;
+ const awaitRecording =
+ isValidVideoIdParam(videoId) && hasRecordingStoppedParam(searchParams);
await reconcileStaleEditUpload(videoId);
@@ -441,7 +477,7 @@ export default async function ShareVideoPage(props: PageProps<"/s/[videoId]">) {
)}
</div>
)),
- Effect.catchTags(getShareVideoPageCatchers(videoId)),
+ Effect.catchTags(getShareVideoPageCatchers(videoId, awaitRecording)),
provideOptionalAuth,
EffectRuntime.runPromise,
);
@@ -466,7 +502,7 @@ async function AuthorizedContent({
organizationIconUrl?: ImageUpload.ImageUrlOrKey | null;
shareableLinkIconUrl?: ImageUpload.ImageUrlOrKey | null;
};
- searchParams: { [key: string]: string | string[] | undefined };
+ searchParams: ShareVideoSearchParams;
}) {
// will have already been fetched if auth is required
const user = await getCurrentUser();
@@ -494,11 +530,7 @@ async function AuthorizedContent({
const replyId = optionFromTOrFirst(searchParams.reply).pipe(
Option.map(Comment.CommentId.make),
);
- const recordingStoppedParam = Array.isArray(searchParams.recordingStopped)
- ? searchParams.recordingStopped[0]
- : searchParams.recordingStopped;
- const recordingStopped =
- recordingStoppedParam === "1" || recordingStoppedParam === "true";
+ const recordingStopped = hasRecordingStoppedParam(searchParams);
// Fetch spaces data for the sharing dialog
let spacesData = null;