@@ -8,6 +8,8 @@ import type { LoopSchemas } from "@posthog/api-client/loops";
88import { Tabs , TabsContent , TabsList , TabsTrigger } from "@posthog/quill" ;
99import { ANALYTICS_EVENTS } from "@posthog/shared/analytics-events" ;
1010import type { UserBasic } from "@posthog/shared/domain-types" ;
11+ import { useOptionalAuthenticatedClient } from "@posthog/ui/features/auth/authClient" ;
12+ import { useCurrentUser } from "@posthog/ui/features/auth/useCurrentUser" ;
1113import { useOrgMembers } from "@posthog/ui/features/canvas/hooks/useOrgMembers" ;
1214import { StopCloudRunDialog } from "@posthog/ui/features/sessions/components/StopCloudRunDialog" ;
1315import { useSetHeaderContent } from "@posthog/ui/hooks/useSetHeaderContent" ;
@@ -67,9 +69,22 @@ function startLoopFromTemplate(template: LoopTemplate): void {
6769
6870export function LoopsListView ( ) {
6971 const { data : loops , isLoading, isError, error } = useLoops ( ) ;
72+ const authenticatedClient = useOptionalAuthenticatedClient ( ) ;
73+ const {
74+ data : currentUser ,
75+ isLoading : currentUserLoading ,
76+ isError : currentUserError ,
77+ error : currentUserQueryError ,
78+ } = useCurrentUser ( { client : authenticatedClient } ) ;
7079 const limits = useLoopLimits ( ) ;
7180 const limitReason =
7281 limits ?. atLimit === true ? loopLimitReason ( limits . max ) : null ;
82+ let listError : unknown = null ;
83+ if ( isError ) {
84+ listError = error ;
85+ } else if ( currentUserError ) {
86+ listError = currentUserQueryError ;
87+ }
7388
7489 const headerContent = useMemo (
7590 ( ) => (
@@ -134,8 +149,9 @@ export function LoopsListView() {
134149 return (
135150 < LoopsListViewPresentation
136151 loops = { allLoops }
137- isLoading = { isLoading }
138- error = { isError ? error : null }
152+ currentUserId = { currentUser ?. id ?? null }
153+ isLoading = { isLoading || currentUserLoading }
154+ error = { listError }
139155 limitReason = { limitReason }
140156 members = { members }
141157 membersLoading = { membersLoading }
@@ -152,6 +168,7 @@ export function LoopsListView() {
152168
153169interface LoopsListViewPresentationProps {
154170 loops : LoopSchemas . Loop [ ] ;
171+ currentUserId ?: number | null ;
155172 isLoading ?: boolean ;
156173 error ?: unknown ;
157174 limitReason ?: string | null ;
@@ -168,6 +185,7 @@ interface LoopsListViewPresentationProps {
168185
169186export function LoopsListViewPresentation ( {
170187 loops,
188+ currentUserId = null ,
171189 isLoading = false ,
172190 error = null ,
173191 limitReason = null ,
@@ -181,8 +199,16 @@ export function LoopsListViewPresentation({
181199 onResumeBuilderSession,
182200 onBuilderSessionStopped,
183201} : LoopsListViewPresentationProps ) {
184- const personalLoops = loops . filter ( ( loop ) => loop . visibility === "personal" ) ;
185- const teamLoops = loops . filter ( ( loop ) => loop . visibility === "team" ) ;
202+ const personalLoops = loops . filter (
203+ ( loop ) =>
204+ loop . visibility === "personal" ||
205+ ( currentUserId !== null && loop . created_by_id === currentUserId ) ,
206+ ) ;
207+ const teamLoops = loops . filter (
208+ ( loop ) =>
209+ loop . visibility === "team" &&
210+ ( currentUserId === null || loop . created_by_id !== currentUserId ) ,
211+ ) ;
186212
187213 return (
188214 < Flex direction = "column" className = "h-full min-h-0" >
0 commit comments