on master help sign in
search: pull other searches out of initial promise
commitc666bca981edf7748fa29726796a32609b745c0f authorMatilde Park <matilde.park@urbit.org> dateWed 6 Jul 2022, 18:52 (4 years ago) parent168e888
1 file changed+53−57
components/Search.js+53−57
components/Search.js+53−57
@@ -60,76 +60,72 @@ class Search extends Component {
6060
6161 onInputValueChange = debounce(async (query) => {
6262 if (query.length) {
63− fetch(this.searchEndpoint(query))
63+ const search = fetch(this.searchEndpoint(query))
6464 .then((res) => res.json())
6565 .then(async (res) => {
66− // Wrap results in an object which will tell React what component to use to render results.
67− const results = res.results.map((item) => ({
66+ return res.results.map((item) => ({
6867 type: "RESULT",
6968 content: item,
7069 }));
70+ });
7171
72− const patp = this.patpSearch(query)
73− ? !isNaN(query)
74− ? ob.patp(query)
75− : ob.patp(ob.patp2dec(`~${deSig(query)}`))
76− : null;
72+ const patp = this.patpSearch(query)
73+ ? !isNaN(query)
74+ ? ob.patp(query)
75+ : ob.patp(ob.patp2dec(`~${deSig(query)}`))
76+ : null;
7777
78− const patpResult = this.patpSearch(query)
79− ? [
80− {
81− type: "PATP",
82− content: {
83− patp: patp,
84− slug: `/ids/${patp}`,
85− },
86− },
87− ]
88− : [];
78+ const patpResult = this.patpSearch(query)
79+ ? [
80+ {
81+ type: "PATP",
82+ content: {
83+ patp: patp,
84+ slug: `/ids/${patp}`,
85+ },
86+ },
87+ ]
88+ : [];
8989
90− const glossarySearch = fetch(this.glossarySearch(query))
91− .then((res) => res.json())
92− .then((res) => {
93− return res.results.map((item) => ({
94− type: "GLOSSARY_RESULT",
95− content: item,
96− }));
97− });
90+ const glossarySearch = fetch(this.glossarySearch(query))
91+ .then((res) => res.json())
92+ .then((res) => {
93+ return res.results.map((item) => ({
94+ type: "GLOSSARY_RESULT",
95+ content: item,
96+ }));
97+ });
9898
99− const devSearch = fetch(this.devSearch(query))
100− .then((res) => res.json())
101− .then((res) => {
102− return res.results.map((item) => ({
103− type: "DEV_RESULT",
104− content: item,
105− }));
106− });
99+ const devSearch = fetch(this.devSearch(query))
100+ .then((res) => res.json())
101+ .then((res) => {
102+ return res.results.map((item) => ({
103+ type: "DEV_RESULT",
104+ content: item,
105+ }));
106+ });
107107
108− const opsSearch = fetch(this.opsSearch(query))
109− .then((res) => res.json())
110− .then((res) => {
111− return res.results.map((item) => ({
112− type: "OPS_RESULT",
113− content: item,
114− }));
115− });
108+ const opsSearch = fetch(this.opsSearch(query))
109+ .then((res) => res.json())
110+ .then((res) => {
111+ return res.results.map((item) => ({
112+ type: "OPS_RESULT",
113+ content: item,
114+ }));
115+ });
116116
117− const [glossaryResults, devResults, opsResults] = await Promise.all([
118− glossarySearch,
119− devSearch,
120− opsSearch,
121− ]);
117+ const [results, glossaryResults, devResults, opsResults] =
118+ await Promise.all([search, glossarySearch, devSearch, opsSearch]);
122119
123− const list = [
124− ...glossaryResults,
125− ...patpResult,
126− ...results,
127− ...devResults,
128− ...opsResults,
129− ];
120+ const list = [
121+ ...glossaryResults,
122+ ...patpResult,
123+ ...results,
124+ ...devResults,
125+ ...opsResults,
126+ ];
130127
131− this.setState({ results: list });
132− });
128+ this.setState({ results: list });
133129 } else {
134130 this.setState({ results: [] });
135131 }