aboutsummaryrefslogtreecommitdiff
path: root/src/utils/users.ts
diff options
context:
space:
mode:
authorShravya Ramesh <37447613+shravyaramesh@users.noreply.github.com>2021-03-05 20:33:51 -0800
committerGitHub <noreply@github.com>2021-03-05 20:33:51 -0800
commit27925a267e9d279e29a1a1852891e392fdc4b3af (patch)
treef77ab55bf3f5cbd6190177058353ef01ad767711 /src/utils/users.ts
parent8e4d9135f0645b56665ad23d6de5dd0afa1ef444 (diff)
parent59bc015a22a0c50d6c64ecf7501c269dae59bfbd (diff)
Merge branch 'master' into badges-people-screen
Diffstat (limited to 'src/utils/users.ts')
-rw-r--r--src/utils/users.ts37
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);
+ }
+};