fix propagation

This commit is contained in:
Ishaan Dey 2024-05-16 21:45:19 -07:00
parent bf0111fe91
commit 509669ea30
4 changed files with 33 additions and 38 deletions

View File

@ -87,18 +87,6 @@
background: radial-gradient(circle at bottom, #312e81 -10%, hsl(0 0% 3.9%) 80%); /* violet 900 -> bg */ background: radial-gradient(circle at bottom, #312e81 -10%, hsl(0 0% 3.9%) 80%); /* violet 900 -> bg */
} }
.gradient-project-card-bg {
background: radial-gradient(circle at bottom right, #a5b4fc -15%, #3730a3 25%, hsl(0 0% 3.9%) 50%); /* violet 300 -> 800 */
}
.gradient-project-card {
background: radial-gradient(circle at bottom right, #312e81 -75%, hsl(0 0% 3.9%) 50%); /* violet 900 -> bg */
}
.gradient-project-card-bg > div:hover {
background: radial-gradient(circle at bottom right, #312e81 -75%, hsl(0 0% 3.9%) 60%); /* violet 900 -> bg */
}
.inline-decoration::before { .inline-decoration::before {
content: 'Generate'; content: 'Generate';
color: #525252; color: #525252;

View File

@ -1,30 +1,30 @@
"use client" "use client";
import { Sandbox } from "@/lib/types" import { Sandbox } from "@/lib/types";
import { Ellipsis, Globe, Lock, Trash2 } from "lucide-react" import { Ellipsis, Globe, Lock, Trash2 } from "lucide-react";
import { import {
DropdownMenu, DropdownMenu,
DropdownMenuContent, DropdownMenuContent,
DropdownMenuItem, DropdownMenuItem,
DropdownMenuTrigger, DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu" } from "@/components/ui/dropdown-menu";
export default function ProjectCardDropdown({ export default function ProjectCardDropdown({
sandbox, sandbox,
onVisibilityChange, onVisibilityChange,
onDelete, onDelete,
}: { }: {
sandbox: Sandbox sandbox: Sandbox;
onVisibilityChange: (sandbox: Sandbox) => void onVisibilityChange: (sandbox: Sandbox) => void;
onDelete: (sandbox: Sandbox) => void onDelete: (sandbox: Sandbox) => void;
}) { }) {
return ( return (
<DropdownMenu> <DropdownMenu modal={false}>
<DropdownMenuTrigger <DropdownMenuTrigger
onClick={(e) => { onClick={(e) => {
e.preventDefault() e.preventDefault();
e.stopPropagation() e.stopPropagation();
}} }}
className="h-6 w-6 flex items-center justify-center transition-colors bg-transparent hover:bg-muted-foreground/25 rounded-sm outline-foreground" className="h-6 w-6 flex items-center justify-center transition-colors bg-transparent hover:bg-muted-foreground/25 rounded-sm outline-foreground"
> >
@ -33,8 +33,8 @@ export default function ProjectCardDropdown({
<DropdownMenuContent className="w-40"> <DropdownMenuContent className="w-40">
<DropdownMenuItem <DropdownMenuItem
onClick={(e) => { onClick={(e) => {
e.stopPropagation() e.stopPropagation();
onVisibilityChange(sandbox) onVisibilityChange(sandbox);
}} }}
className="cursor-pointer" className="cursor-pointer"
> >
@ -52,8 +52,8 @@ export default function ProjectCardDropdown({
</DropdownMenuItem> </DropdownMenuItem>
<DropdownMenuItem <DropdownMenuItem
onClick={(e) => { onClick={(e) => {
e.stopPropagation() e.stopPropagation();
onDelete(sandbox) onDelete(sandbox);
}} }}
className="!text-destructive cursor-pointer" className="!text-destructive cursor-pointer"
> >
@ -62,5 +62,5 @@ export default function ProjectCardDropdown({
</DropdownMenuItem> </DropdownMenuItem>
</DropdownMenuContent> </DropdownMenuContent>
</DropdownMenu> </DropdownMenu>
) );
} }

View File

@ -7,25 +7,31 @@ import ProjectCardDropdown from "./dropdown";
import { Clock, Globe, Lock } from "lucide-react"; import { Clock, Globe, Lock } from "lucide-react";
import { Sandbox } from "@/lib/types"; import { Sandbox } from "@/lib/types";
import { Card } from "@/components/ui/card"; import { Card } from "@/components/ui/card";
import { useRouter } from "next/navigation";
export default function ProjectCard({ export default function ProjectCard({
children, children,
sandbox, sandbox,
onVisibilityChange, onVisibilityChange,
onDelete, onDelete,
deletingId,
}: { }: {
children?: React.ReactNode; children?: React.ReactNode;
sandbox: Sandbox; sandbox: Sandbox;
onVisibilityChange: (sandbox: Sandbox) => void; onVisibilityChange: (sandbox: Sandbox) => void;
onDelete: (sandbox: Sandbox) => void; onDelete: (sandbox: Sandbox) => void;
deletingId: string;
}) { }) {
const [hovered, setHovered] = useState(false); const [hovered, setHovered] = useState(false);
const router = useRouter();
return ( return (
<Card <Card
tabIndex={0}
onClick={() => router.push(`/code/${sandbox.id}`)}
onMouseEnter={() => setHovered(true)} onMouseEnter={() => setHovered(true)}
onMouseLeave={() => setHovered(false)} onMouseLeave={() => setHovered(false)}
className="group/canvas-card p-4 h-48 flex flex-col justify-between items-start hover:border-foreground transition-all relative overflow-hidden" className={`group/canvas-card p-4 h-48 flex flex-col justify-between items-start hover:border-muted-foreground relative overflow-hidden transition-all`}
> >
<AnimatePresence> <AnimatePresence>
{hovered && ( {hovered && (

View File

@ -9,7 +9,7 @@ import Link from "next/link";
import { Card } from "../ui/card"; import { Card } from "../ui/card";
import { deleteSandbox, updateSandbox } from "@/lib/actions"; import { deleteSandbox, updateSandbox } from "@/lib/actions";
import { toast } from "sonner"; import { toast } from "sonner";
import { useState } from "react"; import { useEffect, useState } from "react";
import { CanvasRevealEffect } from "./projectCard/revealEffect"; import { CanvasRevealEffect } from "./projectCard/revealEffect";
const colors = { const colors = {
@ -30,19 +30,20 @@ export default function DashboardProjects({
sandboxes: Sandbox[]; sandboxes: Sandbox[];
q: string | null; q: string | null;
}) { }) {
const [focusedId, setFocusedId] = useState<string | null>(null);
const [deletingId, setDeletingId] = useState<string>(""); const [deletingId, setDeletingId] = useState<string>("");
const onDelete = async (sandbox: Sandbox) => { const onDelete = async (sandbox: Sandbox) => {
setDeletingId(sandbox.id); setDeletingId(sandbox.id);
toast(`Project ${sandbox.name} deleted.`); toast(`Project ${sandbox.name} deleted.`);
await deleteSandbox(sandbox.id); await deleteSandbox(sandbox.id);
setTimeout(() => {
// timeout to wait for revalidatePath and avoid flashing
setDeletingId("");
}, 200);
}; };
useEffect(() => {
if (deletingId) {
setDeletingId("");
}
}, [sandboxes]);
const onVisibilityChange = async (sandbox: Sandbox) => { const onVisibilityChange = async (sandbox: Sandbox) => {
const newVisibility = const newVisibility =
sandbox.visibility === "public" ? "private" : "public"; sandbox.visibility === "public" ? "private" : "public";
@ -71,17 +72,17 @@ export default function DashboardProjects({
<Link <Link
key={sandbox.id} key={sandbox.id}
href={`/code/${sandbox.id}`} href={`/code/${sandbox.id}`}
onFocus={() => setFocusedId(sandbox.id)}
className={`${ className={`${
deletingId === sandbox.id deletingId === sandbox.id
? "pointer-events-none opacity-50" ? "pointer-events-none opacity-50 cursor-events-none"
: "" : "cursor-pointer"
} cursor-pointer transition-all focus-visible:outline-none focus-visible:ring-offset-2 focus-visible:ring-offset-background focus-visible:ring-2 focus-visible:ring-ring rounded-lg`} } transition-all focus-visible:outline-none focus-visible:ring-offset-2 focus-visible:ring-offset-background focus-visible:ring-2 focus-visible:ring-ring rounded-lg`}
> >
<ProjectCard <ProjectCard
sandbox={sandbox} sandbox={sandbox}
onVisibilityChange={onVisibilityChange} onVisibilityChange={onVisibilityChange}
onDelete={onDelete} onDelete={onDelete}
deletingId={deletingId}
> >
<CanvasRevealEffect <CanvasRevealEffect
animationSpeed={3} animationSpeed={3}