Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
feat(web): reflect inherited viewer rules on space shared caps
Richie McIlroy1d8048fb31a9
diff --git a/apps/web/app/(org)/dashboard/spaces/[spaceId]/SharedCaps.tsx b/apps/web/app/(org)/dashboard/spaces/[spaceId]/SharedCaps.tsxindex b662460a9..1c0c6fc9e 100644--- a/apps/web/app/(org)/dashboard/spaces/[spaceId]/SharedCaps.tsx+++ b/apps/web/app/(org)/dashboard/spaces/[spaceId]/SharedCaps.tsx@@ -2,12 +2,24 @@import type { VideoMetadata } from "@cap/database/types";import { Button } from "@cap/ui";-import type { Organisation, Space, User, Video } from "@cap/web-domain";-import { faFolderPlus, faInfoCircle } from "@fortawesome/free-solid-svg-icons";+import type { SpaceRuleSource, ViewerSettingKey } from "@cap/web-backend";+import type {+ ImageUpload,+ Organisation,+ Space,+ User,+ Video,+} from "@cap/web-domain";+import {+ faFolderPlus,+ faGear,+ faInfoCircle,+} from "@fortawesome/free-solid-svg-icons";import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";import { useRouter, useSearchParams } from "next/navigation";import { useState } from "react";import { useVideosAnalyticsQuery } from "@/lib/Queries/Analytics";+import SpaceDialog from "../../_components/Navbar/SpaceDialog";import { useDashboardContext } from "../../Contexts";import { CapPagination } from "../../caps/components/CapPagination";import Folder, { type FolderDataType } from "../../caps/components/Folder";@@ -28,11 +40,26 @@ type SharedVideoData = {ownerId: string;name: string;createdAt: Date;+ public?: boolean;totalComments: number;totalReactions: number;ownerName: string | null;metadata?: VideoMetadata;+ hasPassword?: boolean;+ hasInheritedPassword?: boolean;+ inheritedPasswordSources?: SpaceRuleSource[];+ inheritedSpaceSettings?: Partial<Record<ViewerSettingKey, SpaceRuleSource[]>>;+ sharedSpaces?: {+ id: string;+ name: string;+ isOrg: boolean;+ organizationId: string;+ iconUrl?: ImageUpload.ImageUrl | null;+ settings?: Partial<Record<ViewerSettingKey, boolean>> | null;+ hasPassword?: boolean;+ }[];hasActiveUpload: boolean | undefined;+ settings?: Partial<Record<ViewerSettingKey, boolean>> | null;}[];type SpaceData = {@@ -40,6 +67,9 @@ type SpaceData = {name: string;organizationId: Organisation.OrganisationId;createdById: User.UserId;+ iconUrl?: ImageUpload.ImageUrl | null;+ settings?: Partial<Record<ViewerSettingKey, boolean>> | null;+ hasPassword?: boolean;};export const SharedCaps = ({@@ -82,6 +112,7 @@ export const SharedCaps = ({isDragging: false,});const [isAddVideosDialogOpen, setIsAddVideosDialogOpen] = useState(false);+ const [isSpaceSettingsOpen, setIsSpaceSettingsOpen] = useState(false);const [isAddOrganizationVideosDialogOpen,setIsAddOrganizationVideosDialogOpen,@@ -105,18 +136,51 @@ export const SharedCaps = ({router.refresh();};+ const spaceSettingsDialog = spaceData ? (+ <SpaceDialog+ edit+ open={isSpaceSettingsOpen}+ onClose={() => setIsSpaceSettingsOpen(false)}+ onSpaceUpdated={() => {+ router.refresh();+ setIsSpaceSettingsOpen(false);+ }}+ space={{+ id: spaceData.id,+ name: spaceData.name,+ members: spaceMembers?.map((member) => member.userId) ?? [],+ iconUrl: spaceData.iconUrl ?? undefined,+ settings: spaceData.settings ?? null,+ hasPassword: spaceData.hasPassword,+ }}+ />+ ) : null;+if (data.length === 0 && folders?.length === 0) {return (<div className="flex relative flex-col w-full h-full">+ {spaceSettingsDialog}{spaceData && spaceMembers && (- <MembersIndicator- memberCount={spaceMemberCount}- members={spaceMembers}- organizationMembers={organizationMembers || []}- spaceId={spaceData.id}- canManageMembers={isSpaceOwner}- onAddVideos={() => setIsAddVideosDialogOpen(true)}- />+ <div className="flex flex-wrap gap-3">+ <MembersIndicator+ memberCount={spaceMemberCount}+ members={spaceMembers}+ organizationMembers={organizationMembers || []}+ spaceId={spaceData.id}+ canManageMembers={isSpaceOwner}+ onAddVideos={() => setIsAddVideosDialogOpen(true)}+ />+ {isSpaceOwner && (+ <Button+ variant="gray"+ size="sm"+ onClick={() => setIsSpaceSettingsOpen(true)}+ >+ <FontAwesomeIcon className="size-3" icon={faGear} />+ Space settings+ </Button>+ )}+ </div>)}{organizationData && organizationMembers && !spaceData && (<OrganizationIndicator@@ -163,6 +227,7 @@ export const SharedCaps = ({return (<div className="flex relative flex-col w-full h-full">+ {spaceSettingsDialog}{isDraggingCap.isDragging && (<div className="fixed inset-0 z-50 pointer-events-none"><div className="flex justify-center items-center w-full h-full">@@ -187,14 +252,26 @@ export const SharedCaps = ({/><div className="flex flex-wrap gap-3 mb-10">{spaceData && spaceMembers && (- <MembersIndicator- memberCount={spaceMemberCount}- members={spaceMembers}- organizationMembers={organizationMembers || []}- spaceId={spaceData.id}- canManageMembers={isSpaceOwner}- onAddVideos={() => setIsAddVideosDialogOpen(true)}- />+ <>+ <MembersIndicator+ memberCount={spaceMemberCount}+ members={spaceMembers}+ organizationMembers={organizationMembers || []}+ spaceId={spaceData.id}+ canManageMembers={isSpaceOwner}+ onAddVideos={() => setIsAddVideosDialogOpen(true)}+ />+ {isSpaceOwner && (+ <Button+ variant="gray"+ size="sm"+ onClick={() => setIsSpaceSettingsOpen(true)}+ >+ <FontAwesomeIcon className="size-3" icon={faGear} />+ Space settings+ </Button>+ )}+ </>)}{organizationData && organizationMembers && !spaceData && (<OrganizationIndicatordiff --git a/apps/web/app/(org)/dashboard/spaces/[spaceId]/components/SharedCapCard.tsx b/apps/web/app/(org)/dashboard/spaces/[spaceId]/components/SharedCapCard.tsxindex 5bfbcaf61..6cd4d1ce9 100644--- a/apps/web/app/(org)/dashboard/spaces/[spaceId]/components/SharedCapCard.tsx+++ b/apps/web/app/(org)/dashboard/spaces/[spaceId]/components/SharedCapCard.tsx@@ -1,7 +1,8 @@"use client";import type { VideoMetadata } from "@cap/database/types";-import type { Video } from "@cap/web-domain";+import type { SpaceRuleSource, ViewerSettingKey } from "@cap/web-backend";+import type { ImageUpload, Video } from "@cap/web-domain";import { faBuilding, faUser } from "@fortawesome/free-solid-svg-icons";import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";import { CapCard } from "../../../caps/components/CapCard/CapCard";@@ -12,11 +13,28 @@ interface SharedCapCardProps {ownerId: string;name: string;createdAt: Date;+ public?: boolean;totalComments: number;totalReactions: number;ownerName: string | null;metadata?: VideoMetadata;+ hasPassword?: boolean;+ hasInheritedPassword?: boolean;+ inheritedPasswordSources?: SpaceRuleSource[];+ inheritedSpaceSettings?: Partial<+ Record<ViewerSettingKey, SpaceRuleSource[]>+ >;+ sharedSpaces?: {+ id: string;+ name: string;+ isOrg: boolean;+ organizationId: string;+ iconUrl?: ImageUpload.ImageUrl | null;+ settings?: Partial<Record<ViewerSettingKey, boolean>> | null;+ hasPassword?: boolean;+ }[];hasActiveUpload: boolean | undefined;+ settings?: Partial<Record<ViewerSettingKey, boolean>> | null;};analytics: number;isLoadingAnalytics: boolean;@@ -46,7 +64,7 @@ export const SharedCapCard: React.FC<SharedCapCardProps> = ({const isOwner = userId === cap.ownerId;return (- <div onDragStart={onDragStart} onDragEnd={onDragEnd}>+ <li className="list-none" onDragStart={onDragStart} onDragEnd={onDragEnd}><CapCardhideSharedStatus={hideSharedStatus}isLoadingAnalytics={isLoadingAnalytics}@@ -77,6 +95,6 @@ export const SharedCapCard: React.FC<SharedCapCardProps> = ({)}</div></CapCard>- </div>+ </li>);};diff --git a/apps/web/app/(org)/dashboard/spaces/[spaceId]/page.tsx b/apps/web/app/(org)/dashboard/spaces/[spaceId]/page.tsxindex a6bb80a84..e4d1727d3 100644--- a/apps/web/app/(org)/dashboard/spaces/[spaceId]/page.tsx+++ b/apps/web/app/(org)/dashboard/spaces/[spaceId]/page.tsx@@ -7,6 +7,7 @@ import {organizations,sharedVideos,spaceMembers,+ spaces,spaceVideos,users,videos,@@ -17,6 +18,7 @@ import {Database,ImageUploads,makeCurrentUserLayer,+ resolveEffectiveVideoRules,Spaces,} from "@cap/web-backend";import {@@ -25,7 +27,7 @@ import {Space,Video,} from "@cap/web-domain";-import { and, count, desc, eq, isNull, sql } from "drizzle-orm";+import { and, count, desc, eq, inArray, isNull, sql } from "drizzle-orm";import { Effect } from "effect";import type { Metadata } from "next";import { notFound } from "next/navigation";@@ -142,6 +144,52 @@ const fetchOrganizationMembers = Effect.fn(function* ();});+async function fetchSharedSpacesForVideos(videoIds: Video.VideoId[]) {+ if (videoIds.length === 0) return {};++ const rows = await db()+ .select({+ videoId: spaceVideos.videoId,+ id: spaces.id,+ name: spaces.name,+ organizationId: spaces.organizationId,+ iconUrl: spaces.iconUrl,+ settings: spaces.settings,+ hasPassword: sql`${spaces.password} IS NOT NULL`.mapWith(Boolean),+ })+ .from(spaceVideos)+ .innerJoin(spaces, eq(spaceVideos.spaceId, spaces.id))+ .where(inArray(spaceVideos.videoId, videoIds));++ const resolvedRows = await Effect.gen(function* () {+ const imageUploads = yield* ImageUploads;++ return yield* Effect.all(+ rows.map(+ Effect.fn(function* (row) {+ return {+ ...row,+ isOrg: false as const,+ iconUrl: row.iconUrl+ ? yield* imageUploads.resolveImageUrl(row.iconUrl)+ : null,+ };+ }),+ ),+ );+ }).pipe(runPromise);++ return resolvedRows.reduce<+ Record<string, Omit<(typeof resolvedRows)[number], "videoId">[]>+ >((acc, row) => {+ const spaces = acc[row.videoId] ?? [];+ acc[row.videoId] = spaces;+ const { videoId: _videoId, ...space } = row;+ spaces.push(space);+ return acc;+ }, {});+}+export default async function SharedCapsPage(props: {params: Promise<{ spaceId: string }>;searchParams: Promise<{ [key: string]: string | string[] | undefined }>;@@ -173,6 +221,15 @@ export default async function SharedCapsPage(props: {fetchOrganizationMembers(space.organizationId).pipe(runPromise),fetchFolders(space.id, false),]);+ const resolvedSpace = await Effect.gen(function* () {+ const imageUploads = yield* ImageUploads;+ return {+ ...space,+ iconUrl: space.iconUrl+ ? yield* imageUploads.resolveImageUrl(space.iconUrl)+ : null,+ };+ }).pipe(runPromise);async function fetchSpaceVideos(spaceId: Space.SpaceIdOrOrganisationId,@@ -189,6 +246,9 @@ export default async function SharedCapsPage(props: {createdAt: videos.createdAt,metadata: videos.metadata,duration: videos.duration,+ public: videos.public,+ settings: videos.settings,+ hasPassword: sql`${videos.password} IS NOT NULL`.mapWith(Boolean),totalComments: sql<number>`COUNT(DISTINCT CASE WHEN ${comments.type} = 'text' THEN ${comments.id} END)`,totalReactions: sql<number>`COUNT(DISTINCT CASE WHEN ${comments.type} = 'emoji' THEN ${comments.id} END)`,ownerName: users.name,@@ -216,6 +276,10 @@ export default async function SharedCapsPage(props: {videos.name,videos.createdAt,videos.metadata,+ videos.duration,+ videos.public,+ videos.settings,+ videos.password,users.name,).orderBy(desc(videos.effectiveCreatedAt))@@ -240,14 +304,28 @@ export default async function SharedCapsPage(props: {page,limit,);+ const sharedSpacesMap = await fetchSharedSpacesForVideos(+ spaceVideoData.map((video) => Video.VideoId.make(video.id)),+ );const processedVideoData = spaceVideoData.map((video) => {- const { effectiveDate, ...videoWithoutEffectiveDate } = video;+ const { effectiveDate: _effectiveDate, ...videoWithoutEffectiveDate } =+ video;+ const sharedSpaces = sharedSpacesMap[video.id] ?? [];+ const rules = resolveEffectiveVideoRules({+ videoSettings: video.settings,+ organizationSettings: null,+ spaces: sharedSpaces,+ });return {...videoWithoutEffectiveDate,id: Video.VideoId.make(video.id),+ hasInheritedPassword: rules.hasInheritedPassword,+ inheritedPasswordSources: rules.inheritedPasswordSources,+ inheritedSpaceSettings: rules.inheritedSettings,+ sharedSpaces,ownerName: video.ownerName ?? null,metadata: video.metadata as- | { customCreatedAt?: string; [key: string]: any }+ | { customCreatedAt?: string; [key: string]: unknown }| undefined,};});@@ -256,7 +334,7 @@ export default async function SharedCapsPage(props: {<SharedCapsdata={processedVideoData}count={totalCount}- spaceData={space}+ spaceData={resolvedSpace}spaceId={params.spaceId as Space.SpaceIdOrOrganisationId}analyticsEnabled={Boolean(serverEnv().TINYBIRD_TOKEN && serverEnv().TINYBIRD_HOST,@@ -287,6 +365,9 @@ export default async function SharedCapsPage(props: {createdAt: videos.createdAt,metadata: videos.metadata,duration: videos.duration,+ public: videos.public,+ settings: videos.settings,+ hasPassword: sql`${videos.password} IS NOT NULL`.mapWith(Boolean),totalComments: sql<number>`COUNT(DISTINCT CASE WHEN ${comments.type} = 'text' THEN ${comments.id} END)`,totalReactions: sql<number>`COUNT(DISTINCT CASE WHEN ${comments.type} = 'emoji' THEN ${comments.id} END)`,ownerName: users.name,@@ -314,6 +395,9 @@ export default async function SharedCapsPage(props: {videos.metadata,users.name,videos.duration,+ videos.public,+ videos.settings,+ videos.password,).orderBy(desc(videos.effectiveCreatedAt)).limit(limit)@@ -345,14 +429,28 @@ export default async function SharedCapsPage(props: {]);const { videos: orgVideoData, totalCount } = organizationVideos;+ const sharedSpacesMap = await fetchSharedSpacesForVideos(+ orgVideoData.map((video) => Video.VideoId.make(video.id)),+ );const processedVideoData = orgVideoData.map((video) => {- const { effectiveDate, ...videoWithoutEffectiveDate } = video;+ const { effectiveDate: _effectiveDate, ...videoWithoutEffectiveDate } =+ video;+ const sharedSpaces = sharedSpacesMap[video.id] ?? [];+ const rules = resolveEffectiveVideoRules({+ videoSettings: video.settings,+ organizationSettings: null,+ spaces: sharedSpaces,+ });return {...videoWithoutEffectiveDate,id: Video.VideoId.make(video.id),+ hasInheritedPassword: rules.hasInheritedPassword,+ inheritedPasswordSources: rules.inheritedPasswordSources,+ inheritedSpaceSettings: rules.inheritedSettings,+ sharedSpaces,ownerName: video.ownerName ?? null,metadata: video.metadata as- | { customCreatedAt?: string; [key: string]: any }+ | { customCreatedAt?: string; [key: string]: unknown }| undefined,};});