summaryrefslogtreecommitdiff
path: root/apps/web/src/components/editor/scenes-view.tsx
blob: f1df32e9510be19e839d05e49fcbc08c974bde5d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"use client";

import {
  Sheet,
  SheetContent,
  SheetDescription,
  SheetHeader,
  SheetTitle,
  SheetTrigger,
} from "@/components/ui/sheet";
import { Button } from "@/components/ui/button";
import { useSceneStore } from "@/stores/scene-store";
import { Check } from "lucide-react";

export function ScenesView({ children }: { children: React.ReactNode }) {
  const { scenes, currentScene, switchToScene } = useSceneStore();

  const handleSceneSwitch = async (sceneId: string) => {
    try {
      await switchToScene({ sceneId });
    } catch (error) {
      console.error("Failed to switch scene:", error);
    }
  };

  return (
    <Sheet>
      <SheetTrigger asChild>{children}</SheetTrigger>
      <SheetContent>
        <SheetHeader>
          <SheetTitle>Scenes</SheetTitle>
          <SheetDescription>
            Switch between scenes in your project
          </SheetDescription>
        </SheetHeader>
        <div className="py-4">
          {scenes.length === 0 ? (
            <div className="text-sm text-muted-foreground">
              No scenes available
            </div>
          ) : (
            <div className="space-y-2">
              {scenes.map((scene) => (
                <Button
                  key={scene.id}
                  variant={
                    currentScene?.id === scene.id ? "default" : "outline"
                  }
                  className="w-full justify-between"
                  onClick={() => handleSceneSwitch(scene.id)}
                >
                  <span>{scene.name}</span>
                  {currentScene?.id === scene.id && (
                    <Check className="h-4 w-4" />
                  )}
                </Button>
              ))}
            </div>
          )}
        </div>
      </SheetContent>
    </Sheet>
  );
}