Something went wrong. Try again.
Mirror — see github.com/blacksky-algorithms/blacksky.community
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414import {View} from 'react-native'import {Image} from 'expo-image'import {msg, plural} from '@lingui/core/macro'import {useLingui} from '@lingui/react'import {Trans} from '@lingui/react/macro'
import {useOpenLink} from '#/lib/hooks/useOpenLink'import {toNiceDomain} from '#/lib/strings/url-helpers'import {logger} from '#/logger'import {useModerationOpts} from '#/state/preferences/moderation-opts'import {useRequireAuth} from '#/state/session'import {UserAvatar} from '#/view/com/util/UserAvatar'import {atoms as a, useTheme} from '#/alf'import {AvatarStack} from '#/components/AvatarStack'import {Button, ButtonText} from '#/components/Button'import {LinearGradientBackground} from '#/components/LinearGradientBackground'import {InlineLinkText} from '#/components/Link'import * as ProfileCard from '#/components/ProfileCard'import * as Toast from '#/components/Toast'import {Text} from '#/components/Typography'import {LiveWatchButton} from '#/features/events/components/LiveWatchButton'import { eventDateParts, eventPhase, formatEventTime,} from '#/features/events/format'import {eventPoster} from '#/features/events/poster'import {useRsvpMutation} from '#/features/events/queries'import {coverUrl, type ParsedEvent} from '#/features/events/record'import { type EventView, RSVP_GOING, RSVP_INTERESTED, RSVP_NOTGOING, type RsvpStatus, type RsvpView,} from '#/features/events/types'import { useEventLive, useWatchStreamplace,} from '#/features/events/useStreamplace'
export function EventHeader({ event, parsed, guests,}: { event: EventView parsed: ParsedEvent guests: RsvpView[]}) { const t = useTheme() const {_, i18n} = useLingui() const openLink = useOpenLink() const watch = useWatchStreamplace() const live = useEventLive(parsed) const date = eventDateParts(parsed, i18n.locale) const localTime = formatEventTime(parsed, i18n.locale)?.local const past = eventPhase(parsed, new Date()) === 'past' const otherLinks = parsed.links.filter( link => link.uri !== parsed.joinUrl && link.uri !== parsed.streamplaceUrl, ) const place = parsed.location ?? (parsed.streamplaceUrl || parsed.mode === 'virtual' ? _(msg`Online`) : undefined)
return ( <View style={[a.pb_xl]}> <LinearGradientBackground gradient="primary" style={[a.absolute, a.inset_0, {height: 220, opacity: 0.35}]} /> <View style={[a.align_center, a.px_lg, a.pt_2xl, a.gap_lg]}> {parsed.cancelled && ( <View style={[ a.rounded_full, a.px_md, a.py_xs, {backgroundColor: t.palette.negative_500}, ]}> <Text style={[a.text_sm, a.font_bold, {color: t.palette.white}]}> <Trans>Cancelled</Trans> </Text> </View> )} <Poster event={event} parsed={parsed} /> <Text style={[ a.text_4xl, a.font_bold, a.text_center, a.leading_tight, {letterSpacing: -0.5}, ]}> {parsed.name} </Text> {date && ( <View style={[a.align_center, a.gap_2xs]}> <Text style={[a.text_lg, a.font_semi_bold, a.text_center]}> {date.longDate} </Text> <Text style={[a.text_md, a.text_center, t.atoms.text_contrast_medium]}> {date.timeRange} </Text> {localTime && ( <Text style={[a.text_sm, a.text_center, t.atoms.text_contrast_low]}> <Trans>{localTime} your time</Trans> </Text> )} </View> )} {place && ( <View style={[ a.flex_row, a.flex_wrap, a.align_center, a.justify_center, a.gap_sm, ]}> <Text style={[ a.flex_shrink, a.text_md, a.text_center, t.atoms.text_contrast_medium, ]}> 📍 {place} </Text> {live && <LiveWatchButton url={parsed.streamplaceUrl!} />} </View> )} {parsed.joinUrl && !parsed.cancelled && !past && ( <Button label={_(msg`Join online at ${toNiceDomain(parsed.joinUrl)}`)} size="large" color="primary" onPress={() => openLink(parsed.joinUrl!, undefined, true)}> <ButtonText> <Trans>Join · {toNiceDomain(parsed.joinUrl)}</Trans> </ButtonText> </Button> )} <View style={[a.flex_row, a.align_center, a.gap_sm]}> <UserAvatar avatar={event.creator.avatar} size={28} type="user" /> <Text style={[a.text_md, t.atoms.text_contrast_medium]}> <Trans> Hosted by{' '} <InlineLinkText label={_(msg`View host's profile`)} to={`/profile/${event.creator.handle || event.creator.did}`} style={[a.text_md, a.font_semi_bold]}> {event.creator.displayName || `@${event.creator.handle}`} </InlineLinkText> </Trans> </Text> </View> {parsed.streamplaceUrl && !live && ( <Button label={_(msg`Watch on Streamplace`)} size="small" color="secondary" onPress={() => watch(parsed.streamplaceUrl!)}> <ButtonText> <Trans>📺 Watch on Streamplace</Trans> </ButtonText> </Button> )} {!parsed.cancelled && !past && <RsvpChoices event={event} />} <Guests event={event} guests={guests} /> </View> {parsed.description && ( <View style={[ a.mx_lg, a.mt_xl, a.p_lg, a.rounded_lg, a.gap_sm, t.atoms.bg_contrast_25, ]}> <Text style={[a.text_md, a.font_bold]}> <Trans>About</Trans> </Text> <Text style={[a.text_md, a.leading_snug]}>{parsed.description}</Text> </View> )} {otherLinks.length > 0 && ( <View style={[ a.mx_lg, a.mt_md, a.p_lg, a.rounded_lg, a.gap_sm, t.atoms.bg_contrast_25, ]}> <Text style={[a.text_md, a.font_bold]}> <Trans>Links</Trans> </Text> {otherLinks.map(link => ( <InlineLinkText key={link.uri} label={link.name || link.uri} to={link.uri} style={[a.text_md]}> {link.name || toNiceDomain(link.uri)} </InlineLinkText> ))} </View> )} <Text style={[a.px_lg, a.pt_xl, a.text_lg, a.font_bold]}> <Trans>Guest list</Trans> </Text> </View> )}
function Poster({event, parsed}: {event: EventView; parsed: ParsedEvent}) { const {_} = useLingui() const size = 280 const cover = coverUrl(event) if (cover) { return ( <Image source={{uri: cover}} alt={_(msg`Cover image for ${parsed.name}`)} accessibilityIgnoresInvertColors style={[a.rounded_lg, {width: size, height: size}]} contentFit="cover" /> ) } const poster = eventPoster(event.uri, parsed) return ( <LinearGradientBackground gradient={poster.gradient} style={[ a.rounded_lg, a.align_center, a.justify_center, {width: size, height: size}, ]}> <Text aria-hidden style={{fontSize: 96}}> {poster.emoji} </Text> </LinearGradientBackground> )}
function RsvpChoices({event}: {event: EventView}) { const t = useTheme() const {_} = useLingui() const requireAuth = useRequireAuth() const {mutate, isPending} = useRsvpMutation(event, 'EventPage') const current = event.viewer?.rsvp?.status const choices: { status: RsvpStatus emoji: string label: string removeLabel: string }[] = [ { status: RSVP_GOING, emoji: '👍', label: _(msg`Going`), removeLabel: _(msg`Going, tap to remove`), }, { status: RSVP_INTERESTED, emoji: '🤔', label: _(msg`Interested`), removeLabel: _(msg`Interested, tap to remove`), }, { status: RSVP_NOTGOING, emoji: '😢', label: _(msg`Not going`), removeLabel: _(msg`Not going, tap to remove`), }, ] const onPress = (status: RsvpStatus) => requireAuth(() => mutate( {status, current: event.viewer?.rsvp}, { onError: error => { logger.error('Failed to update RSVP', {safeMessage: error}) Toast.show(_(msg`Couldn't update your RSVP`), {type: 'error'}) }, }, ), )
return ( <View style={[a.flex_row, a.gap_sm, a.w_full, {maxWidth: 420}]}> {choices.map(choice => { const selected = current === choice.status return ( <Button key={choice.status} label={selected ? choice.removeLabel : choice.label} size="large" color={selected ? 'primary' : 'secondary'} disabled={isPending} style={[a.flex_1, a.flex_col, a.gap_2xs, a.py_md]} onPress={() => onPress(choice.status)}> <Text style={[a.text_2xl]}>{choice.emoji}</Text> <Text style={[ a.text_sm, a.font_semi_bold, selected ? {color: t.palette.white} : t.atoms.text, ]}> {choice.label} </Text> </Button> ) })} </View> )}
function Guests({event, guests}: {event: EventView; guests: RsvpView[]}) { const t = useTheme() if (event.goingCount + event.interestedCount === 0) return null return ( <View style={[a.flex_row, a.align_center, a.gap_sm]}> {guests.length > 0 && ( <AvatarStack profiles={guests.slice(0, 5).map(guest => guest.actor)} size={28} /> )} <Text style={[a.text_md, a.font_semi_bold, t.atoms.text_contrast_high]}> {plural(event.goingCount, {one: '# going', other: '# going'})} {event.interestedCount > 0 ? ` · ${plural(event.interestedCount, { one: '# interested', other: '# interested', })}` : ''} </Text> </View> )}
export function GuestRow({ rsvp, noBorder,}: { rsvp: RsvpView noBorder?: boolean}) { const t = useTheme() const {_} = useLingui() const moderationOpts = useModerationOpts() if (!moderationOpts) return null const response = rsvp.status === RSVP_GOING ? {emoji: '👍', label: _(msg`Going`)} : rsvp.status === RSVP_INTERESTED ? {emoji: '🤔', label: _(msg`Interested`)} : {emoji: '😢', label: _(msg`Not going`)}
return ( <View style={[ a.py_md, a.px_xl, !noBorder && [a.border_t, t.atoms.border_contrast_low], ]}> <ProfileCard.Link profile={rsvp.actor} accessibilityHint={response.label}> <ProfileCard.Outer> <ProfileCard.Header> <ProfileCard.Avatar profile={rsvp.actor} moderationOpts={moderationOpts} /> <ProfileCard.NameAndHandle profile={rsvp.actor} moderationOpts={moderationOpts} /> <View style={[ a.flex_row, a.align_center, a.gap_sm, a.rounded_full, a.px_md, a.py_xs, rsvp.status === RSVP_GOING ? {backgroundColor: t.palette.primary_100} : t.atoms.bg_contrast_50, ]}> <Text aria-hidden style={[a.text_sm]}> {response.emoji} </Text> <Text style={[a.text_sm, a.font_semi_bold]}> {response.label} </Text> </View> </ProfileCard.Header> </ProfileCard.Outer> </ProfileCard.Link> </View> )}