File tree Expand file tree Collapse file tree 1 file changed +17
-4
lines changed
Expand file tree Collapse file tree 1 file changed +17
-4
lines changed Original file line number Diff line number Diff line change 11import { useEffect } from 'react'
2+ import { getItemFromStorage } from '../helper/getItemFromStorage'
23import { getProfilePicture } from '../helper/getProfilePicture'
4+ import { setItemInStorage } from '../helper/setItemInStorage'
35
46export const useFetchImageUrl = (
57 setImageUrl : ( value : React . SetStateAction < string > ) => void ,
@@ -8,11 +10,22 @@ export const useFetchImageUrl = (
810 useEffect ( ( ) => {
911 const fetchImageUrl = async ( ) => {
1012 try {
11- const data = await getProfilePicture ( user_id || '' )
12- if ( ! data ) {
13- throw new Error ( )
13+ const parsedData = getItemFromStorage ( )
14+ const profilePictures = parsedData . profile_pictures || { }
15+
16+ if ( profilePictures [ user_id ] ) {
17+ setImageUrl ( profilePictures [ user_id ] )
1418 } else {
15- setImageUrl ( data )
19+ const url = await getProfilePicture ( user_id )
20+ if ( ! url ) {
21+ throw new Error ( )
22+ } else {
23+ setImageUrl ( url )
24+ const parsed = getItemFromStorage ( )
25+ const pictures = parsed . profile_pictures || { }
26+ pictures [ user_id ] = url
27+ setItemInStorage ( 'profile_pictures' , pictures )
28+ }
1629 }
1730 } catch ( error : any ) { }
1831 }
You can’t perform that action at this time.
0 commit comments