aboutsummaryrefslogtreecommitdiff
path: root/src/utils/users.ts
diff options
context:
space:
mode:
authorLeon Jiang <35908040+leonyjiang@users.noreply.github.com>2021-03-10 22:59:36 -0500
committerLeon Jiang <35908040+leonyjiang@users.noreply.github.com>2021-03-10 22:59:36 -0500
commit603b6e1e7afe464538aa1ab1b6ec9f892266d01b (patch)
treee22fc1ee0e6b7551a55ee0a7376b33ce49e4f885 /src/utils/users.ts
parent1d86e3dc7af3f5fc8f8269257b6d4d23836986e9 (diff)
Refactor utils
Diffstat (limited to 'src/utils/users.ts')
-rw-r--r--src/utils/users.ts114
1 files changed, 0 insertions, 114 deletions
diff --git a/src/utils/users.ts b/src/utils/users.ts
index 3e0d9eef..af4f3813 100644
--- a/src/utils/users.ts
+++ b/src/utils/users.ts
@@ -166,117 +166,3 @@ export const defaultUserProfile = () => {
return defaultImage;
};
-/*
- * AsyncStorage key for list of recently-searched users.
- */
-const recentlySearchedUsersKey = '@recently_searched_users';
-
-/*
- * Stores `user` in AsyncStorage as a recently-searched user.
- */
-export const addUserToRecentlySearched = async (user: ProfilePreviewType) => {
- let users: ProfilePreviewType[];
- // retrieve and update recently-searched categories list
- try {
- const usersJSON = await AsyncStorage.getItem(recentlySearchedUsersKey);
- if (usersJSON) {
- users = JSON.parse(usersJSON);
- // if category already exists, move it to the end
- for (let i = 0; i < users.length; i++) {
- // TODO: speed up comparison by adding some id field to category
- if (users[i].id === user.id) {
- users.splice(i, 1);
- break;
- }
- }
- users.push(user);
- } else {
- users = [user];
- }
- // store updated list of recently-searched categories
- try {
- AsyncStorage.setItem(recentlySearchedUsersKey, JSON.stringify(users));
- } catch (e) {
- console.log(e);
- }
- } catch (e) {
- console.log(e);
- }
-};
-
-/*
- * Retrieves and returns user's recently-searched categories from AsyncStorage.
- */
-export const getRecentlySearchedUsers = async (): Promise<
- ProfilePreviewType[]
-> => {
- try {
- const usersJSON = await AsyncStorage.getItem(recentlySearchedUsersKey);
- if (usersJSON) return JSON.parse(usersJSON);
- } catch (e) {
- console.log(e);
- }
- return [];
-};
-
-/*
- * AsyncStorage key for list of recently-searched categories.
- */
-const recentlySearchedCategoriesKey = '@recently_searched_categories';
-
-/*
- * Stores `category` in AsyncStorage as a recently-searched category.
- */
-export const addCategoryToRecentlySearched = async (
- category: CategoryPreviewType,
-) => {
- let categories: CategoryPreviewType[];
- // retrieve and update recently-searched categories list
- try {
- const categoriesJSON = await AsyncStorage.getItem(
- recentlySearchedCategoriesKey,
- );
- if (categoriesJSON) {
- categories = JSON.parse(categoriesJSON);
- // if category already exists, move it to the end
- for (let i = 0; i < categories.length; i++) {
- // TODO: speed up comparison by adding some id field to category
- if (categories[i].name === category.name) {
- categories.splice(i, 1);
- break;
- }
- }
- categories.push(category);
- } else {
- categories = [category];
- }
- // store updated list of recently-searched categories
- try {
- AsyncStorage.setItem(
- recentlySearchedCategoriesKey,
- JSON.stringify(categories),
- );
- } catch (e) {
- console.log(e);
- }
- } catch (e) {
- console.log(e);
- }
-};
-
-/*
- * Retrieves and returns user's recently-searched categories from AsyncStorage.
- */
-export const getRecentlySearchedCategories = async (): Promise<
- CategoryPreviewType[]
-> => {
- try {
- const categoriesJSON = await AsyncStorage.getItem(
- '@recently_searched_categories',
- );
- if (categoriesJSON) return JSON.parse(categoriesJSON);
- } catch (e) {
- console.log(e);
- }
- return [];
-};