Files
Verso/services/web/frontend/js/services/algolia-search.js
T
Timothée AlbyandCopybot 1af8f0358b Merge pull request #2501 from overleaf/as-unvendor-algoliasearch
Unvendor Algolia search client

GitOrigin-RevId: ad0ea56c66a516bd8a26a76d454cbc8d0594a03f
2020-01-11 04:15:10 +00:00

66 lines
1.8 KiB
JavaScript

/* eslint-disable
max-len,
no-undef,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS103: Rewrite code to no longer use __guard__
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
define(['base', 'algoliasearch'], (App, AlgoliaSearch) =>
App.factory('algoliaSearch', function() {
let kbIdx, wikiIdx
if (
(window.sharelatex != null ? window.sharelatex.algolia : undefined) !=
null &&
__guard__(
window.sharelatex.algolia != null
? window.sharelatex.algolia.indexes
: undefined,
x => x.wiki
) != null
) {
const client = AlgoliaSearch(
window.sharelatex.algolia != null
? window.sharelatex.algolia.app_id
: undefined,
window.sharelatex.algolia != null
? window.sharelatex.algolia.api_key
: undefined
)
wikiIdx = client.initIndex(
__guard__(
window.sharelatex.algolia != null
? window.sharelatex.algolia.indexes
: undefined,
x1 => x1.wiki
)
)
kbIdx = client.initIndex(
__guard__(
window.sharelatex.algolia != null
? window.sharelatex.algolia.indexes
: undefined,
x2 => x2.kb
)
)
}
// searchKB is deprecated
const service = {
searchWiki: wikiIdx ? wikiIdx.search.bind(wikiIdx) : null,
searchKB: kbIdx ? kbIdx.search.bind(kbIdx) : null
}
return service
}))
function __guard__(value, transform) {
return typeof value !== 'undefined' && value !== null
? transform(value)
: undefined
}