| @@ -11,18 +11,22 @@ | ||
| 11 | 11 | }; |
| 12 | 12 | |
| 13 | 13 | const state = (set, get) => ({ |
| 14 | 14 | ...initialState, |
| 15 | - setDomainActivity: ({ domain, position, type = 'primary' }) => { | |
| 16 | - const activities = get().activities; | |
| 15 | + setDomainActivity: ({ | |
| 16 | + domain, | |
| 17 | + position, | |
| 18 | + type = 'primary', | |
| 19 | + action = 'clicked', | |
| 20 | + }) => { | |
| 17 | 21 | set({ |
| 18 | 22 | activities: [ |
| 19 | - ...activities, | |
| 23 | + ...get().activities, | |
| 20 | 24 | { |
| 21 | - domain, | |
| 25 | + domain: domain?.toLowerCase(), | |
| 22 | 26 | position, |
| 23 | 27 | type, |
| 24 | - action: 'clicked', | |
| 28 | + action, | |
| 25 | 29 | date: new Date().toISOString(), |
| 26 | 30 | }, |
| 27 | 31 | ], |
| 28 | 32 | }); |
| @@ -28,13 +32,24 @@ | ||
| 28 | 32 | }); |
| 29 | 33 | }, |
| 30 | 34 | }); |
| 31 | 35 | |
| 36 | +const debounce = (func, delay) => { | |
| 37 | + let timeoutId; | |
| 38 | + return (...params) => { | |
| 39 | + clearTimeout(timeoutId); | |
| 40 | + timeoutId = setTimeout(() => func(...params), delay); | |
| 41 | + }; | |
| 42 | +}; | |
| 43 | + | |
| 32 | 44 | const path = '/extendify/v1/assists/domains-recommendations-activities'; |
| 33 | 45 | const storage = { |
| 34 | 46 | getItem: async () => await apiFetch({ path }), |
| 35 | - setItem: async (_name, state) => | |
| 36 | - await apiFetch({ path, method: 'POST', data: { state } }), | |
| 47 | + setItem: debounce( | |
| 48 | + async (_name, state) => | |
| 49 | + await apiFetch({ path, method: 'POST', data: { state } }), | |
| 50 | + 500, | |
| 51 | + ), | |
| 37 | 52 | }; |
| 38 | 53 | |
| 39 | 54 | export const useDomainActivities = create( |
| 40 | 55 | persist( |