Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(web): restore private screenshot viewing and share dialog layout

Richie McIlroy56da066f8bbd
diff --git a/apps/web/__tests__/unit/share-page-loading.test.ts b/apps/web/__tests__/unit/share-page-loading.test.ts
index 551285e11..ecae39305 100644
--- a/apps/web/__tests__/unit/share-page-loading.test.ts
+++ b/apps/web/__tests__/unit/share-page-loading.test.ts
@@ -5,9 +5,11 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
const mocks = vi.hoisted(() => ({
select: vi.fn(),
policy: vi.fn(),
+ thumbnailUrl: vi.fn(),
playbackUrl: vi.fn(),
quota: vi.fn(),
user: vi.fn(),
+ authenticated: false,
sharedOrganizations: [] as {
id: string;
name: string;
@@ -27,7 +29,12 @@ vi.mock("@cap/web-backend", () => ({
Database: Context.GenericTag("ShareTestDatabase"),
ImageUploads: Context.GenericTag("ShareTestImages"),
Videos: Context.GenericTag("ShareTestVideos"),
- provideOptionalAuth: <A, E, R>(effect: Effect.Effect<A, E, R>) => effect,
+ provideOptionalAuth: <A, E, R>(effect: Effect.Effect<A, E, R>) =>
+ mocks.authenticated
+ ? Effect.provideService(Context.GenericTag("CurrentUser"), {
+ id: "owner",
+ })(effect)
+ : effect,
resolveEffectiveVideoRules: () => ({
settings: {},
hasInheritedPassword: false,
@@ -51,8 +58,7 @@ vi.mock("@/lib/server", () => ({
resolveImageUrl: (url: string) => Effect.succeed(url),
}),
Effect.provideService(Context.GenericTag("ShareTestVideos"), {
- getThumbnailURL: () =>
- Effect.succeed(Option.some("https://media.example.com/image.jpg")),
+ getThumbnailURL: mocks.thumbnailUrl,
}),
Effect.runPromise,
),
@@ -154,6 +160,7 @@ async function renderAuthorizedContent() {
)) as ReactElement<{
children: ReactElement<{
initialPlaybackUrl?: Promise<string | null>;
+ screenshotImageUrl?: string | null;
data: { sharedOrganizations: unknown[]; ownerIsOverShareLimit: boolean };
}>;
}>;
@@ -162,9 +169,13 @@ async function renderAuthorizedContent() {
describe("share page loading", () => {
beforeEach(() => {
mocks.policy.mockReturnValue(Effect.void);
+ mocks.thumbnailUrl.mockReturnValue(
+ Effect.succeed(Option.some("https://media.example.com/image.jpg")),
+ );
mocks.playbackUrl.mockResolvedValue("https://media.example.com/result.mp4");
mocks.quota.mockResolvedValue(false);
mocks.user.mockResolvedValue(null);
+ mocks.authenticated = false;
mocks.sharedOrganizations = [];
arrangeRows([createVideo()]);
});
@@ -274,4 +285,23 @@ describe("share page loading", () => {
expect(content.props.children.props.initialPlaybackUrl).toBeUndefined();
expect(mocks.playbackUrl).not.toHaveBeenCalled();
});
+
+ it("keeps the owner's auth context when loading a private screenshot", async () => {
+ mocks.authenticated = true;
+ arrangeRows([{ ...createVideo(), public: false, isScreenshot: true }]);
+ mocks.thumbnailUrl.mockImplementation(() =>
+ Effect.flatMap(Effect.context<never>(), (context) =>
+ Option.isSome(
+ Context.getOption(context, Context.GenericTag("CurrentUser")),
+ )
+ ? Effect.succeed(Option.some("https://media.example.com/image.jpg"))
+ : Effect.fail({ _tag: "PolicyDenied" }),
+ ),
+ );
+
+ const content = await renderAuthorizedContent();
+ expect(content.props.children.props.screenshotImageUrl).toBe(
+ "https://media.example.com/image.jpg",
+ );
+ });
});
diff --git a/apps/web/app/(org)/dashboard/caps/components/SharingDialog.tsx b/apps/web/app/(org)/dashboard/caps/components/SharingDialog.tsx
index cae466172..163b39641 100644
--- a/apps/web/app/(org)/dashboard/caps/components/SharingDialog.tsx
+++ b/apps/web/app/(org)/dashboard/caps/components/SharingDialog.tsx
@@ -449,23 +449,27 @@ export const SharingDialog: React.FC<SharingDialogProps> = ({
</div>
<div className="p-3 mb-4 rounded-lg border bg-gray-1 border-gray-4">
- <div className="flex items-center justify-between gap-2 mb-2">
- <div>
- <p className="text-sm font-medium text-gray-12">
- People with access
- </p>
- <p className="text-xs text-gray-10">
- Invite someone by email. They can view with a Cap account
- using that address.
- </p>
- </div>
- <Button size="xs" variant="gray" onClick={copyShareUrl}>
+ <div className="flex items-center justify-between gap-2">
+ <p className="text-sm font-medium text-gray-12">
+ People with access
+ </p>
+ <Button
+ size="xs"
+ variant="gray"
+ className="shrink-0 whitespace-nowrap"
+ onClick={copyShareUrl}
+ >
<FontAwesomeIcon icon={faCopy} className="size-3 mr-1" />
Copy link
</Button>
</div>
+ <p className="mt-1 mb-2 text-xs text-gray-10">
+ Invite someone by email. They can view with a Cap account
+ using that address.
+ </p>
<div className="flex gap-2">
<Input
+ className="min-w-0 flex-1"
type="email"
placeholder="[email protected]"
value={viewerEmail}
@@ -474,6 +478,7 @@ export const SharingDialog: React.FC<SharingDialogProps> = ({
<Button
size="sm"
variant="dark"
+ className="shrink-0"
spinner={inviteViewer.isPending}
disabled={
inviteViewer.isPending ||
diff --git a/apps/web/app/s/[videoId]/page.tsx b/apps/web/app/s/[videoId]/page.tsx
index 886978f8d..0b1d2685d 100644
--- a/apps/web/app/s/[videoId]/page.tsx
+++ b/apps/web/app/s/[videoId]/page.tsx
@@ -579,6 +579,7 @@ async function AuthorizedContent({
const screenshotImageUrlPromise = video.isScreenshot
? Effect.flatMap(Videos, (videos) => videos.getThumbnailURL(videoId)).pipe(
Effect.map(Option.getOrNull),
+ provideOptionalAuth,
runPromise,
)
: Promise.resolve(null);