diff options
author | Eric Bailey <git@esb.lol> | 2024-06-18 12:59:50 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-18 12:59:50 -0500 |
commit | 11065174813a322e5a53097c0ea309fd8e613cc7 (patch) | |
tree | d3be1dcd982fa16f09ee6ada6a037cc4e3cb1a10 /src/components/NewskieDialog.tsx | |
parent | 73c9de3ce27a379b9d57550a8dcc13e251a4e60e (diff) | |
download | voidsky-11065174813a322e5a53097c0ea309fd8e613cc7.tar.zst |
Is it "newskie" or "newsky" 🤔 (#4557)
* add newskie icon (cherry picked from commit 152e074ee053e076bf644e368047e486a5ad127c) (cherry picked from commit 8d2326f115c9c9d32aa1c41259bb81936b3868aa) * add size prop (cherry picked from commit af09ae2d8f4fedf8a50993e94b76efc44a2ef4ea) (cherry picked from commit 38dd38451bcce8afcf302ad1180802640857722a) * add a dialog for newskies to profiles (cherry picked from commit fe16f55e9c5e8faef540b563662b0c0c9a1d2d77) (cherry picked from commit c5b9f1b16ace276f422832069db076a5360616fe) * move newskie to handle (cherry picked from commit 150f2635b278a92ed67dcec748333b428aacb670) (cherry picked from commit 1efaaf835380f4e76d2e4b7fe8b727a92731a794) * use "say hello" in newskie dialog (cherry picked from commit d9a286cfc823a9e697061de84dd317625741a862) (cherry picked from commit 018dd1739fee68906dec63e05519f5ca9ae73910) * tweaks (cherry picked from commit 070363c947600c48368b01c776ea34fbf422f81e) (cherry picked from commit c30855d4ff311e31fb6ae357a9d6cd1662b291d5) * Tweaks * Re-export newskie icon * Design tweaks * Tweaks * Add source icon * Remove unused file * Remove unneeded edits * Simplify logic * Update source * Moderate displayName, fix createdAt type --------- Co-authored-by: Hailey <me@haileyok.com>
Diffstat (limited to 'src/components/NewskieDialog.tsx')
-rw-r--r-- | src/components/NewskieDialog.tsx | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/src/components/NewskieDialog.tsx b/src/components/NewskieDialog.tsx new file mode 100644 index 000000000..fcdae0daa --- /dev/null +++ b/src/components/NewskieDialog.tsx @@ -0,0 +1,81 @@ +import React from 'react' +import {View} from 'react-native' +import {AppBskyActorDefs, moderateProfile} from '@atproto/api' +import {msg, Trans} from '@lingui/macro' +import {useLingui} from '@lingui/react' +import {differenceInSeconds} from 'date-fns' + +import {useGetTimeAgo} from '#/lib/hooks/useTimeAgo' +import {useModerationOpts} from '#/state/preferences/moderation-opts' +import {HITSLOP_10} from 'lib/constants' +import {sanitizeDisplayName} from 'lib/strings/display-names' +import {atoms as a} from '#/alf' +import {Button} from '#/components/Button' +import * as Dialog from '#/components/Dialog' +import {useDialogControl} from '#/components/Dialog' +import {Newskie} from '#/components/icons/Newskie' +import {Text} from '#/components/Typography' + +export function NewskieDialog({ + profile, +}: { + profile: AppBskyActorDefs.ProfileViewDetailed +}) { + const {_} = useLingui() + const moderationOpts = useModerationOpts() + const control = useDialogControl() + const profileName = React.useMemo(() => { + const name = profile.displayName || profile.handle + if (!moderationOpts) return name + const moderation = moderateProfile(profile, moderationOpts) + return sanitizeDisplayName(name, moderation.ui('displayName')) + }, [moderationOpts, profile]) + const timeAgo = useGetTimeAgo() + const createdAt = profile.createdAt as string | undefined + const daysOld = React.useMemo(() => { + if (!createdAt) return Infinity + return differenceInSeconds(new Date(), new Date(createdAt)) / 86400 + }, [createdAt]) + + if (!createdAt || daysOld > 7) return null + + return ( + <View style={[a.pr_2xs]}> + <Button + label={_( + msg`This user is new here. Press for more info about when they joined.`, + )} + hitSlop={HITSLOP_10} + onPress={control.open}> + {({hovered, pressed}) => ( + <Newskie + size="lg" + fill="#FFC404" + style={{ + opacity: hovered || pressed ? 0.5 : 1, + }} + /> + )} + </Button> + + <Dialog.Outer control={control}> + <Dialog.Handle /> + <Dialog.ScrollableInner + label={_(msg`New user info dialog`)} + style={[{width: 'auto', maxWidth: 400, minWidth: 200}]}> + <View style={[a.gap_sm]}> + <Text style={[a.font_bold, a.text_xl]}> + <Trans>Say hello!</Trans> + </Text> + <Text style={[a.text_md]}> + <Trans> + {profileName} joined Bluesky{' '} + {timeAgo(createdAt, {format: 'long'})} ago + </Trans> + </Text> + </View> + </Dialog.ScrollableInner> + </Dialog.Outer> + </View> + ) +} |