Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,21 @@ export const useStartProject = () => {
await apiUtils.project.createRequest.getPendingRequest.invalidate({ projectId: editorEngine.projectId });
},
});
const { mutateAsync: trackProjectAccess } = api.project.trackAccess.useMutation({
onSuccess: () => {
// Invalidate project list to refresh recent projects
apiUtils.project.list.invalidate();
},
});

useEffect(() => {
if (project) {
startSandbox(project);
editorEngine.screenshot.lastScreenshotAt = project.metadata.updatedPreviewImgAt;
// Track project access to update "recent projects" list
trackProjectAccess({ projectId: project.id }).catch(console.error);
}
}, [project]);
}, [project, trackProjectAccess]);

const startSandbox = async (project: Project) => {
try {
Expand Down
26 changes: 26 additions & 0 deletions apps/web/client/src/server/api/routers/project/project.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { env } from '@/env';
import { createTRPCRouter, protectedProcedure } from '@/server/api/trpc';
import { TRPCError } from '@trpc/server';
import { trackEvent } from '@/utils/analytics/server';
import FirecrawlApp from '@mendable/firecrawl-js';
import { initModel } from '@onlook/ai';
Expand Down Expand Up @@ -403,4 +404,29 @@ export const projectRouter = createTRPCRouter({

return { success: true, tags: newTags };
}),

trackAccess: protectedProcedure
.input(z.object({ projectId: z.string().uuid() }))
.mutation(async ({ ctx, input }) => {
// Check if user has access to this project
const membership = await ctx.db.query.userProjects.findFirst({
where: and(
eq(userProjects.userId, ctx.user.id),
eq(userProjects.projectId, input.projectId),
),
});

if (!membership) {
throw new TRPCError({
code: 'FORBIDDEN',
message: 'You do not have access to this project'
});
}

await ctx.db.update(projects).set({
updatedAt: new Date(),
}).where(eq(projects.id, input.projectId));

return { success: true };
}),
});