homeflowjs 1.0.34 → 1.0.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/app/user-history.js +20 -18
  2. package/package.json +1 -1
@@ -1,36 +1,38 @@
1
1
  export const addSearchToLocalStorage = (search) => {
2
- // Get search history from local storage
3
- let searchHistory = localStorage.getItem('searchHistory');
4
- searchHistory = searchHistory ? JSON.parse(searchHistory) : [];
2
+ // <search> format: {channel: 'sales'}
3
+
4
+ // Get search history from local storage.
5
+ // <searchHistory> format: [{channel: 'sales'}, {channel: 'sales'}]
6
+ const searchHistory = JSON.parse(localStorage.getItem?.('searchHistory') || null) || [];
7
+
8
+ // Get current page number from Homeflow state.
9
+ const pageNumber = Homeflow.getState?.().properties?.pagination?.current_page;
5
10
 
6
11
  // Make a new instance of the search object without the page number.
7
- const searchWithoutPageNumber = { ...search, page: null };
12
+ const searchWithoutPageNumberString = JSON.stringify({ ...search, page: null });
8
13
 
9
14
  // Make a new instance of the last search object without the page number.
10
- const lastSearchWithoutPageNumber = { ...searchHistory[0], page: null };
15
+ const lastSearchWithoutPageNumberString = JSON.stringify({ ...searchHistory[0], page: null });
11
16
 
12
17
  /**
13
- * If the searchWithoutPageNumber and lastSearchWithoutPageNumber match,
18
+ * If the searchWithoutPageNumberString and lastSearchWithoutPageNumberString match,
14
19
  * just update the the last search in local storage to have the search's page number if
15
20
  * it has one.
16
21
  */
17
- if ((JSON.stringify(searchWithoutPageNumber) === JSON.stringify(lastSearchWithoutPageNumber))
18
- && search?.page) {
19
- const lastSearchWithUpdatedPageNumber = { ...searchHistory[0], page: search.page };
20
- searchHistory.shift();
21
- searchHistory.unshift(lastSearchWithUpdatedPageNumber);
22
- localStorage.setItem('searchHistory', JSON.stringify(searchHistory));
22
+ if ((searchWithoutPageNumberString === lastSearchWithoutPageNumberString) && pageNumber) {
23
+ searchHistory[0].page = pageNumber;
24
+ localStorage.setItem?.('searchHistory', JSON.stringify(searchHistory));
23
25
  }
24
26
 
25
27
  /**
26
28
  * If the search and last search without page numbers don't match add
27
- * the search to local storage
29
+ * the search to local storage.
28
30
  */
29
- if ((JSON.stringify(searchWithoutPageNumber) !== JSON.stringify(lastSearchWithoutPageNumber))) {
30
- // Add the search to the front of the array
31
- searchHistory.unshift(search);
32
- // Only save the 10 most recent searches
33
- localStorage.setItem('searchHistory', JSON.stringify(searchHistory.slice(0, 10)));
31
+ if (searchWithoutPageNumberString !== lastSearchWithoutPageNumberString) {
32
+ // Add <search> to the front of the array and ensure only 10 most recent searches in history.
33
+ localStorage.setItem('searchHistory', JSON.stringify(
34
+ [{ ...search }, ...searchHistory].slice(0, 10),
35
+ ));
34
36
  }
35
37
  };
36
38
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homeflowjs",
3
- "version": "1.0.34",
3
+ "version": "1.0.35",
4
4
  "sideEffects": [
5
5
  "modal/**/*",
6
6
  "user/default-profile/**/*",