@@ -14,26 +14,21 @@ class Search extends Component {
14 this.searchEndpoint = this.searchEndpoint.bind(this);
14 this.searchEndpoint = this.searchEndpoint.bind(this);
15 this.onInputValueChange = this.onInputValueChange.bind(this);
15 this.onInputValueChange = this.onInputValueChange.bind(this);
16 this.onSelect = this.onSelect.bind(this);
16 this.onSelect = this.onSelect.bind(this);
17− this.glossarySearch = this.glossarySearch.bind(this);
18 this.patpSearch = this.patpSearch.bind(this);
17 this.patpSearch = this.patpSearch.bind(this);
19 this.devSearch = this.devSearch.bind(this);
18 this.devSearch = this.devSearch.bind(this);
20 this.opsSearch = this.opsSearch.bind(this);
19 this.opsSearch = this.opsSearch.bind(this);
23 searchEndpoint(query) {
22 searchEndpoint(query) {
24− return `/api/search?q=${query}`;
23+ return `/api/search?q=${encodeURIComponent(query)}`;
27 devSearch(query) {
26 devSearch(query) {
28− return `/api/dev-search?q=${query}`;
27+ return `/api/dev-search?q=${encodeURIComponent(query)}`;
31− glossarySearch(query) {
32− return `/api/glossary?q=${encodeURIComponent(query)}`;
35 opsSearch(query) {
30 opsSearch(query) {
36− return `/api/ops-search?q=${query}`;
31+ return `/api/ops-search?q=${encodeURIComponent(query)}`;
39 patpSearch(query) {
34 patpSearch(query) {
@@ -45,16 +40,19 @@ class Search extends Component {
47 onSelect(item) {
42 onSelect(item) {
49− this.props.router.push(item.slug);
52 this.setState({
43 this.setState({
53 query: "",
44 query: "",
54 results: [],
45 results: [],
49+ this.props.router.push(`${item.url}${item?.slug ? item.slug : ""}`);
57− this.props.closeSearch();
50+ return this.props.closeSearch();
53+ this.props.router.push(item.slug);
54+ return this.props.closeSearch();
60 onInputValueChange = debounce(async (query) => {
58 onInputValueChange = debounce(async (query) => {
@@ -62,10 +60,13 @@ class Search extends Component {
62 const search = fetch(this.searchEndpoint(query))
60 const search = fetch(this.searchEndpoint(query))
63 .then((res) => res.json())
61 .then((res) => res.json())
64 .then(async (res) => {
62 .then(async (res) => {
63+ return [...res.glossary.map((item) => ({
64+ type: "GLOSSARY_RESULT",
65− return res.results.map((item) => ({
66+ })), ...res.results.map((item) => ({
66 type: "RESULT",
67 type: "RESULT",
67 content: item,
68 content: item,
71 const patp = this.patpSearch(query)
72 const patp = this.patpSearch(query)
@@ -76,53 +77,54 @@ class Search extends Component {
77 const patpResult = this.patpSearch(query)
78 const patpResult = this.patpSearch(query)
80− type: "PATP",
81+ type: "PATP",
81− content: {
82+ content: {
82− patp: patp,
83+ patp: patp,
83− slug: `/ids/${patp}`,
84+ slug: `/ids/${patp}`,
89− const glossarySearch = fetch(this.glossarySearch(query))
90− .then((res) => res.json())
92− return res.results.map((item) => ({
93− type: "GLOSSARY_RESULT",
98 const devSearch = fetch(this.devSearch(query))
90 const devSearch = fetch(this.devSearch(query))
99 .then((res) => res.json())
91 .then((res) => res.json())
100 .then((res) => {
92 .then((res) => {
93+ return [...res.glossary.map((item) => ({
94+ type: "GLOSSARY_RESULT",
101− return res.results.map((item) => ({
96+ })), ...res.results.map((item) => ({
102 type: "DEV_RESULT",
97 type: "DEV_RESULT",
103 content: item,
98 content: item,
107 const opsSearch = fetch(this.opsSearch(query))
102 const opsSearch = fetch(this.opsSearch(query))
108 .then((res) => res.json())
103 .then((res) => res.json())
109 .then((res) => {
104 .then((res) => {
105+ return [...res.glossary.map((item) => ({
106+ type: "GLOSSARY_RESULT",
110− return res.results.map((item) => ({
108+ })), ...res.results.map((item) => ({
111 type: "OPS_RESULT",
109 type: "OPS_RESULT",
112 content: item,
110 content: item,
116− const [results, glossaryResults, devResults, opsResults] =
114+ const [results, devResults, opsResults] =
117− await Promise.all([search, glossarySearch, devSearch, opsSearch]);
115+ await Promise.all([search, devSearch, opsSearch]);
119 const list = [
117 const list = [
121 ...patpResult,
118 ...patpResult,
122 ...results,
119 ...results,
123 ...devResults,
120 ...devResults,
124 ...opsResults,
121 ...opsResults,
124+ const aNum = a?.type === "GLOSSARY_RESULT" ? 1 : -1;
125+ const bNum = b?.type === "GLOSSARY_RESULT" ? 1 : -1;
127 this.setState({ results: list });
129 this.setState({ results: list });
@@ -182,209 +184,195 @@ class Search extends Component {
182 <ul {...getMenuProps()} className="overflow-y-scroll">
184 <ul {...getMenuProps()} className="overflow-y-scroll">
184 ? state.results.map((item, index) => {
186 ? state.results.map((item, index) => {
185− const selected = highlightedIndex === index;
187+ const selected = highlightedIndex === index;
186− if (item.type === "PATP") {
188+ if (item.type === "PATP") {
187− return (
189+ return (
189− className={`cursor-pointer p-2 flex space-x-2 items-center text-left w-full ${
191+ className={`cursor-pointer p-2 flex space-x-2 items-center text-left w-full ${selected ? "bg-green-400" : ""
190− selected ? "bg-green-400" : ""
192− {...getItemProps({
193+ {...getItemProps({
193− key: item.content.slug + "-" + index,
194+ key: item.content.slug + "-" + index,
195− item: item.content,
196+ item: item.content,
196− selected: highlightedIndex === index,
197+ selected: highlightedIndex === index,
199− <div className="rounded-md overflow-hidden">
200+ <div className="rounded-md overflow-hidden">
201− patp={item.content.patp}
202+ patp={item.content.patp}
202− size={25}
203+ size={25}
206− <p className="font-mono">{item.content.patp}</p>
207+ <p className="font-mono">{item.content.patp}</p>
210− if (item.type === "GLOSSARY_RESULT") {
211+ if (item.type === "GLOSSARY_RESULT") {
211− return (
212+ return (
213− className={`cursor-pointer flex text-left w-full ${
214+ className={`cursor-pointer flex text-left w-full ${selected ? "bg-green-400" : ""
214− selected ? "bg-green-400" : ""
216− {...getItemProps({
216+ {...getItemProps({
217− key: item.content.slug + "-" + index,
217+ key: item.content.slug + "-" + index,
219− item: item.content,
219+ item: item.content,
220− selected: highlightedIndex === index,
220+ selected: highlightedIndex === index,
223− <div className="font-semibold p-3">
223+ <div className="font-semibold p-3">
225− className={`text-base ${
226− selected ? "text-white" : "text-wall-600"
225+ className={`text-base ${selected ? "text-white" : "text-wall-600"
229− {item.content.symbol.length > 0 && (
228+ {item.content.symbol.length > 0 && (
231− className={`mr-1 rounded px-1 py-0.5 ${
230+ className={`mr-1 rounded px-1 py-0.5 ${selected
233− ? "bg-washedWhite"
231+ ? "bg-washedWhite"
234− : "bg-wall-100"
232+ : "bg-wall-100"
237− {item.content.symbol}
235+ {item.content.symbol}
240− {item.content.name}
238+ {item.content.name}
243− className={`font-normal text-base mt-1 ${
241+ className={`font-normal text-base mt-1 ${selected ? "text-white" : "text-wall-600"
244− selected ? "text-white" : "text-wall-600"
246− dangerouslySetInnerHTML={{
243+ dangerouslySetInnerHTML={{
247− __html: item.content.desc,
244+ __html: item.content.desc,
254− if (item.type === "RESULT") {
251+ if (item.type === "RESULT") {
255− return (
252+ return (
257− className={`cursor-pointer flex text-left w-full ${
254+ className={`cursor-pointer flex text-left w-full ${selected ? "bg-green-400" : ""
258− selected ? "bg-green-400" : ""
260− {...getItemProps({
256+ {...getItemProps({
261− key: item.content.link + "-" + index,
257+ key: item.content.link + "-" + index,
263− item: item.content,
259+ item: item.content,
264− selected,
260+ selected,
267− <div className="p-3">
263+ <div className="p-3">
269− className={`font-medium text-base ${
270− selected ? "text-white" : "text-wall-600"
265+ className={`font-medium text-base ${selected ? "text-white" : "text-wall-600"
273− {item.content.parent !== "Content"
268+ {item.content.parent !== "Content"
274− ? `${item.content.parent} /`
269+ ? `${item.content.parent} /`
275− : ""}{" "}
270+ : ""}{" "}
276− {item.content.title}
271+ {item.content.title}
279− className={`text-base font-regular text-small ${
274+ className={`text-base font-regular text-small ${selected ? "text-midWhite" : "text-wall-500"
280− selected ? "text-midWhite" : "text-wall-500"
283− {item.content.content}
277+ {item.content.content}
284− {item?.content?.foundOnPage && (
278+ {item?.content?.foundOnPage && (
285− <span className="italic block">
279+ <span className="italic block">
286− Found in page content
280+ Found in page content
294− if (item.type === "DEV_RESULT") {
288+ if (item.type === "DEV_RESULT") {
295− const devItem = Object.assign({}, item.content);
289+ const devItem = Object.assign({}, item.content);
296− devItem[
290+ devItem[
298− ] = `https://developers.urbit.org${item.content.slug}`;
292+ ] = `https://developers.urbit.org${item.content.slug}`;
299− return (
293+ return (
301− className={`cursor-pointer flex text-left w-full ${
295+ className={`cursor-pointer flex text-left w-full ${selected ? "bg-green-400" : ""
302− selected ? "bg-green-400" : ""
304− {...getItemProps({
297+ {...getItemProps({
305− key: item.content.link + "-" + index,
298+ key: item.content.link + "-" + index,
307− item: devItem,
300+ item: devItem,
308− selected,
301+ selected,
311− <div className="p-3">
304+ <div className="p-3">
313− className={`font-medium text-base ${
314− selected ? "text-white" : "text-wall-600"
306+ className={`font-medium text-base ${selected ? "text-white" : "text-wall-600"
317− <span className="text-wall-400">
309+ <span className="text-wall-400">
318− {item.content.parent !== "Content"
310+ {item.content.parent !== "Content"
319− ? `developers.urbit.org / ${item.content.parent} /`
311+ ? `developers.urbit.org / ${item.content.parent} /`
320− : "developers.urbit.org /"}{" "}
312+ : "developers.urbit.org /"}{" "}
322− {item.content.title}
314+ {item.content.title}
325− className={`text-base font-regular text-small ${
317+ className={`text-base font-regular text-small ${selected ? "text-midWhite" : "text-wall-500"
326− selected ? "text-midWhite" : "text-wall-500"
329− {item.content.content}
320+ {item.content.content}
330− {item?.content?.foundOnPage && (
321+ {item?.content?.foundOnPage && (
331− <span className="italic block">
322+ <span className="italic block">
332− Found in page content
323+ Found in page content
340− if (item.type === "OPS_RESULT") {
331+ if (item.type === "OPS_RESULT") {
341− const opsItem = Object.assign({}, item.content);
332+ const opsItem = Object.assign({}, item.content);
342− opsItem[
333+ opsItem[
344− ] = `https://operators.urbit.org${item.content.slug}`;
335+ ] = `https://operators.urbit.org${item.content.slug}`;
345− return (
336+ return (
347− className={`cursor-pointer flex text-left w-full ${
338+ className={`cursor-pointer flex text-left w-full ${selected ? "bg-green-400" : ""
348− selected ? "bg-green-400" : ""
350− {...getItemProps({
340+ {...getItemProps({
351− key: item.content.link + "-" + index,
341+ key: item.content.link + "-" + index,
353− item: opsItem,
343+ item: opsItem,
354− selected,
344+ selected,
357− <div className="p-3">
347+ <div className="p-3">
359− className={`font-medium text-base ${
360− selected ? "text-white" : "text-wall-600"
349+ className={`font-medium text-base ${selected ? "text-white" : "text-wall-600"
363− <span className="text-wall-400">
352+ <span className="text-wall-400">
364− {item.content.parent !== "Content"
353+ {item.content.parent !== "Content"
365− ? `operators.urbit.org / ${item.content.parent} /`
354+ ? `operators.urbit.org / ${item.content.parent} /`
366− : "operators.urbit.org /"}{" "}
355+ : "operators.urbit.org /"}{" "}
368− {item.content.title}
357+ {item.content.title}
371− className={`text-base font-regular text-small ${
360+ className={`text-base font-regular text-small ${selected ? "text-midWhite" : "text-wall-500"
372− selected ? "text-midWhite" : "text-wall-500"
375− {item.content.content}
363+ {item.content.content}
376− {item?.content?.foundOnPage && (
364+ {item?.content?.foundOnPage && (
377− <span className="italic block">
365+ <span className="italic block">
378− Found in page content
366+ Found in page content
386− return null;
374+ return null;