Skip to content

Commit 63af85d

Browse files
apply logic from channel name to profile picture to make it clickable and filtering for this specific channel
1 parent 190762b commit 63af85d

File tree

1 file changed

+90
-10
lines changed

1 file changed

+90
-10
lines changed

src/components/streamFeed/StreamProfilePicture.tsx

+90-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,16 @@ import { FC, useContext, useEffect, useState } from 'react'
22
import { getProfilePicture } from '../../helper/getProfilePicture'
33

44
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'
615

716
type StreamProfilePictureProps = {
817
testid?: string
@@ -23,6 +32,61 @@ const StreamProfilePicture: FC<StreamProfilePictureProps> = ({
2332
}
2433
const [imageUrl, setImageUrl] = useState<string>('')
2534

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+
2690
useEffect(() => {
2791
const fetchImageUrl = async () => {
2892
try {
@@ -37,6 +101,16 @@ const StreamProfilePicture: FC<StreamProfilePictureProps> = ({
37101
return () => {}
38102
}, [user_id])
39103

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+
40114
const imageWidth = (() => {
41115
switch (contextScreenWidth) {
42116
case 'MOBILE':
@@ -50,15 +124,21 @@ const StreamProfilePicture: FC<StreamProfilePictureProps> = ({
50124
})()
51125

52126
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>
62142
)
63143
}
64144

0 commit comments

Comments
 (0)