Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(web): add per-video default playback speed to SettingsDialog

Richie McIlroy3b7026842185
diff --git a/apps/web/app/(org)/dashboard/caps/components/SettingsDialog.tsx b/apps/web/app/(org)/dashboard/caps/components/SettingsDialog.tsx
index 2ea87a097..0a68fbcc0 100644
--- a/apps/web/app/(org)/dashboard/caps/components/SettingsDialog.tsx
+++ b/apps/web/app/(org)/dashboard/caps/components/SettingsDialog.tsx
@@ -15,6 +15,7 @@ import clsx from "clsx";
import { useCallback, useEffect, useState } from "react";
import { toast } from "sonner";
import { updateVideoSettings } from "@/actions/videos/settings";
+import { DEFAULT_PLAYBACK_SPEED, PLAYBACK_SPEEDS } from "@/lib/playback-speed";
import { useDashboardContext } from "../../Contexts";
import type { OrganizationSettings } from "../../dashboard-data";
@@ -77,15 +78,14 @@ export const SettingsDialog = ({
const { user, organizationSettings } = useDashboardContext();
const [saveLoading, setSaveLoading] = useState(false);
const buildSettings = useCallback(
- (
- data?: OrganizationSettings,
- ): Partial<Record<ViewerSettingKey, boolean>> => ({
+ (data?: OrganizationSettings): OrganizationSettings => ({
disableComments: data?.disableComments,
disableSummary: data?.disableSummary,
disableCaptions: data?.disableCaptions,
disableChapters: data?.disableChapters,
disableReactions: data?.disableReactions,
disableTranscript: data?.disableTranscript,
+ defaultPlaybackSpeed: data?.defaultPlaybackSpeed,
}),
[],
);
@@ -162,6 +162,14 @@ export const SettingsDialog = ({
return `Required by ${sources.length} spaces`;
};
+ const handleSpeedChange = (speed: number) =>
+ setSettings((prev) => ({ ...prev, defaultPlaybackSpeed: speed }));
+
+ const videoSpeed = settings?.defaultPlaybackSpeed;
+ const orgSpeed = organizationSettings?.defaultPlaybackSpeed;
+ const selectedSpeed = videoSpeed ?? orgSpeed ?? DEFAULT_PLAYBACK_SPEED;
+ const isInheritingSpeed = videoSpeed === undefined;
+
return (
<Dialog open={isOpen} onOpenChange={onClose}>
<DialogContent className="max-w-md min-w-fit">
@@ -218,6 +226,42 @@ export const SettingsDialog = ({
);
})}
</div>
+ <div className="px-5 pb-5">
+ <div className="flex flex-col gap-3 p-4 rounded-xl border border-gray-3 bg-gray-1">
+ <div className="flex flex-col gap-1">
+ <div className="flex gap-1.5 items-center flex-wrap">
+ <p className="text-sm text-gray-12">Default playback speed</p>
+ {isInheritingSpeed && (
+ <p className="py-1 px-1.5 text-[10px] leading-none font-medium rounded-full text-gray-11 bg-gray-5">
+ Org default {orgSpeed ?? DEFAULT_PLAYBACK_SPEED}×
+ </p>
+ )}
+ </div>
+ <p className="text-xs text-gray-10">
+ The speed this cap starts playing at. Viewers can still change
+ it.
+ </p>
+ </div>
+ <div className="flex flex-wrap gap-1 items-center p-1 w-fit rounded-lg border bg-gray-2 border-gray-3">
+ {PLAYBACK_SPEEDS.map((speed) => (
+ <button
+ key={speed}
+ type="button"
+ onClick={() => handleSpeedChange(speed)}
+ aria-pressed={selectedSpeed === speed}
+ className={clsx(
+ "min-w-10 rounded-md px-2 py-1 text-xs font-medium tabular-nums transition-colors",
+ selectedSpeed === speed
+ ? "text-white bg-blue-11"
+ : "text-gray-11 hover:bg-gray-3",
+ )}
+ >
+ {speed}×
+ </button>
+ ))}
+ </div>
+ </div>
+ </div>
<DialogFooter className="p-5 border-t border-gray-4">
<Button
variant="gray"