Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
more optimizations (#664)
Ameer Al Ashhabf1c1b9c82823
diff --git a/apps/web/actions/videos/get-user-videos.ts b/apps/web/actions/videos/get-user-videos.tsindex 2d7ed12bc..6dce02df8 100644--- a/apps/web/actions/videos/get-user-videos.ts+++ b/apps/web/actions/videos/get-user-videos.ts@@ -5,7 +5,7 @@ import { videos, comments, users } from "@cap/database/schema";import { db } from "@cap/database";import { eq, desc, sql } from "drizzle-orm";-export async function getUserVideos(limit: number = 20) {+export async function getUserVideos(limit?: number) {try {const user = await getCurrentUser();@@ -50,7 +50,7 @@ export async function getUserVideos(limit: number = 20) {${videos.createdAt})`))- .limit(limit);+ .limit(limit || 20);const processedVideoData = videoData.map((video) => {const { effectiveDate, ...videoWithoutEffectiveDate } = video;@@ -68,4 +68,4 @@ export async function getUserVideos(limit: number = 20) {console.error("Error fetching user videos:", error);return { success: false, error: "Failed to fetch videos" };}-}\ No newline at end of file+}diff --git a/apps/web/app/dashboard/spaces/[spaceId]/components/AddVideosDialogBase.tsx b/apps/web/app/dashboard/spaces/[spaceId]/components/AddVideosDialogBase.tsxindex 7880259a7..4571b7523 100644--- a/apps/web/app/dashboard/spaces/[spaceId]/components/AddVideosDialogBase.tsx+++ b/apps/web/app/dashboard/spaces/[spaceId]/components/AddVideosDialogBase.tsx@@ -15,7 +15,7 @@ import { useForm } from "react-hook-form";import { toast } from "sonner";import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";import { faVideo } from "@fortawesome/free-solid-svg-icons";-import { useMutation, useQuery } from "@tanstack/react-query";+import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";import { Search } from "lucide-react";import clsx from "clsx";import VirtualizedVideoGrid from "./VirtualizedVideoGrid";@@ -28,7 +28,7 @@ interface AddVideosDialogBaseProps {onVideosAdded?: () => void;addVideos: (entityId: string, videoIds: string[]) => Promise<any>;removeVideos: (entityId: string, videoIds: string[]) => Promise<any>;- getVideos: (limit: number) => Promise<any>;+ getVideos: (limit?: number) => Promise<any>;getEntityVideoIds: (entityId: string) => Promise<any>;}@@ -64,6 +64,8 @@ const AddVideosDialogBase: React.FC<AddVideosDialogBaseProps> = ({const [searchTerm, setSearchTerm] = useState("");const filterTabs = ['all', 'added', 'notAdded'];+ const queryClient = useQueryClient();+const form = useForm<z.infer<typeof formSchema>>({resolver: zodResolver(formSchema),defaultValues: {@@ -74,14 +76,16 @@ const AddVideosDialogBase: React.FC<AddVideosDialogBaseProps> = ({const { data: videosData, isLoading } = useQuery<Video[]>({queryKey: ["user-videos"],queryFn: async () => {- const result = await getVideos(50);+ const result = await getVideos();if (!result.success) {throw new Error(result.error);}return result.data;},enabled: open,- refetchOnWindowFocus: false // Don't refetch when window regains focus+ refetchOnWindowFocus: false, // Don't refetch when window regains focus+ staleTime: Infinity, // Consider data fresh forever (until manually invalidated)+ gcTime: 1000 * 60 * 5, // Cache for 5 minutes (gcTime is the new name for cacheTime)});const { data: entityVideoIds } = useQuery<string[]>({@@ -94,7 +98,9 @@ const AddVideosDialogBase: React.FC<AddVideosDialogBaseProps> = ({return result.data;},enabled: open,- refetchOnWindowFocus: false // Don't refetch when window regains focus+ refetchOnWindowFocus: false, // Don't refetch when window regains focus+ staleTime: Infinity, // Consider data fresh forever (until manually invalidated)+ gcTime: 1000 * 60 * 5, // Cache for 5 minutes (gcTime is the new name for cacheTime)});const updateVideosMutation = useMutation({@@ -109,8 +115,15 @@ const AddVideosDialogBase: React.FC<AddVideosDialogBaseProps> = ({}return { addResult, removeResult };},- onSuccess: (result) => {+ onSuccess: async (result) => {const { addResult, removeResult } = result || {};++ // Invalidate both queries to ensure UI updates+ await Promise.all([+ queryClient.invalidateQueries({ queryKey: ["user-videos"] }),+ queryClient.invalidateQueries({ queryKey: ["entity-video-ids", entityId] })+ ]);+if ((addResult?.success ?? true) && (removeResult?.success ?? true)) {toast.success("Videos updated successfully");setSelectedVideos([]);@@ -265,7 +278,6 @@ const AddVideosDialogBase: React.FC<AddVideosDialogBaseProps> = ({height={300}columnCount={3}rowHeight={200}- columnWidth={200}/>)}</div>diff --git a/apps/web/app/dashboard/spaces/[spaceId]/components/VirtualizedVideoGrid.tsx b/apps/web/app/dashboard/spaces/[spaceId]/components/VirtualizedVideoGrid.tsxindex b1a5879e3..59ed726c5 100644--- a/apps/web/app/dashboard/spaces/[spaceId]/components/VirtualizedVideoGrid.tsx+++ b/apps/web/app/dashboard/spaces/[spaceId]/components/VirtualizedVideoGrid.tsx@@ -11,7 +11,6 @@ interface VirtualizedVideoGridProps {height?: number;columnCount?: number;rowHeight?: number;- columnWidth?: number;}const VirtualizedVideoGrid = ({@@ -22,7 +21,6 @@ const VirtualizedVideoGrid = ({height = 400,columnCount = 3,rowHeight = 200,- columnWidth = 200,}: VirtualizedVideoGridProps) => {// Create a ref for the scrollable containerconst scrollRef = useRef<HTMLDivElement>(null);@@ -53,10 +51,14 @@ const VirtualizedVideoGrid = ({scrollRef,count: videos.length,columns: responsiveColumnCount,- gap: 12,+ gap: {+ y: 16,+ x: 12,+ },size: {height: rowHeight,- }+ },+ overscan: 5, // Add overscan to prevent refetching when scrolling});return (@@ -78,10 +80,10 @@ const VirtualizedVideoGrid = ({return (<div- className="px-2 mx-auto md:mx-0 md:px-0"+ key={video.id}+ className="px-2 mx-auto md:mx-0 md:px-0 w-[96%]"><VideoCard- key={video.id}video={video}isSelected={selectedVideos.includes(video.id)}onToggle={() => handleVideoToggle(video.id)}