Spaces:
deepak191z
/
Runtime error

File size: 2,415 Bytes
229b3b8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import {
  DRAG_END,
  DRAG_PREFIX,
  DRAG_START,
  ITransition,
  TRANSITIONS,
  dispatcher,
  filter,
} from '@designcombo/core';
import React, { useEffect, useState } from 'react';
import Draggable from '@/components/shared/draggable';
import { ScrollArea } from '@/components/ui/scroll-area';

export const Transitions = () => {
  const [shouldDisplayPreview, setShouldDisplayPreview] = useState(true);
  //   handle track and track item events - updates
  useEffect(() => {
    const dragEvents = dispatcher.bus.pipe(
      filter(({ key }) => key.startsWith(DRAG_PREFIX)),
    );

    const dragEventsSubscription = dragEvents.subscribe((obj) => {
      if (obj.key === DRAG_START) {
        setShouldDisplayPreview(false);
      } else if (obj.key === DRAG_END) {
        setShouldDisplayPreview(true);
      }
    });
    return () => dragEventsSubscription.unsubscribe();
  }, []);
  return (
    <div className="flex-1 overflow-auto flex flex-col">
      <div className="text-md flex-none text-text-primary font-medium h-12  flex items-center px-4">
        Transitions
      </div>
      <ScrollArea>
        <div className="grid grid-cols-3 gap-2 px-4">
          {TRANSITIONS.map((transition, index) => (
            <TransitionsMenuItem
              key={index}
              transition={transition}
              shouldDisplayPreview={shouldDisplayPreview}
            />
          ))}
        </div>
      </ScrollArea>
    </div>
  );
};

const TransitionsMenuItem = ({
  transition,
  shouldDisplayPreview,
}: {
  transition: Partial<ITransition>;
  shouldDisplayPreview: boolean;
}) => {
  const style = React.useMemo(
    () => ({
      backgroundImage: `url(${transition.preview})`,
      backgroundSize: 'cover',
      width: '70px',
      height: '70px',
    }),
    [transition.preview],
  );

  return (
    <Draggable
      data={transition}
      renderCustomPreview={<div style={style} className="draggable" />}
      shouldDisplayPreview={shouldDisplayPreview}
    >
      <div>
        <div>
          <div
            //  ref={divRef}
            style={style}
            className="draggable"
          />
        </div>
        <div className="text-muted-foreground text-[12px] text-nowrap overflow-ellipsis h-6 flex items-center capitalize">
          {transition.name || transition.type}
        </div>
      </div>
    </Draggable>
  );
};

export default TransitionsMenuItem;