File size: 1,549 Bytes
f42b4a1
ac7030c
8f2b05f
 
 
 
 
 
 
 
 
f8ca042
8f2b05f
ac7030c
8f2b05f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ac7030c
f8ca042
 
8f2b05f
 
 
 
 
 
 
 
38d787b
8f2b05f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f8ca042
8f2b05f
 
 
 
 
 
 
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
import { cn } from "@/lib/utils/cn"
import { MediaDisplayLayout, MediaInfo } from "@/types/general"
import { TrackCard } from "../track-card"
import { VideoCard } from "../video-card"

export function MediaList({
  items,
  type = "video",
  layout = "grid",
  className = "",
  onSelect,
  selectedId,
}: {
  items: MediaInfo[]

  /**
   * Layout mode
   * 
   * This isn't necessarily based on screen size, it can also be:
   * - based on the device type (eg. a smart TV)
   * - a design choice for a particular page
   */
  layout?: MediaDisplayLayout

  /**
   * Content type
   * 
   * Used to change the way we display elements
   */
  type?: "video" | "track"

  className?: string

  onSelect?: (media: MediaInfo) => void

  selectedId?: string
}) {
  
  return (
    <div
      className={cn(
        layout === "table"
          ? `flex flex-col` :
        layout === "grid"
          ? `grid grid-cols-1 gap-x-4 gap-y-5 sm:grid-cols-2 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4` :
        layout === "vertical"
          ? `grid grid-cols-1 gap-2`
          : `flex flex-col md:flex-row space-y-4 md:space-y-0 md:space-x-4`,
        className,
      )}
    >
    {items.map((media, i) => {
      const Component = type === "track" ? TrackCard : VideoCard
    
      return (
        <Component
          key={media.id}
          media={media}
          className="w-full"
          layout={layout}
          onSelect={onSelect}
          selected={selectedId === media.id}
          index={i}
        />
      )
    })}
    </div>
  )
}