about summary refs log tree commit diff
path: root/bskyogcard/src/components/StarterPack.tsx
blob: 29bb8f32ab5d9787be811db8b741d6e5f483105d (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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/* eslint-disable bsky-internal/avoid-unwrapped-text */
import React from 'react'
import {AppBskyGraphDefs, AppBskyGraphStarterpack} from '@atproto/api'

import {Butterfly} from './Butterfly.js'
import {Img} from './Img.js'

export const STARTERPACK_HEIGHT = 630
export const STARTERPACK_WIDTH = 1200
export const TILE_SIZE = STARTERPACK_HEIGHT / 3

const GRADIENT_TOP = '#0A7AFF'
const GRADIENT_BOTTOM = '#59B9FF'
const IMAGE_STROKE = '#359CFF'

export function StarterPack(props: {
  starterPack: AppBskyGraphDefs.StarterPackView
  images: Map<string, Buffer>
}) {
  const {starterPack, images} = props
  const record = AppBskyGraphStarterpack.isRecord(starterPack.record)
    ? starterPack.record
    : null
  const imagesArray = [...images.values()]
  const imageOfCreator = images.get(starterPack.creator.did)
  const imagesExceptCreator = [...images.entries()]
    .filter(([did]) => did !== starterPack.creator.did)
    .map(([, image]) => image)
  const imagesAcross: Buffer[] = []
  if (imageOfCreator) {
    if (imagesExceptCreator.length >= 6) {
      imagesAcross.push(...imagesExceptCreator.slice(0, 3))
      imagesAcross.push(imageOfCreator)
      imagesAcross.push(...imagesExceptCreator.slice(3, 6))
    } else {
      const firstHalf = Math.floor(imagesExceptCreator.length / 2)
      imagesAcross.push(...imagesExceptCreator.slice(0, firstHalf))
      imagesAcross.push(imageOfCreator)
      imagesAcross.push(
        ...imagesExceptCreator.slice(firstHalf, imagesExceptCreator.length),
      )
    }
  } else {
    imagesAcross.push(...imagesExceptCreator.slice(0, 7))
  }
  const isLongTitle = record ? record.name.length > 30 : false
  return (
    <div
      style={{
        display: 'flex',
        justifyContent: 'center',
        width: STARTERPACK_WIDTH,
        height: STARTERPACK_HEIGHT,
        backgroundColor: 'black',
        color: 'white',
        fontFamily: 'Inter',
      }}>
      {/* image tiles */}
      <div
        style={{
          display: 'flex',
          flexWrap: 'wrap',
          alignItems: 'stretch',
          width: TILE_SIZE * 6,
          height: TILE_SIZE * 3,
        }}>
        {[...Array(18)].map((_, i) => {
          const image = imagesArray.at(i % imagesArray.length)
          return (
            <div
              key={i}
              style={{
                display: 'flex',
                height: TILE_SIZE,
                width: TILE_SIZE,
              }}>
              {image && <Img height="100%" width="100%" src={image} />}
            </div>
          )
        })}
        {/* background overlay */}
        <div
          style={{
            display: 'flex',
            width: '100%',
            height: '100%',
            position: 'absolute',
            backgroundImage: `linear-gradient(to bottom, ${GRADIENT_TOP}, ${GRADIENT_BOTTOM})`,
            opacity: 0.9,
          }}
        />
      </div>
      {/* foreground text & images */}
      <div
        style={{
          display: 'flex',
          alignItems: 'center',
          flexDirection: 'column',
          width: '100%',
          height: '100%',
          position: 'absolute',
          color: 'white',
        }}>
        <div
          style={{
            color: 'white',
            padding: 60,
            fontSize: 40,
          }}>
          JOIN THE CONVERSATION
        </div>
        <div style={{display: 'flex'}}>
          {imagesAcross.map((image, i) => {
            return (
              <div
                key={i}
                style={{
                  display: 'flex',
                  height: 172 + 15 * 2,
                  width: 172 + 15 * 2,
                  margin: -15,
                  border: `15px solid ${IMAGE_STROKE}`,
                  borderRadius: '50%',
                  overflow: 'hidden',
                }}>
                <Img height="100%" width="100%" src={image} />
              </div>
            )
          })}
        </div>
        <div
          style={{
            padding: '75px 30px 0px',
            fontSize: isLongTitle ? 55 : 65,
            display: 'flex',
            textAlign: 'center',
          }}>
          {record?.name || 'Starter Pack'}
        </div>
        <div
          style={{
            display: 'flex',
            fontSize: 40,
            justifyContent: 'center',
            padding: '30px 30px 10px',
          }}>
          on <Butterfly width="65" style={{margin: '-7px 10px 0'}} /> Bluesky
        </div>
      </div>
    </div>
  )
}