-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsearch.page.tsx
92 lines (86 loc) · 2.58 KB
/
search.page.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { useDebounce } from "@react-hook/debounce"
import cx from "classnames"
import QueryString from "query-string"
import React, { useEffect } from "react"
import { Helmet } from "react-helmet"
import { Input } from "reakit"
import { LexicalSearch } from "src/components/lexical-search"
import Link from "src/components/link"
import * as Dailp from "src/graphql/dailp"
import { useLocation } from "src/renderer/PageShell"
import { closeBlock, fullWidth } from "src/style/utils.css"
import Layout from "../layout"
import { documentWordPath, sourceCitationRoute } from "../routes"
import { boldWordRow, wordRow } from "./timeline.css"
const SearchPage = () => {
const location = useLocation()
const [morphemeId, setMorpheme] = useDebounce(
(location.search && location.search["query"]) || null,
300
)
useEffect(() => {
if (typeof window !== "undefined") {
window.history.replaceState(
null,
"",
QueryString.stringifyUrl({
url: "",
query: { query: morphemeId },
})
)
}
}, [morphemeId])
return (
<Layout>
<LexicalSearch />
</Layout>
)
}
export const Page = SearchPage
const Timeline = (p: { gloss: string }) => {
const [timeline] = Dailp.useWordSearchQuery({
variables: { query: p.gloss },
})
if (!p.gloss) {
return null
} else if (timeline.fetching) {
return <>Loading...</>
} else if (timeline.error) {
console.error(timeline.error)
return <>Error!</>
} else if (!timeline.data || !timeline.data.wordSearch.length) {
return <>No results found.</>
} else {
return (
<div className={fullWidth}>
<div className={boldWordRow}>
<div>Document ID</div>
<div>Transcription</div>
<div>Normalization</div>
<div>Simple Phonetics</div>
<div>Translation</div>
</div>
{timeline.data.wordSearch.map((form, i) => (
<div key={i} className={wordRow}>
{!!form.document ? (
<Link
href={
form.document.isReference
? sourceCitationRoute(form.document.slug)
: documentWordPath(form.document.slug, form.index)
}
>
{form.document.slug.toUpperCase()}
</Link>
) : null}
<div>{form.source}</div>
<div>{form.normalizedSource}</div>
<div>{form.romanizedSource}</div>
<div>{form.englishGloss.join(", ")}</div>
</div>
))}
</div>
)
}
}
const searchBox = cx(fullWidth, closeBlock)