@@ -2,7 +2,16 @@ import { FC, useContext, useEffect, useState } from 'react'
2
2
import { getProfilePicture } from '../../helper/getProfilePicture'
3
3
4
4
import { getImage } from '../../helper/getImage'
5
- import { ContextScreenWidth } from '../../App'
5
+ import {
6
+ ContextDisableFocusTrap ,
7
+ ContextFilteredStreamData ,
8
+ ContextScreenWidth ,
9
+ ContextSearchResults ,
10
+ ContextSearchText ,
11
+ ContextSEOSearchText ,
12
+ ContextStreamData ,
13
+ } from '../../App'
14
+ import { getSearchFilter } from '../../helper/getSearchFilter'
6
15
7
16
type StreamProfilePictureProps = {
8
17
testid ?: string
@@ -23,6 +32,61 @@ const StreamProfilePicture: FC<StreamProfilePictureProps> = ({
23
32
}
24
33
const [ imageUrl , setImageUrl ] = useState < string > ( '' )
25
34
35
+ const contextStreamData = useContext ( ContextStreamData )
36
+ if ( ! contextStreamData ) {
37
+ throw new Error (
38
+ 'ContextStreamData must be used within a ContextStreamData.Provider'
39
+ )
40
+ }
41
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
42
+ const [ streamData , _setStreamData ] = contextStreamData
43
+
44
+ const contextFilteredStreamData = useContext ( ContextFilteredStreamData )
45
+ if ( ! contextFilteredStreamData ) {
46
+ throw new Error (
47
+ 'ContextFilteredStreamData must be used within a ContextFilteredStreamData.Provider'
48
+ )
49
+ }
50
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
51
+ const [ _filteredStreamData , setFilteredStreamData ] =
52
+ contextFilteredStreamData
53
+
54
+ const contextSearchText = useContext ( ContextSearchText )
55
+ if ( ! contextSearchText ) {
56
+ throw new Error (
57
+ 'ContextSearchText must be used within a ContextSearchText.Provider'
58
+ )
59
+ }
60
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
61
+ const [ _searchText , setSearchText ] = contextSearchText
62
+
63
+ const contextSEOSearchText = useContext ( ContextSEOSearchText )
64
+ if ( ! contextSEOSearchText ) {
65
+ throw new Error (
66
+ 'ContextSEOSearchText must be used within a ContextSEOSearchText.Provider'
67
+ )
68
+ }
69
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
70
+ const [ _seoSearchText , setSEOSearchText ] = contextSEOSearchText
71
+
72
+ const contextDisableFocusTrap = useContext ( ContextDisableFocusTrap )
73
+ if ( ! contextDisableFocusTrap ) {
74
+ throw new Error (
75
+ 'ContextDisableFocusTrap must be used within a ContextDisableFocusTrap.Provider'
76
+ )
77
+ }
78
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
79
+ const [ _focusTrapDisabled , setFocusTrapDisabled ] = contextDisableFocusTrap
80
+
81
+ const contextSearchResults = useContext ( ContextSearchResults )
82
+ if ( ! contextSearchResults ) {
83
+ throw new Error (
84
+ 'ContextSearchResults must be used within a ContextSearchResults.Provider'
85
+ )
86
+ }
87
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
88
+ const [ _searchResults , setSearchResults ] = contextSearchResults
89
+
26
90
useEffect ( ( ) => {
27
91
const fetchImageUrl = async ( ) => {
28
92
try {
@@ -37,6 +101,16 @@ const StreamProfilePicture: FC<StreamProfilePictureProps> = ({
37
101
return ( ) => { }
38
102
} , [ user_id ] )
39
103
104
+ const handleClick = ( ) => {
105
+ setFilteredStreamData ( {
106
+ data : getSearchFilter ( user_name , streamData , true ) ! ,
107
+ } )
108
+ setSearchText ( user_name )
109
+ setSEOSearchText ( user_name )
110
+ setFocusTrapDisabled ( true )
111
+ setSearchResults ( [ ] )
112
+ }
113
+
40
114
const imageWidth = ( ( ) => {
41
115
switch ( contextScreenWidth ) {
42
116
case 'MOBILE' :
@@ -50,15 +124,21 @@ const StreamProfilePicture: FC<StreamProfilePictureProps> = ({
50
124
} ) ( )
51
125
52
126
return (
53
- < img
54
- src = { getImage ( imageUrl , { size : contextScreenWidth } , 'PROFILE' ) }
55
- alt = { user_name }
56
- title = { user_name }
57
- className = "rounded-full col-span-1 mx-auto"
58
- style = { { width : `max(${ imageWidth } px, 80%)` } }
59
- loading = "lazy"
60
- data-testid = { testid }
61
- />
127
+ < button className = "h-fit" onClick = { handleClick } >
128
+ < img
129
+ src = { getImage (
130
+ imageUrl ,
131
+ { size : contextScreenWidth } ,
132
+ 'PROFILE'
133
+ ) }
134
+ alt = { user_name }
135
+ title = { user_name }
136
+ className = "rounded-full col-span-1 mx-auto"
137
+ style = { { width : `max(${ imageWidth } px, 80%)` } }
138
+ loading = "lazy"
139
+ data-testid = { testid }
140
+ />
141
+ </ button >
62
142
)
63
143
}
64
144
0 commit comments