@@ -19,102 +19,111 @@ import { UserShare } from '@components/user/user-share';
19
19
import type { LayoutProps } from './common-layout' ;
20
20
21
21
export function UserHomeLayout ( { children } : LayoutProps ) : JSX . Element {
22
- const { user, isAdmin } = useAuth ( ) ;
23
- const { user : userData , loading } = useUser ( ) ;
24
- const { push } = useRouter ( ) ;
22
+ const { user, isAdmin } = useAuth ( ) ;
23
+ const { user : userData , loading } = useUser ( ) ;
24
+ const { push } = useRouter ( ) ;
25
25
26
- const {
27
- query : { id }
28
- } = useRouter ( ) ;
26
+ const {
27
+ query : { id }
28
+ } = useRouter ( ) ;
29
29
30
- const coverData = userData ?. coverPhotoURL
31
- ? { src : userData . coverPhotoURL , alt : userData . name }
32
- : null ;
30
+ const coverData = userData ?. coverPhotoURL
31
+ ? { src : userData . coverPhotoURL , alt : userData . name }
32
+ : null ;
33
33
34
- const profileData = userData
35
- ? { src : userData . photoURL , alt : userData . name }
36
- : null ;
34
+ const profileData = userData
35
+ ? { src : userData . photoURL , alt : userData . name }
36
+ : null ;
37
37
38
- const { id : userId } = user ?? { } ;
38
+ const { id : userId } = user ?? { } ;
39
39
40
- const isOwner = userData ?. id === userId ;
40
+ const isOwner = userData ?. id === userId ;
41
41
42
- const handleMessage = async ( ) : Promise < void > => {
43
- if ( ! user || ! userData ) return ;
44
-
45
- try {
46
- const chatId = await getOrCreateDirectChat ( user . id , userData . id ) ;
47
- await push ( `/chat?chatId=${ chatId } ` ) ;
48
- } catch ( error ) {
49
- console . error ( 'Error creating chat:' , error ) ;
50
- }
51
- } ;
42
+ const handleMessage = async ( ) : Promise < void > => {
43
+ if ( ! user || ! userData ) return ;
52
44
53
- return (
54
- < >
55
- { userData && (
56
- < SEO
57
- title = { `${ `${ userData . name } (@${ userData . username } )` } / Twitter` }
58
- />
59
- ) }
60
- < motion . section { ...variants } exit = { undefined } >
61
- { loading ? (
62
- < Loading className = 'mt-5' />
63
- ) : ! userData ? (
64
- < >
65
- < UserHomeCover />
66
- < div className = 'flex flex-col gap-8' >
67
- < div className = 'relative flex flex-col gap-3 px-4 py-3' >
68
- < UserHomeAvatar />
69
- < p className = 'text-xl font-bold' > @{ id } </ p >
70
- </ div >
71
- < div className = 'p-8 text-center' >
72
- < p className = 'text-3xl font-bold' > This account doesn't exist</ p >
73
- < p className = 'text-light-secondary dark:text-dark-secondary' >
74
- Try searching for another.
75
- </ p >
76
- </ div >
77
- </ div >
78
- </ >
79
- ) : (
80
- < >
81
- < UserHomeCover coverData = { coverData } />
82
- < div className = 'relative flex flex-col gap-3 px-4 py-3' >
83
- < div className = 'flex justify-between' >
84
- < UserHomeAvatar profileData = { profileData } />
85
- { isOwner ? (
86
- < UserEditProfile />
45
+ try {
46
+ const chatId = await getOrCreateDirectChat ( user . id , userData . id ) ;
47
+ await push ( `/chat?chatId=${ chatId } ` ) ;
48
+ } catch ( error ) {
49
+ console . error ( 'Error creating chat:' , error ) ;
50
+ }
51
+ } ;
52
+
53
+ return (
54
+ < >
55
+ { userData && (
56
+ < SEO
57
+ title = { `${ `${ userData . name } (@${ userData . username } )` } / Twitter` }
58
+ />
59
+ ) }
60
+ < motion . section { ...variants } exit = { undefined } >
61
+ { loading ? (
62
+ < Loading className = 'mt-5' />
63
+ ) : ! userData ? (
64
+ < >
65
+ < UserHomeCover />
66
+ < div className = 'flex flex-col gap-8' >
67
+ < div className = 'relative flex flex-col gap-3 px-4 py-3' >
68
+ < UserHomeAvatar />
69
+ < p className = 'text-xl font-bold' > @{ id } </ p >
70
+ </ div >
71
+ < div className = 'p-8 text-center' >
72
+ < p className = 'text-3xl font-bold' >
73
+ This account doesn't exist
74
+ </ p >
75
+ < p className = 'text-light-secondary dark:text-dark-secondary' >
76
+ Try searching for another.
77
+ </ p >
78
+ </ div >
79
+ </ div >
80
+ </ >
87
81
) : (
88
- < div className = 'flex gap-2 self-start' >
89
- < UserShare username = { userData . username } />
90
- < Button
91
- className = 'dark-bg-tab group relative border border-light-line-reply p-2
92
- hover:bg-light-primary/10 active:bg-light-primary/20 dark:border-light-secondary
82
+ < >
83
+ < UserHomeCover coverData = { coverData } />
84
+ < div className = 'relative flex flex-col gap-3 px-4 py-3' >
85
+ < div className = 'flex justify-between' >
86
+ < UserHomeAvatar profileData = { profileData } />
87
+ { isOwner ? (
88
+ < UserEditProfile />
89
+ ) : (
90
+ < div className = 'flex gap-2 self-start' >
91
+ < UserShare
92
+ username = { userData . username }
93
+ />
94
+ < Button
95
+ className = 'dark-bg-tab group relative border border-light-line-reply p-2
96
+ hover:bg-light-primary/10 active:bg-light-primary/20 dark:border-light-secondary
93
97
dark:hover:bg-dark-primary/10 dark:active:bg-dark-primary/20'
94
- onClick = { handleMessage }
95
- >
96
- < HeroIcon className = 'h-5 w-5' iconName = 'EnvelopeIcon' />
97
- < ToolTip tip = 'Message' />
98
- </ Button >
99
- < FollowButton
100
- userTargetId = { userData . id }
101
- userTargetUsername = { userData . username }
102
- />
103
- { isAdmin && < UserEditProfile hide /> }
104
- </ div >
98
+ onClick = { handleMessage }
99
+ >
100
+ < HeroIcon
101
+ className = 'h-5 w-5'
102
+ iconName = 'EnvelopeIcon'
103
+ />
104
+ < ToolTip tip = 'Message' />
105
+ </ Button >
106
+ < FollowButton
107
+ userTargetId = { userData . id }
108
+ userTargetUsername = {
109
+ userData . username
110
+ }
111
+ />
112
+ { isAdmin && < UserEditProfile hide /> }
113
+ </ div >
114
+ ) }
115
+ </ div >
116
+ < UserDetails { ...userData } />
117
+ </ div >
118
+ </ >
105
119
) }
106
- </ div >
107
- < UserDetails { ...userData } />
108
- </ div >
109
- </ >
110
- ) }
111
- </ motion . section >
112
- { userData && (
113
- < >
114
- < UserNav />
115
- { children }
120
+ </ motion . section >
121
+ { userData && (
122
+ < >
123
+ < UserNav />
124
+ { children }
125
+ </ >
126
+ ) }
116
127
</ >
117
- ) }
118
- </ >
119
- ) ;
128
+ ) ;
120
129
}
0 commit comments