Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fmt

Richie McIlroyc039a4ab630e
diff --git a/apps/desktop/src/components/titlebar/controls/CaptionControlsWindows11.tsx b/apps/desktop/src/components/titlebar/controls/CaptionControlsWindows11.tsx
index 1025b41d3..8777b0991 100644
--- a/apps/desktop/src/components/titlebar/controls/CaptionControlsWindows11.tsx
+++ b/apps/desktop/src/components/titlebar/controls/CaptionControlsWindows11.tsx
@@ -19,7 +19,7 @@ export default function (
const currentWindow = getCurrentWindow();
const [focused, setFocus] = createSignal(true);
- let unlisten: () => undefined | undefined;
+ let unlisten: (() => void) | undefined;
onMount(async () => {
unlisten = await currentWindow.onFocusChanged(({ payload: focused }) =>
setFocus(focused),
diff --git a/apps/desktop/src/routes/editor/MaskOverlay.tsx b/apps/desktop/src/routes/editor/MaskOverlay.tsx
index 0bb506863..5f2db0e22 100644
--- a/apps/desktop/src/routes/editor/MaskOverlay.tsx
+++ b/apps/desktop/src/routes/editor/MaskOverlay.tsx
@@ -48,6 +48,29 @@ export function MaskOverlay(props: MaskOverlayProps) {
);
};
+ const currentMaskState = maskState();
+ const selected = selectedMask();
+
+ return (
+ <Show when={selected && currentMaskState}>
+ <MaskOverlayContent
+ size={props.size}
+ maskState={currentMaskState as ReturnType<typeof evaluateMask>}
+ updateSegment={updateSegment}
+ projectHistory={projectHistory}
+ />
+ </Show>
+ );
+}
+
+function MaskOverlayContent(props: {
+ size: { width: number; height: number };
+ maskState: ReturnType<typeof evaluateMask>;
+ updateSegment: (fn: (segment: MaskSegment) => void) => void;
+ projectHistory: ReturnType<typeof useEditorContext>["projectHistory"];
+}) {
+ const { projectHistory, updateSegment } = props;
+
function createMouseDownDrag<T>(
setup: () => T,
update: (
@@ -85,116 +108,106 @@ export function MaskOverlay(props: MaskOverlayProps) {
};
}
+ const state = () => props.maskState;
+ const rect = () => {
+ const width = state().size.x * props.size.width;
+ const height = state().size.y * props.size.height;
+ const left = state().position.x * props.size.width - width / 2;
+ const top = state().position.y * props.size.height - height / 2;
+ return { width, height, left, top };
+ };
+
+ const onMove = createMouseDownDrag(
+ () => ({
+ startPos: { ...state().position },
+ }),
+ (e, { startPos }, initialMouse) => {
+ const dx = (e.clientX - initialMouse.x) / props.size.width;
+ const dy = (e.clientY - initialMouse.y) / props.size.height;
+
+ updateSegment((s) => {
+ s.center.x = Math.max(0, Math.min(1, startPos.x + dx));
+ s.center.y = Math.max(0, Math.min(1, startPos.y + dy));
+ });
+ },
+ );
+
+ const createResizeHandler = (dirX: -1 | 0 | 1, dirY: -1 | 0 | 1) => {
+ return createMouseDownDrag(
+ () => ({
+ startPos: { ...state().position },
+ startSize: { ...state().size },
+ }),
+ (e, { startPos, startSize }, initialMouse) => {
+ const dx = (e.clientX - initialMouse.x) / props.size.width;
+ const dy = (e.clientY - initialMouse.y) / props.size.height;
+
+ updateSegment((s) => {
+ if (dirX !== 0) {
+ const newWidth = Math.max(0.01, startSize.x + dx * dirX);
+ s.size.x = newWidth;
+ s.center.x = startPos.x + dx / 2;
+ }
+
+ if (dirY !== 0) {
+ const newHeight = Math.max(0.01, startSize.y + dy * dirY);
+ s.size.y = newHeight;
+ s.center.y = startPos.y + dy / 2;
+ }
+ });
+ },
+ );
+ };
+
return (
- <Show when={selectedMask() && maskState()}>
- {() => {
- const state = () => maskState()!;
- const rect = () => {
- const width = state().size.x * props.size.width;
- const height = state().size.y * props.size.height;
- const left = state().position.x * props.size.width - width / 2;
- const top = state().position.y * props.size.height - height / 2;
- return { width, height, left, top };
- };
-
- const onMove = createMouseDownDrag(
- () => ({
- startPos: { ...state().position },
- }),
- (e, { startPos }, initialMouse) => {
- const dx = (e.clientX - initialMouse.x) / props.size.width;
- const dy = (e.clientY - initialMouse.y) / props.size.height;
-
- updateSegment((s) => {
- s.center.x = Math.max(0, Math.min(1, startPos.x + dx));
- s.center.y = Math.max(0, Math.min(1, startPos.y + dy));
- });
- },
- );
-
- const createResizeHandler = (dirX: -1 | 0 | 1, dirY: -1 | 0 | 1) => {
- return createMouseDownDrag(
- () => ({
- startPos: { ...state().position },
- startSize: { ...state().size },
- }),
- (e, { startPos, startSize }, initialMouse) => {
- const dx = (e.clientX - initialMouse.x) / props.size.width;
- const dy = (e.clientY - initialMouse.y) / props.size.height;
-
- updateSegment((s) => {
- if (dirX !== 0) {
- const newWidth = Math.max(0.01, startSize.x + dx * dirX);
- s.size.x = newWidth;
- s.center.x = startPos.x + dx / 2;
- }
-
- if (dirY !== 0) {
- const newHeight = Math.max(0.01, startSize.y + dy * dirY);
- s.size.y = newHeight;
- s.center.y = startPos.y + dy / 2;
- }
- });
- },
- );
- };
-
- return (
- <div class="absolute inset-0 pointer-events-none">
- <div
- class="absolute pointer-events-auto group"
- style={{
- left: `${rect().left}px`,
- top: `${rect().top}px`,
- width: `${rect().width}px`,
- height: `${rect().height}px`,
- }}
- onMouseDown={onMove}
- >
- {/* Border/Highlight */}
- <div class="absolute inset-0 rounded-md border-2 border-blue-9 bg-blue-9/10 cursor-move" />
-
- {/* Handles */}
- {/* Corners */}
- <ResizeHandle
- class="top-0 left-0 -translate-x-1/2 -translate-y-1/2 cursor-nw-resize"
- onMouseDown={createResizeHandler(-1, -1)}
- />
- <ResizeHandle
- class="top-0 right-0 translate-x-1/2 -translate-y-1/2 cursor-ne-resize"
- onMouseDown={createResizeHandler(1, -1)}
- />
- <ResizeHandle
- class="bottom-0 left-0 -translate-x-1/2 translate-y-1/2 cursor-sw-resize"
- onMouseDown={createResizeHandler(-1, 1)}
- />
- <ResizeHandle
- class="bottom-0 right-0 translate-x-1/2 translate-y-1/2 cursor-se-resize"
- onMouseDown={createResizeHandler(1, 1)}
- />
-
- {/* Sides */}
- <ResizeHandle
- class="top-0 left-1/2 -translate-x-1/2 -translate-y-1/2 cursor-n-resize"
- onMouseDown={createResizeHandler(0, -1)}
- />
- <ResizeHandle
- class="bottom-0 left-1/2 -translate-x-1/2 translate-y-1/2 cursor-s-resize"
- onMouseDown={createResizeHandler(0, 1)}
- />
- <ResizeHandle
- class="left-0 top-1/2 -translate-x-1/2 -translate-y-1/2 cursor-w-resize"
- onMouseDown={createResizeHandler(-1, 0)}
- />
- <ResizeHandle
- class="right-0 top-1/2 translate-x-1/2 -translate-y-1/2 cursor-e-resize"
- onMouseDown={createResizeHandler(1, 0)}
- />
- </div>
- </div>
- );
- }}
- </Show>
+ <div class="absolute inset-0 pointer-events-none">
+ <div
+ class="absolute pointer-events-auto group"
+ style={{
+ left: `${rect().left}px`,
+ top: `${rect().top}px`,
+ width: `${rect().width}px`,
+ height: `${rect().height}px`,
+ }}
+ onMouseDown={onMove}
+ >
+ <div class="absolute inset-0 rounded-md border-2 border-blue-9 bg-blue-9/10 cursor-move" />
+
+ <ResizeHandle
+ class="top-0 left-0 -translate-x-1/2 -translate-y-1/2 cursor-nw-resize"
+ onMouseDown={createResizeHandler(-1, -1)}
+ />
+ <ResizeHandle
+ class="top-0 right-0 translate-x-1/2 -translate-y-1/2 cursor-ne-resize"
+ onMouseDown={createResizeHandler(1, -1)}
+ />
+ <ResizeHandle
+ class="bottom-0 left-0 -translate-x-1/2 translate-y-1/2 cursor-sw-resize"
+ onMouseDown={createResizeHandler(-1, 1)}
+ />
+ <ResizeHandle
+ class="bottom-0 right-0 translate-x-1/2 translate-y-1/2 cursor-se-resize"
+ onMouseDown={createResizeHandler(1, 1)}
+ />
+
+ <ResizeHandle
+ class="top-0 left-1/2 -translate-x-1/2 -translate-y-1/2 cursor-n-resize"
+ onMouseDown={createResizeHandler(0, -1)}
+ />
+ <ResizeHandle
+ class="bottom-0 left-1/2 -translate-x-1/2 translate-y-1/2 cursor-s-resize"
+ onMouseDown={createResizeHandler(0, 1)}
+ />
+ <ResizeHandle
+ class="left-0 top-1/2 -translate-x-1/2 -translate-y-1/2 cursor-w-resize"
+ onMouseDown={createResizeHandler(-1, 0)}
+ />
+ <ResizeHandle
+ class="right-0 top-1/2 translate-x-1/2 -translate-y-1/2 cursor-e-resize"
+ onMouseDown={createResizeHandler(1, 0)}
+ />
+ </div>
+ </div>
);
}
diff --git a/apps/web/app/(org)/dashboard/analytics/components/ChartArea.tsx b/apps/web/app/(org)/dashboard/analytics/components/ChartArea.tsx
index 666461a6e..56c46efb5 100644
--- a/apps/web/app/(org)/dashboard/analytics/components/ChartArea.tsx
+++ b/apps/web/app/(org)/dashboard/analytics/components/ChartArea.tsx
@@ -52,9 +52,9 @@ function ChartArea({ selectedMetrics, data, isLoading }: ChartAreaProps) {
const chartData = useMemo(() => {
if (!data || data.length === 0) return [];
const bucketDuration =
- data.length > 1
- ? new Date(data[1]?.bucket).getTime() -
- new Date(data[0]?.bucket).getTime()
+ data.length > 1 && data[1]?.bucket && data[0]?.bucket
+ ? new Date(data[1].bucket).getTime() -
+ new Date(data[0].bucket).getTime()
: 0;
const hourly = bucketDuration > 0 && bucketDuration <= 60 * 60 * 1000;
return data.map((point) => ({
diff --git a/apps/web/app/(org)/dashboard/folder/[id]/components/ClientMyCapsLink.tsx b/apps/web/app/(org)/dashboard/folder/[id]/components/ClientMyCapsLink.tsx
index fe119dfba..d27a6cb74 100644
--- a/apps/web/app/(org)/dashboard/folder/[id]/components/ClientMyCapsLink.tsx
+++ b/apps/web/app/(org)/dashboard/folder/[id]/components/ClientMyCapsLink.tsx
@@ -4,7 +4,7 @@ import type { Space, Video } from "@cap/web-domain";
import clsx from "clsx";
import Link from "next/link";
import { useRouter } from "next/navigation";
-import { useEffect, useRef, useState } from "react";
+import { useCallback, useEffect, useRef, useState } from "react";
import { toast } from "sonner";
import { moveVideoToFolder } from "@/actions/folders/moveVideoToFolder";
import { SignedImageUrl } from "@/components/SignedImageUrl";
@@ -22,26 +22,71 @@ export function ClientMyCapsLink({
const router = useRouter();
const { activeSpace } = useDashboardContext();
- // Register this component as a drop target for mobile drag and drop
- useEffect(() => {
- if (!linkRef.current) return;
+ const processDrop = useCallback(
+ async (capData: { id: Video.VideoId; name: string }) => {
+ setIsDragOver(false);
- const unregister = registerDropTarget(linkRef.current, (data) => {
- if (data && data.type === "application/cap") {
- handleDrop({ id: data.id, name: data.name });
+ try {
+ if (!capData || !capData.id) {
+ console.error("Invalid cap data");
+ return;
+ }
+
+ setIsMovingVideo(true);
+
+ await moveVideoToFolder({
+ videoId: capData.id,
+ folderId: null,
+ spaceId: spaceId ?? null,
+ });
+ router.refresh();
+ if (activeSpace) {
+ toast.success(`Moved "${capData.name}" to "${activeSpace.name}"`);
+ } else {
+ toast.success(`Moved "${capData.name}" to My Caps`);
+ }
+ } catch (error) {
+ console.error("Error moving video:", error);
+ toast.error("Failed to move video");
+ } finally {
+ setIsMovingVideo(false);
}
- });
+ },
+ [spaceId, router, activeSpace],
+ );
- return () => {
- unregister();
- };
- }, [handleDrop]);
+ const handleDrop = useCallback(
+ async (
+ e:
+ | React.DragEvent<HTMLAnchorElement>
+ | { id: Video.VideoId; name: string },
+ ) => {
+ if ("preventDefault" in e) {
+ e.preventDefault();
+
+ try {
+ const capData = JSON.parse(e.dataTransfer.getData("application/cap"));
+
+ if (!capData || !capData.id) {
+ console.error("Invalid cap data");
+ return;
+ }
+
+ await processDrop(capData);
+ } catch (error) {
+ console.error("Error processing drop:", error);
+ toast.error("Failed to move video");
+ }
+ } else {
+ await processDrop(e);
+ }
+ },
+ [processDrop],
+ );
- // Handle drag events for desktop
const handleDragOver = (e: React.DragEvent<HTMLAnchorElement>) => {
e.preventDefault();
- // Check if the dragged item is a cap
if (e.dataTransfer.types.includes("application/cap")) {
setIsDragOver(true);
}
@@ -51,63 +96,19 @@ export function ClientMyCapsLink({
setIsDragOver(false);
};
- const handleDrop = async (
- e: React.DragEvent<HTMLAnchorElement> | { id: Video.VideoId; name: string },
- ) => {
- if ("preventDefault" in e) {
- e.preventDefault();
-
- try {
- // Get the cap data from the data transfer
- const capData = JSON.parse(e.dataTransfer.getData("application/cap"));
-
- if (!capData || !capData.id) {
- console.error("Invalid cap data");
- return;
- }
-
- await processDrop(capData);
- } catch (error) {
- console.error("Error processing drop:", error);
- toast.error("Failed to move video");
- }
- } else {
- // Handle mobile drop with direct data
- await processDrop(e);
- }
- };
-
- // Common function to process the drop for both desktop and mobile
- const processDrop = async (capData: { id: Video.VideoId; name: string }) => {
- setIsDragOver(false);
+ useEffect(() => {
+ if (!linkRef.current) return;
- try {
- if (!capData || !capData.id) {
- console.error("Invalid cap data");
- return;
+ const unregister = registerDropTarget(linkRef.current, (data) => {
+ if (data && data.type === "application/cap") {
+ handleDrop({ id: data.id, name: data.name });
}
+ });
- setIsMovingVideo(true);
-
- // Move the video to the root folder (null parentId)
- await moveVideoToFolder({
- videoId: capData.id,
- folderId: null,
- spaceId: spaceId ?? null,
- });
- router.refresh();
- if (activeSpace) {
- toast.success(`Moved "${capData.name}" to "${activeSpace.name}"`);
- } else {
- toast.success(`Moved "${capData.name}" to My Caps`);
- }
- } catch (error) {
- console.error("Error moving video:", error);
- toast.error("Failed to move video");
- } finally {
- setIsMovingVideo(false);
- }
- };
+ return () => {
+ unregister();
+ };
+ }, [handleDrop]);
return (
<Link
diff --git a/apps/web/app/(org)/dashboard/settings/organization/components/MembersCard.tsx b/apps/web/app/(org)/dashboard/settings/organization/components/MembersCard.tsx
index 2eff19bce..769eab846 100644
--- a/apps/web/app/(org)/dashboard/settings/organization/components/MembersCard.tsx
+++ b/apps/web/app/(org)/dashboard/settings/organization/components/MembersCard.tsx
@@ -87,11 +87,12 @@ export const MembersCard = ({
const confirmRemoveMember = async () => {
if (!pendingMember) return;
+ if (!activeOrganization?.organization.id) return;
setRemoving(true);
try {
await removeOrganizationMember(
pendingMember.id,
- activeOrganization?.organization.id,
+ activeOrganization.organization.id,
);
toast.success("Member removed successfully");
setConfirmOpen(false);
diff --git a/apps/web/app/(org)/dashboard/settings/organization/components/OrgName.tsx b/apps/web/app/(org)/dashboard/settings/organization/components/OrgName.tsx
index 4fd718fab..1e480ca51 100644
--- a/apps/web/app/(org)/dashboard/settings/organization/components/OrgName.tsx
+++ b/apps/web/app/(org)/dashboard/settings/organization/components/OrgName.tsx
@@ -15,11 +15,11 @@ const OrgName = () => {
const handleOrgNameChange = async () => {
try {
- if (!orgName) return;
+ if (!orgName || !activeOrganization?.organization.id) return;
setSaveLoading(true);
await updateOrganizationDetails({
organizationName: orgName,
- organizationId: activeOrganization?.organization.id,
+ organizationId: activeOrganization.organization.id,
});
toast.success("Settings updated successfully");
router.refresh();
diff --git a/apps/web/components/pages/seo/AgenciesPage.tsx b/apps/web/components/pages/seo/AgenciesPage.tsx
index b9f5e9a41..6edd651e0 100644
--- a/apps/web/components/pages/seo/AgenciesPage.tsx
+++ b/apps/web/components/pages/seo/AgenciesPage.tsx
@@ -528,7 +528,9 @@ export const AgenciesPage = () => {
key={cellIndex.toString()}
className={`px-6 py-4 text-[15px] text-gray-10 ${
rowIndex ===
- agenciesContent.comparisonTable?.rows.length - 1
+ (agenciesContent.comparisonTable?.rows.length ??
+ 0) -
+ 1
? ""
: "border-b border-gray-5"
}`}
diff --git a/apps/web/components/seo/SeoPageTemplate.tsx b/apps/web/components/seo/SeoPageTemplate.tsx
index 5652d01f3..65d6b1036 100644
--- a/apps/web/components/seo/SeoPageTemplate.tsx
+++ b/apps/web/components/seo/SeoPageTemplate.tsx
@@ -400,7 +400,7 @@ export const SeoPageTemplate = ({
key={cellIndex.toString()}
className={`px-6 py-4 text-[15px] text-gray-10 ${
rowIndex ===
- content.comparisonTable?.rows.length - 1
+ (content.comparisonTable?.rows.length ?? 0) - 1
? ""
: "border-b border-gray-5"
}`}
diff --git a/apps/web/components/tools/TrimmingTool.tsx b/apps/web/components/tools/TrimmingTool.tsx
index 0451b19c0..3dafc4814 100644
--- a/apps/web/components/tools/TrimmingTool.tsx
+++ b/apps/web/components/tools/TrimmingTool.tsx
@@ -193,7 +193,7 @@ export const TrimmingTool = () => {
if (videoPreviewRef.current) {
setVideoState((prev) => ({
...prev,
- currentTime: videoPreviewRef.current?.currentTime,
+ currentTime: videoPreviewRef.current?.currentTime ?? 0,
}));
}
};
@@ -657,7 +657,7 @@ export const TrimmingTool = () => {
if (newEndTime > trimState.startTime && videoState.info) {
setTrimState((prev) => ({
...prev,
- endTime: Math.min(newEndTime, videoState.info?.duration),
+ endTime: Math.min(newEndTime, videoState.info?.duration ?? 0),
}));
}
};
@@ -676,9 +676,10 @@ export const TrimmingTool = () => {
const setCurrentPositionAsStart = () => {
if (videoPreviewRef.current && videoState.currentTime < trimState.endTime) {
+ const currentTime = videoPreviewRef.current.currentTime ?? 0;
setTrimState((prev) => ({
...prev,
- startTime: videoPreviewRef.current?.currentTime,
+ startTime: currentTime,
}));
}
};
@@ -688,9 +689,10 @@ export const TrimmingTool = () => {
videoPreviewRef.current &&
videoState.currentTime > trimState.startTime
) {
+ const currentTime = videoPreviewRef.current.currentTime ?? 0;
setTrimState((prev) => ({
...prev,
- endTime: videoPreviewRef.current?.currentTime,
+ endTime: currentTime,
}));
}
};
diff --git a/apps/web/utils/changelog.ts b/apps/web/utils/changelog.ts
index d6304914f..46aa3c1f3 100644
--- a/apps/web/utils/changelog.ts
+++ b/apps/web/utils/changelog.ts
@@ -17,6 +17,8 @@ function parseFrontmatter(fileContent: string) {
const frontMatterLines = frontMatterBlock?.trim().split("\n");
const metadata: Partial<ChangelogMetadata> = {};
+ if (!frontMatterLines) return { metadata, content };
+
frontMatterLines.forEach((line) => {
const [key, ...valueArr] = line.split(": ");
if (!key) return;
diff --git a/crates/recording/src/output_pipeline/async_camera.rs b/crates/recording/src/output_pipeline/async_camera.rs
index dca0c510a..fd458eeec 100644
--- a/crates/recording/src/output_pipeline/async_camera.rs
+++ b/crates/recording/src/output_pipeline/async_camera.rs
@@ -250,19 +250,20 @@ impl VideoMuxer for AsyncCameraMp4Muxer {
}
let backlog = self.frames_submitted.saturating_sub(self.frames_encoded);
- if encoded_this_call == 0 && backlog > 10 {
- if let Some(converted) = pool.recv_timeout(Duration::from_millis(5)) {
- let pts = converted.frame.pts().unwrap_or(0);
- if self.last_pts.is_none_or(|last| pts > last) {
- let frame_timestamp = Duration::from_micros(pts as u64);
- encoder.queue_preconverted_frame(
- converted.frame,
- frame_timestamp,
- &mut self.output,
- )?;
- self.last_pts = Some(pts);
- self.frames_encoded += 1;
- }
+ if encoded_this_call == 0
+ && backlog > 10
+ && let Some(converted) = pool.recv_timeout(Duration::from_millis(5))
+ {
+ let pts = converted.frame.pts().unwrap_or(0);
+ if self.last_pts.is_none_or(|last| pts > last) {
+ let frame_timestamp = Duration::from_micros(pts as u64);
+ encoder.queue_preconverted_frame(
+ converted.frame,
+ frame_timestamp,
+ &mut self.output,
+ )?;
+ self.last_pts = Some(pts);
+ self.frames_encoded += 1;
}
}
diff --git a/packages/database/auth/auth-options.ts b/packages/database/auth/auth-options.ts
index 2d78b247e..6ed147e26 100644
--- a/packages/database/auth/auth-options.ts
+++ b/packages/database/auth/auth-options.ts
@@ -152,11 +152,11 @@ export const authOptions = (): NextAuthOptions => {
async session({ token, session }) {
if (!session.user) return session;
- if (token) {
+ if (token && token.id) {
session.user.id = token.id;
- session.user.name = token.name;
- session.user.email = token.email;
- session.user.image = token.picture;
+ session.user.name = token.name ?? null;
+ session.user.email = token.email ?? null;
+ session.user.image = token.picture ?? null;
}
return session;