1
- import React from 'react'
1
+ import { useMemo , useState } from 'react'
2
2
import { View } from 'react-native'
3
3
import { type AppBskyActorDefs , moderateProfile } from '@atproto/api'
4
4
import { msg , Trans } from '@lingui/macro'
@@ -27,30 +27,12 @@ export function NewskieDialog({
27
27
disabled ?: boolean
28
28
} ) {
29
29
const { _} = useLingui ( )
30
- const t = useTheme ( )
31
- const moderationOpts = useModerationOpts ( )
32
- const { currentAccount} = useSession ( )
33
- const timeAgo = useGetTimeAgo ( )
34
30
const control = useDialogControl ( )
35
31
36
- const isMe = profile . did === currentAccount ?. did
37
32
const createdAt = profile . createdAt as string | undefined
38
33
39
- const profileName = React . useMemo ( ( ) => {
40
- const name = profile . displayName || profile . handle
41
-
42
- if ( isMe ) {
43
- return _ ( msg `You` )
44
- }
45
-
46
- if ( ! moderationOpts ) return name
47
- const moderation = moderateProfile ( profile , moderationOpts )
48
-
49
- return sanitizeDisplayName ( name , moderation . ui ( 'displayName' ) )
50
- } , [ _ , isMe , moderationOpts , profile ] )
51
-
52
- const [ now ] = React . useState ( ( ) => Date . now ( ) )
53
- const daysOld = React . useMemo ( ( ) => {
34
+ const [ now ] = useState ( ( ) => Date . now ( ) )
35
+ const daysOld = useMemo ( ( ) => {
54
36
if ( ! createdAt ) return Infinity
55
37
return differenceInSeconds ( now , new Date ( createdAt ) ) / 86400
56
38
} , [ createdAt , now ] )
@@ -77,88 +59,116 @@ export function NewskieDialog({
77
59
) }
78
60
</ Button >
79
61
80
- < Dialog . Outer control = { control } >
62
+ < Dialog . Outer control = { control } nativeOptions = { { preventExpansion : true } } >
81
63
< Dialog . Handle />
82
- < Dialog . ScrollableInner
83
- label = { _ ( msg `New user info dialog` ) }
84
- style = { web ( { width : 'auto' , maxWidth : 400 , minWidth : 200 } ) } >
85
- < View style = { [ a . gap_md ] } >
86
- < View style = { [ a . align_center ] } >
87
- < View
88
- style = { [
89
- {
90
- height : 60 ,
91
- width : 64 ,
92
- } ,
93
- ] } >
94
- < Newskie
95
- width = { 64 }
96
- height = { 64 }
97
- fill = "#FFC404"
98
- style = { [ a . absolute , a . inset_0 ] }
99
- />
100
- </ View >
101
- < Text style = { [ a . font_bold , a . text_xl ] } >
102
- { isMe ? (
103
- < Trans > Welcome, friend!</ Trans >
104
- ) : (
105
- < Trans > Say hello!</ Trans >
106
- ) }
107
- </ Text >
108
- </ View >
109
- < Text style = { [ a . text_md , a . text_center , a . leading_snug ] } >
110
- { profile . joinedViaStarterPack ? (
111
- < Trans >
112
- { profileName } joined Bluesky using a starter pack{ ' ' }
113
- { timeAgo ( createdAt , now , { format : 'long' } ) } ago
114
- </ Trans >
115
- ) : (
116
- < Trans >
117
- { profileName } joined Bluesky{ ' ' }
118
- { timeAgo ( createdAt , now , { format : 'long' } ) } ago
119
- </ Trans >
120
- ) }
121
- </ Text >
122
- { profile . joinedViaStarterPack ? (
123
- < StarterPackCard . Link
124
- starterPack = { profile . joinedViaStarterPack }
125
- onPress = { ( ) => {
126
- control . close ( )
127
- } } >
128
- < View
129
- style = { [
130
- a . w_full ,
131
- a . mt_sm ,
132
- a . p_lg ,
133
- a . border ,
134
- a . rounded_sm ,
135
- t . atoms . border_contrast_low ,
136
- ] } >
137
- < StarterPackCard . Card
138
- starterPack = { profile . joinedViaStarterPack }
139
- />
140
- </ View >
141
- </ StarterPackCard . Link >
142
- ) : null }
64
+ < DialogInner profile = { profile } createdAt = { createdAt } now = { now } />
65
+ </ Dialog . Outer >
66
+ </ View >
67
+ )
68
+ }
143
69
144
- { isNative && (
145
- < Button
146
- label = { _ ( msg `Close` ) }
147
- variant = "solid"
148
- color = "secondary"
149
- size = "small"
150
- style = { [ a . mt_sm ] }
151
- onPress = { ( ) => control . close ( ) } >
152
- < ButtonText >
153
- < Trans > Close</ Trans >
154
- </ ButtonText >
155
- </ Button >
156
- ) }
70
+ function DialogInner ( {
71
+ profile,
72
+ createdAt,
73
+ now,
74
+ } : {
75
+ profile : AppBskyActorDefs . ProfileViewDetailed
76
+ createdAt : string
77
+ now : number
78
+ } ) {
79
+ const control = Dialog . useDialogContext ( )
80
+ const { _} = useLingui ( )
81
+ const t = useTheme ( )
82
+ const moderationOpts = useModerationOpts ( )
83
+ const { currentAccount} = useSession ( )
84
+ const timeAgo = useGetTimeAgo ( )
85
+ const isMe = profile . did === currentAccount ?. did
86
+
87
+ const profileName = useMemo ( ( ) => {
88
+ const name = profile . displayName || profile . handle
89
+
90
+ if ( isMe ) {
91
+ return _ ( msg `You` )
92
+ }
93
+
94
+ if ( ! moderationOpts ) return name
95
+ const moderation = moderateProfile ( profile , moderationOpts )
96
+
97
+ return sanitizeDisplayName ( name , moderation . ui ( 'displayName' ) )
98
+ } , [ _ , isMe , moderationOpts , profile ] )
99
+
100
+ return (
101
+ < Dialog . ScrollableInner
102
+ label = { _ ( msg `New user info dialog` ) }
103
+ style = { web ( { maxWidth : 400 } ) } >
104
+ < View style = { [ a . gap_md ] } >
105
+ < View style = { [ a . align_center ] } >
106
+ < View
107
+ style = { [
108
+ {
109
+ height : 60 ,
110
+ width : 64 ,
111
+ } ,
112
+ ] } >
113
+ < Newskie
114
+ width = { 64 }
115
+ height = { 64 }
116
+ fill = "#FFC404"
117
+ style = { [ a . absolute , a . inset_0 ] }
118
+ />
157
119
</ View >
120
+ < Text style = { [ a . font_bold , a . text_xl ] } >
121
+ { isMe ? < Trans > Welcome, friend!</ Trans > : < Trans > Say hello!</ Trans > }
122
+ </ Text >
123
+ </ View >
124
+ < Text style = { [ a . text_md , a . text_center , a . leading_snug ] } >
125
+ { profile . joinedViaStarterPack ? (
126
+ < Trans >
127
+ { profileName } joined Bluesky using a starter pack{ ' ' }
128
+ { timeAgo ( createdAt , now , { format : 'long' } ) } ago
129
+ </ Trans >
130
+ ) : (
131
+ < Trans >
132
+ { profileName } joined Bluesky{ ' ' }
133
+ { timeAgo ( createdAt , now , { format : 'long' } ) } ago
134
+ </ Trans >
135
+ ) }
136
+ </ Text >
137
+ { profile . joinedViaStarterPack ? (
138
+ < StarterPackCard . Link
139
+ starterPack = { profile . joinedViaStarterPack }
140
+ onPress = { ( ) => control . close ( ) } >
141
+ < View
142
+ style = { [
143
+ a . w_full ,
144
+ a . mt_sm ,
145
+ a . p_lg ,
146
+ a . border ,
147
+ a . rounded_sm ,
148
+ t . atoms . border_contrast_low ,
149
+ ] } >
150
+ < StarterPackCard . Card
151
+ starterPack = { profile . joinedViaStarterPack }
152
+ />
153
+ </ View >
154
+ </ StarterPackCard . Link >
155
+ ) : null }
158
156
159
- < Dialog . Close />
160
- </ Dialog . ScrollableInner >
161
- </ Dialog . Outer >
162
- </ View >
157
+ { isNative && (
158
+ < Button
159
+ label = { _ ( msg `Close` ) }
160
+ color = "secondary"
161
+ size = "small"
162
+ style = { [ a . mt_sm ] }
163
+ onPress = { ( ) => control . close ( ) } >
164
+ < ButtonText >
165
+ < Trans > Close</ Trans >
166
+ </ ButtonText >
167
+ </ Button >
168
+ ) }
169
+ </ View >
170
+
171
+ < Dialog . Close />
172
+ </ Dialog . ScrollableInner >
163
173
)
164
174
}
0 commit comments