export const toggleBookmark = (url, index) => async (dispatch, getState) => { const results = selectors.results(getState()) const { hasBookmark } = results[index] dispatch(changeHasBookmark(index)) // Reset UI state in case of error analytics.trackEvent({ category: 'Overview', action: hasBookmark ? 'Remove result bookmark' : 'Create result bookmark', }) try { // Either perform adding or removal of bookmark if if (hasBookmark) { await removeBookmarkByUrl(url) } else { await createBookmarkByUrl(url) } } catch (error) { dispatch(changeHasBookmark(index)) // Reset UI state in case of error } finally { updateLastActive() // Consider user active (analytics) } }
handleDeleteBlacklistData = () => { analytics.trackEvent({ category: 'Popup', action: 'Delete blacklisted pages', }) this.deleteDocs( this.state.url, this.state.domainDelete ? 'domain' : 'url', ) this.resetBlacklistConfirmState() }
export const start = () => (dispatch, getState) => { const state = getState() analytics.trackEvent({ category: 'Imports', action: 'Start import', name: selectors.allowTypesString(state), value: selectors.concurrency(state), }) dispatch(prepareImport()) port.postMessage({ cmd: CMDS.START, payload: selectors.allowTypes(state), }) }
onSearchEnter(event) { if (event.key === 'Enter') { event.preventDefault() analytics.trackEvent({ category: 'Search', action: 'Popup search', }) const queryFilters = extractQueryFilters(this.state.searchValue) const queryParams = qs.stringify(queryFilters) browser.tabs.create({ url: `${constants.OVERVIEW_URL}?${queryParams}`, }) // New tab with query window.close() // Close the popup } }
return event => { event.preventDefault() analytics.trackEvent({ category: 'Popup', action: domainDelete ? 'Blacklist domain' : 'Blacklist site', }) this.addToBlacklist(url) this.setState(state => ({ ...state, blacklistChoice: false, blacklistConfirm: true, isBlacklisted: true, url, domainDelete, })) }
onPauseConfirm(event) { event.preventDefault() const { isPaused, pauseValue } = this.state analytics.trackEvent({ category: 'Popup', action: isPaused ? 'Resume indexing' : 'Pause indexing', value: isPaused ? undefined : pauseValue, }) // Tell background script to do on extension level this.toggleLoggingPause(pauseValue) updateLastActive() // Consider user active (analytics) // Do local level state toggle and reset this.setState(state => ({ ...state, isPaused: !isPaused, pauseValue: 20, })) }
// Analytics use function trackSearch(searchResult, overwrite, state) { // Value should be set as # results (if non-default search) const value = overwrite && !selectors.isEmptyQuery(state) ? searchResult.totalCount : undefined let action if (searchResult.totalCount > 0) { action = overwrite ? 'Successful search' : 'Paginate search' } else { action = 'Unsuccessful search' } if (filters.onlyBookmarks(state)) { action += ' (BM only)' } const name = overwrite ? selectors.queryParamsDisplay(state) : selectors.currentPageDisplay(state) analytics.trackEvent({ category: 'Search', action, name, value }) }
export const deleteDocs = () => async (dispatch, getState) => { const url = selectors.urlToDelete(getState()) analytics.trackEvent({ category: 'Overview', action: 'Delete result', }) try { dispatch(hideDeleteConfirm()) // Remove all assoc. docs from the database + index await deleteDocsByUrl(url) const pageId = await generatePageDocId({ url }) // Hide the result item + confirm modal directly (optimistically) dispatch(hideResultItem(pageId)) } catch (error) { } finally { dispatch(setResultDeleting(undefined)) updateLastActive() // Consider user active (analytics) } }
cb: () => analytics.trackEvent({ category: 'Imports', action: 'Finish import', }),
cb: () => analytics.trackEvent({ category: 'Imports', action: 'Resume import', }),
cb: () => analytics.trackEvent({ category: 'Imports', action: 'Cancel import', }),