Move Algolia bits to own file in web/lib/service
This commit is contained in:
parent
47cc313aef
commit
a14e7d3947
|
@ -1,5 +1,4 @@
|
||||||
/* eslint-disable react-hooks/exhaustive-deps */
|
/* eslint-disable react-hooks/exhaustive-deps */
|
||||||
import algoliasearch from 'algoliasearch/lite'
|
|
||||||
import { SearchOptions } from '@algolia/client-search'
|
import { SearchOptions } from '@algolia/client-search'
|
||||||
import { useRouter } from 'next/router'
|
import { useRouter } from 'next/router'
|
||||||
import { Contract } from 'common/contract'
|
import { Contract } from 'common/contract'
|
||||||
|
@ -11,7 +10,7 @@ import {
|
||||||
import { ShowTime } from './contract/contract-details'
|
import { ShowTime } from './contract/contract-details'
|
||||||
import { Row } from './layout/row'
|
import { Row } from './layout/row'
|
||||||
import { useEffect, useLayoutEffect, useRef, useMemo, ReactNode } from 'react'
|
import { useEffect, useLayoutEffect, useRef, useMemo, ReactNode } from 'react'
|
||||||
import { ENV, IS_PRIVATE_MANIFOLD } from 'common/envs/constants'
|
import { IS_PRIVATE_MANIFOLD } from 'common/envs/constants'
|
||||||
import { useFollows } from 'web/hooks/use-follows'
|
import { useFollows } from 'web/hooks/use-follows'
|
||||||
import {
|
import {
|
||||||
historyStore,
|
historyStore,
|
||||||
|
@ -28,14 +27,11 @@ import { DEFAULT_CATEGORY_GROUPS } from 'common/categories'
|
||||||
import { Col } from './layout/col'
|
import { Col } from './layout/col'
|
||||||
import clsx from 'clsx'
|
import clsx from 'clsx'
|
||||||
import { safeLocalStorage } from 'web/lib/util/local'
|
import { safeLocalStorage } from 'web/lib/util/local'
|
||||||
|
import {
|
||||||
const searchClient = algoliasearch(
|
getIndexName,
|
||||||
'GJQPAYENIF',
|
searchClient,
|
||||||
'75c28fc084a80e1129d427d470cf41a3'
|
searchIndexName,
|
||||||
)
|
} from 'web/lib/service/algolia'
|
||||||
|
|
||||||
const indexPrefix = ENV === 'DEV' ? 'dev-' : ''
|
|
||||||
const searchIndexName = ENV === 'DEV' ? 'dev-contracts' : 'contractsIndex'
|
|
||||||
|
|
||||||
export const SORTS = [
|
export const SORTS = [
|
||||||
{ label: 'Newest', value: 'newest' },
|
{ label: 'Newest', value: 'newest' },
|
||||||
|
@ -154,7 +150,7 @@ export function ContractSearch(props: {
|
||||||
if (freshQuery || requestedPage < state.numPages) {
|
if (freshQuery || requestedPage < state.numPages) {
|
||||||
const index = query
|
const index = query
|
||||||
? searchIndex
|
? searchIndex
|
||||||
: searchClient.initIndex(`${indexPrefix}contracts-${sort}`)
|
: searchClient.initIndex(getIndexName(sort))
|
||||||
const numericFilters = query
|
const numericFilters = query
|
||||||
? []
|
? []
|
||||||
: [
|
: [
|
||||||
|
|
14
web/lib/service/algolia.ts
Normal file
14
web/lib/service/algolia.ts
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
import algoliasearch from 'algoliasearch/lite'
|
||||||
|
import { ENV } from 'common/envs/constants'
|
||||||
|
|
||||||
|
export const searchClient = algoliasearch(
|
||||||
|
'GJQPAYENIF',
|
||||||
|
'75c28fc084a80e1129d427d470cf41a3'
|
||||||
|
)
|
||||||
|
|
||||||
|
const indexPrefix = ENV === 'DEV' ? 'dev-' : ''
|
||||||
|
export const searchIndexName = ENV === 'DEV' ? 'dev-contracts' : 'contractsIndex'
|
||||||
|
|
||||||
|
export const getIndexName = (sort: string) => {
|
||||||
|
return `${indexPrefix}contracts-${sort}`
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user