From 0b9cd7ff54e57a9d5e4992a494e69f2cc28cd458 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Mon, 13 Sep 2021 00:17:25 -0700 Subject: [PATCH] Add ordering, limits --- src/App.tsx | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 3f300a3..8ee05ce 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -44,10 +44,21 @@ function buildRequest(searchTerm: string, conlang: Conlang, direction: SearchDir [Conlang.Elesu]: 'elesu', }; + const offset = 0; + const limit = 20; + const conlangDb = conlang.toString(); - const field = direction === SearchDirection.ToConlang ? 'eng' : specForConlang[conlang]; - const query = `${conlangDb}?${field}=like.*${searchTerm}*`; - const effectiveUri = `${backendUrl}/${query}`; + const conlangSpec = specForConlang[conlang]; + const field = direction === SearchDirection.ToConlang ? 'eng' : conlangSpec; + + const params = new URLSearchParams([ + [field, `like.*${searchTerm}*`], + ['order', conlangSpec], + ['limit', limit], + ['offset', offset], + ]); + + const effectiveUri = `${backendUrl}/${conlangDb}?${params}`; fetch(`${effectiveUri}`) .then((resp) => resp.json())