aboutsummaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
authorankit-thanekar007 <ankit.thanekar007@gmail.com>2021-03-04 16:06:21 -0800
committerankit-thanekar007 <ankit.thanekar007@gmail.com>2021-03-04 16:06:21 -0800
commit79396f899fe25f611d790d918e8ae4275a61e43c (patch)
treef5c9c003091d3d28ca32b31bb2b1bf8f67892acc /src/utils
parent95bc850b9db986b9f462f19d7801218027307d58 (diff)
TMA-663-Changes for empty view
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/users.ts32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/utils/users.ts b/src/utils/users.ts
index b8faf206..653c941e 100644
--- a/src/utils/users.ts
+++ b/src/utils/users.ts
@@ -164,3 +164,35 @@ 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);
+ }
+};