Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
folders for "all" spaces and org switch reroute (#742)
Ameer Al Ashhabc43713149770
diff --git a/apps/web/app/(org)/dashboard/_components/DashboardInner.tsx b/apps/web/app/(org)/dashboard/_components/DashboardInner.tsxindex 5d30a4480..7ef626c3d 100644--- a/apps/web/app/(org)/dashboard/_components/DashboardInner.tsx+++ b/apps/web/app/(org)/dashboard/_components/DashboardInner.tsx@@ -300,14 +300,13 @@ const MenuItem = memo(({ icon, name, href, onClick, iconClassName }: Props) => {const ReferButton = () => {const iconRef = useRef<ReferIconHandle>(null);- const [isHovered, setIsHovered] = useState(false);return (- <Link href="/dashboard/refer" className="relative hidden lg:block">+ <Link href="/dashboard/refer" className="hidden relative lg:block">{/* Red notification dot with pulse animation */}- <div className="absolute top-1 right-1 z-10">+ <div className="absolute right-0 top-1 z-10"><div className="relative">- <div className="absolute inset-0 w-2 h-2 bg-red-500 rounded-full animate-ping opacity-75" />+ <div className="absolute inset-0 w-2 h-2 bg-red-500 rounded-full opacity-75 animate-ping" /><div className="relative w-2 h-2 bg-red-500 rounded-full" /></div></div>@@ -315,11 +314,9 @@ const ReferButton = () => {<divonMouseEnter={() => {iconRef.current?.startAnimation();- setIsHovered(true);}}onMouseLeave={() => {iconRef.current?.stopAnimation();- setIsHovered(false);}}className="flex justify-center items-center rounded-full transition-colors cursor-pointer bg-gray-3 hover:bg-gray-5 size-9">diff --git a/apps/web/app/(org)/dashboard/_components/Navbar/Items.tsx b/apps/web/app/(org)/dashboard/_components/Navbar/Items.tsxindex dc4cc7fc2..821c95250 100644--- a/apps/web/app/(org)/dashboard/_components/Navbar/Items.tsx+++ b/apps/web/app/(org)/dashboard/_components/Navbar/Items.tsx@@ -31,7 +31,7 @@ import { motion } from "framer-motion";import { Check, ChevronDown, Plus } from "lucide-react";import Image from "next/image";import Link from "next/link";-import { usePathname } from "next/navigation";+import { usePathname, useRouter } from "next/navigation";import { cloneElement, useRef, useState } from "react";import { useDashboardContext } from "../../Contexts";import { CogIcon, CapIcon } from "../AnimatedIcons";@@ -68,13 +68,13 @@ const AdminNavItems = ({ toggleMobileNav }: Props) => {},...(buildEnv.NEXT_PUBLIC_IS_CAP && user.email.endsWith("@cap.so")? [- {- name: "Admin Dev",- href: "/dashboard/admin",- icon: <CogIcon />,- subNav: [],- },- ]+ {+ name: "Admin Dev",+ href: "/dashboard/admin",+ icon: <CogIcon />,+ subNav: [],+ },+ ]: []),];@@ -89,6 +89,7 @@ const AdminNavItems = ({ toggleMobileNav }: Props) => {const [organizationName, setOrganizationName] = useState("");const isOwner = activeOrg?.organization.ownerId === user.id;const [openAIDialog, setOpenAIDialog] = useState(false);+ const router = useRouter();const isPathActive = (path: string) => pathname.includes(path);@@ -197,6 +198,7 @@ const AdminNavItems = ({ toggleMobileNav }: Props) => {organization.organization.id);setOpen(false);+ router.push("/dashboard/caps");}}><div className="flex gap-2 items-center w-full">@@ -347,10 +349,10 @@ const AdminNavItems = ({ toggleMobileNav }: Props) => {subscribed={userIsSubscribed}/>{buildEnv.NEXT_PUBLIC_IS_CAP && (- <div className="mt-2 flex justify-center items-center">+ <div className="flex justify-center items-center mt-2"><Linkhref="/dashboard/refer"- className="text-sm text-gray-10 hover:text-gray-12 underline"+ className="text-sm underline text-gray-10 hover:text-gray-12">Earn 40% Referral</Link>diff --git a/apps/web/app/(org)/dashboard/caps/components/Folder.tsx b/apps/web/app/(org)/dashboard/caps/components/Folder.tsxindex 623792e21..ac3331729 100644--- a/apps/web/app/(org)/dashboard/caps/components/Folder.tsx+++ b/apps/web/app/(org)/dashboard/caps/components/Folder.tsx@@ -13,6 +13,7 @@ import { registerDropTarget } from "../../folder/[id]/components/ClientCapCard";import { ConfirmationDialog } from "../../_components/ConfirmationDialog";import { FoldersDropdown } from "./FoldersDropdown";import clsx from "clsx";+import { useDashboardContext } from "../../Contexts";export type FolderDataType = {name: string;@@ -33,6 +34,7 @@ const Folder = ({ name, color, id, parentId, videoCount, spaceId }: FolderDataTyconst folderRef = useRef<HTMLDivElement>(null);const [isDragOver, setIsDragOver] = useState(false);const [isMovingVideo, setIsMovingVideo] = useState(false);+ const { activeOrganization } = useDashboardContext();// Use a ref to track drag state to avoid re-renders during animationconst dragStateRef = useRef({isDragging: false,@@ -91,7 +93,7 @@ const Folder = ({ name, color, id, parentId, videoCount, spaceId }: FolderDataTytry {setIsMovingVideo(true);- await moveVideoToFolder({ videoId: data.id, folderId: id, spaceId });+ await moveVideoToFolder({ videoId: data.id, folderId: id, spaceId: spaceId ?? activeOrganization?.organization.id });toast.success(`"${data.name}" moved to "${name}" folder`);} catch (error) {console.error("Error moving video to folder:", error);diff --git a/apps/web/app/(org)/dashboard/folder/[id]/components/ClientCapCard.tsx b/apps/web/app/(org)/dashboard/folder/[id]/components/ClientCapCard.tsxindex b7ff7c3ad..8ab620c2a 100644--- a/apps/web/app/(org)/dashboard/folder/[id]/components/ClientCapCard.tsx+++ b/apps/web/app/(org)/dashboard/folder/[id]/components/ClientCapCard.tsx@@ -4,11 +4,7 @@ import {CapCard,CapCardProps,} from "../../../caps/components/CapCard/CapCard";-import { deleteVideo } from "@/actions/videos/delete";import { useState, useRef } from "react";-import { createPortal } from "react-dom";-import { useRouter } from "next/navigation";-import { toast } from "sonner";type ClientCapCardProps = CapCardProps & {videoId: string;@@ -40,23 +36,9 @@ export function registerDropTarget(export function ClientCapCard(props: ClientCapCardProps) {const { videoId, ...rest } = props;- const router = useRouter();const [isDragging, setIsDragging] = useState(false);const cardRef = useRef<HTMLDivElement>(null);- const [touchDragging, setTouchDragging] = useState(false);- const [touchPosition, setTouchPosition] = useState({ x: 0, y: 0 });- const dragDataRef = useRef<any>(null);- const handleDelete = async (videoId: string) => {- try {- await deleteVideo(videoId);- router.refresh();- toast.success("Video deleted successfully");- } catch (error) {- console.error("Error deleting video:", error);- toast.error("Failed to delete video");- }- };// Create a drag preview element with thumbnailconst createDragPreview = (text: string): HTMLElement => {@@ -77,15 +59,6 @@ export function ClientCapCard(props: ClientCapCardProps) {return container;};- // Create the data object for drag operations- const createDragData = () => {- return {- id: videoId,- name: props.cap.name,- type: "application/cap",- };- };-// Handle drag start event for desktopconst handleDragStart = (e: React.DragEvent<HTMLDivElement>) => {// Set the data transfer@@ -121,142 +94,16 @@ export function ClientCapCard(props: ClientCapCardProps) {setIsDragging(false);};- // Touch event handlers for mobile drag and drop- const handleTouchStart = (e: React.TouchEvent<HTMLDivElement>) => {- // Store the drag data for potential drop- dragDataRef.current = createDragData();-- // Get touch position- if (e.touches.length > 0) {- const touch = e.touches[0];- // Safely access touch properties- if (touch) {- const initialX = touch.clientX;- const initialY = touch.clientY;-- // Set a timeout to distinguish between tap and drag- const timer = setTimeout(() => {- // Start dragging after a short delay to avoid accidental drags- setTouchDragging(true);- setTouchPosition({ x: initialX, y: initialY });- }, 200);-- // Clear the timer if the touch ends quickly (tap)- const clearTimer = () => clearTimeout(timer);- document.addEventListener("touchend", clearTimer, { once: true });- }- }- };-- const handleTouchMove = (e: React.TouchEvent<HTMLDivElement>) => {- if (!touchDragging) return;-- // Prevent scrolling while dragging- e.preventDefault();-- if (e.touches.length > 0) {- const touch = e.touches[0];- // Safely access touch properties- if (touch) {- setTouchPosition({ x: touch.clientX, y: touch.clientY });-- // Check if we're over any drop targets- checkDropTargets(touch.clientX, touch.clientY);- }- }- };-- const handleTouchEnd = (e: React.TouchEvent<HTMLDivElement>) => {- if (!touchDragging) return;-- // Check if we're over a drop target and trigger the drop- if (e.changedTouches.length > 0) {- const lastTouch = e.changedTouches[0];- // Safely access touch properties- if (lastTouch) {- const dropTarget = findDropTargetAtPosition(- lastTouch.clientX,- lastTouch.clientY- );-- if (dropTarget && dragDataRef.current) {- dropTarget.onDrop(dragDataRef.current);- }- }- }-- // Reset dragging state- setTouchDragging(false);- dragDataRef.current = null;- };-- // Helper function to check if we're over a drop target- const checkDropTargets = (x: number, y: number) => {- // Highlight the drop target we're over (if any)- dropTargets.forEach((target) => {- const rect = target.element.getBoundingClientRect();- const isOver =- x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom;-- // Add/remove a class to highlight the drop target- if (isOver) {- target.element.classList.add("drag-over");- // Trigger the onDragOver callback if provided- if (target.onDragOver) {- target.onDragOver();- }- } else if (target.element.classList.contains("drag-over")) {- target.element.classList.remove("drag-over");- // Trigger the onDragLeave callback if provided- if (target.onDragLeave) {- target.onDragLeave();- }- }- });- };-- // Helper function to find a drop target at a position- const findDropTargetAtPosition = (x: number, y: number) => {- return dropTargets.find((target) => {- const rect = target.element.getBoundingClientRect();- return (- x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom- );- });- };return (- <>- <div- ref={cardRef}- draggable={true}- onDragStart={handleDragStart}- onDragEnd={handleDragEnd}- onTouchStart={handleTouchStart}- onTouchMove={handleTouchMove}- onTouchEnd={handleTouchEnd}- className={isDragging || touchDragging ? "opacity-50" : ""}- >- <CapCard {...rest} />- </div>-- {/* Mobile drag preview */}- {touchDragging &&- typeof document !== "undefined" &&- createPortal(- <div- className="flex fixed z-50 gap-2 items-center px-3 py-2 rounded-lg border shadow-md pointer-events-none bg-gray-1 border-gray-4"- style={{- left: `${touchPosition.x - 20}px`,- top: `${touchPosition.y - 30}px`,- }}- >- <span className="text-sm font-medium text-gray-12">- {props.cap.name}- </span>- </div>,- document.body- )}- </>+ <div+ ref={cardRef}+ draggable={true}+ onDragStart={handleDragStart}+ onDragEnd={handleDragEnd}+ className={isDragging ? "opacity-50" : ""}+ >+ <CapCard {...rest} />+ </div>);}diff --git a/apps/web/app/(org)/dashboard/spaces/[spaceId]/SharedCaps.tsx b/apps/web/app/(org)/dashboard/spaces/[spaceId]/SharedCaps.tsxindex ddd825b55..e9142aa1f 100644--- a/apps/web/app/(org)/dashboard/spaces/[spaceId]/SharedCaps.tsx+++ b/apps/web/app/(org)/dashboard/spaces/[spaceId]/SharedCaps.tsx@@ -181,14 +181,11 @@ export const SharedCaps = ({</div></div>)}- {/* Only render NewFolderDialog if not in All Spaces (Caps/personal) context */}- {spaceData && (- <NewFolderDialog- open={openNewFolderDialog}- spaceId={spaceData.id}- onOpenChange={setOpenNewFolderDialog}- />- )}+ <NewFolderDialog+ open={openNewFolderDialog}+ spaceId={spaceData?.id ?? activeOrganization?.organization.id}+ onOpenChange={setOpenNewFolderDialog}+ /><div className="flex flex-wrap gap-3 mb-10">{spaceData && spaceMembers && (<MembersIndicator@@ -227,16 +224,15 @@ export const SharedCaps = ({onVideosAdded={handleVideosAdded}/>)}- {spaceData && (- <Button- onClick={() => setOpenNewFolderDialog(true)}- size="sm"- variant="dark"- className="flex gap-2 items-center w-fit"- >- <FontAwesomeIcon className="size-3.5" icon={faFolderPlus} />- New Folder- </Button>)}+ <Button+ onClick={() => setOpenNewFolderDialog(true)}+ size="sm"+ variant="dark"+ className="flex gap-2 items-center w-fit"+ >+ <FontAwesomeIcon className="size-3.5" icon={faFolderPlus} />+ New Folder+ </Button></div>{folders && folders.length > 0 && (<>diff --git a/apps/web/app/(org)/dashboard/spaces/[spaceId]/page.tsx b/apps/web/app/(org)/dashboard/spaces/[spaceId]/page.tsxindex 4eda27527..c6cf4a11a 100644--- a/apps/web/app/(org)/dashboard/spaces/[spaceId]/page.tsx+++ b/apps/web/app/(org)/dashboard/spaces/[spaceId]/page.tsx@@ -307,7 +307,7 @@ export default async function SharedCapsPage({.innerJoin(videos, eq(sharedVideos.videoId, videos.id)).leftJoin(comments, eq(videos.id, comments.videoId)).leftJoin(users, eq(videos.ownerId, users.id))- .where(eq(sharedVideos.organizationId, orgId))+ .where(and(eq(sharedVideos.organizationId, orgId), isNull(videos.folderId))).groupBy(videos.id,videos.ownerId,@@ -326,7 +326,8 @@ export default async function SharedCapsPage({db().select({ count: count() }).from(sharedVideos)- .where(eq(sharedVideos.organizationId, orgId)),+ .innerJoin(videos, eq(sharedVideos.videoId, videos.id))+ .where(and(eq(sharedVideos.organizationId, orgId), isNull(videos.folderId))),]);return {videos: videoRows,