diff options
Diffstat (limited to 'app/assets/javascripts/frequent_items/utils.js')
-rw-r--r-- | app/assets/javascripts/frequent_items/utils.js | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/app/assets/javascripts/frequent_items/utils.js b/app/assets/javascripts/frequent_items/utils.js index 88519d934cb..27ef47df8c8 100644 --- a/app/assets/javascripts/frequent_items/utils.js +++ b/app/assets/javascripts/frequent_items/utils.js @@ -35,13 +35,15 @@ export const getTopFrequentItems = (items) => { }; export const updateExistingFrequentItem = (frequentItem, item) => { - const accessedOverHourAgo = - Math.abs(item.lastAccessedOn - frequentItem.lastAccessedOn) / HOUR_IN_MS > 1; + // `frequentItem` comes from localStorage and it's possible it doesn't have a `lastAccessedOn` + const neverAccessed = !frequentItem.lastAccessedOn; + const shouldUpdate = + neverAccessed || Math.abs(item.lastAccessedOn - frequentItem.lastAccessedOn) / HOUR_IN_MS > 1; return { ...item, - frequency: accessedOverHourAgo ? frequentItem.frequency + 1 : frequentItem.frequency, - lastAccessedOn: accessedOverHourAgo ? Date.now() : frequentItem.lastAccessedOn, + frequency: shouldUpdate ? frequentItem.frequency + 1 : frequentItem.frequency, + lastAccessedOn: shouldUpdate ? Date.now() : frequentItem.lastAccessedOn, }; }; |