diff options
author | Ivan Chen <ivan@thetaggid.com> | 2021-03-05 16:33:48 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-05 16:33:48 -0500 |
commit | b1dee65ee7bb8e120fc38a495f4027905d300650 (patch) | |
tree | 485ad2d437ded6af4364d72dd7bcba7e5b109849 /src/utils/users.ts | |
parent | f355c91ff5c631da55a29d83b676648b8022a6b3 (diff) | |
parent | 7cc6df961f99d5828f6cbe39c7509e17bae7d93c (diff) |
Merge pull request #279 from ankit-thanekar007/tma-663-updated-search-results
TMA-663-Updated Search Results
Diffstat (limited to 'src/utils/users.ts')
-rw-r--r-- | src/utils/users.ts | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/utils/users.ts b/src/utils/users.ts index ca917ae4..653c941e 100644 --- a/src/utils/users.ts +++ b/src/utils/users.ts @@ -159,3 +159,40 @@ export const checkIfUserIsBlocked = async ( } return await isUserBlocked(userId, loggedInUser.userId, token); }; + +export const defaultUserProfile = () => { + const defaultImage = require('../assets/images/avatar-placeholder.png'); + return defaultImage; +}; + +export const addUserToRecentlyViewed = async (user: ProfilePreviewType) => { + const jsonValue = await AsyncStorage.getItem('@recently_searched_users'); + let recentlySearchedList = jsonValue != null ? JSON.parse(jsonValue) : null; + if (recentlySearchedList) { + if (recentlySearchedList.length > 0) { + if ( + recentlySearchedList.some( + (saved_user: ProfilePreviewType) => saved_user.id === user.id, + ) + ) { + console.log('User already in recently searched.'); + } else { + if (recentlySearchedList.length >= 10) { + recentlySearchedList.pop(); + } + recentlySearchedList.unshift(user); + } + } + } else { + recentlySearchedList = [user]; + } + try { + let recentlySearchedListString = JSON.stringify(recentlySearchedList); + await AsyncStorage.setItem( + '@recently_searched_users', + recentlySearchedListString, + ); + } catch (e) { + console.log(e); + } +}; |