Skip to content

Commit 2b785e2

Browse files
committed
fix search box and docson
1 parent 2d42ed9 commit 2b785e2

File tree

5 files changed

+20
-16
lines changed

5 files changed

+20
-16
lines changed

app/routes/MdxRoute.res

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ let components = {
4747
"Warn": Markdown.Warn.make,
4848
"CommunityContent": CommunityContent.make,
4949
"WarningTable": WarningTable.make,
50-
"Docson": Docson.make,
50+
"Docson": DocsonLazy.make,
51+
"Suspense": React.Suspense.make,
5152
}
5253

5354
let convertToNavItems = (items, rootPath) =>

docs/manual/build-configuration-schema.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ section: "Build System"
77
order: 3
88
---
99

10-
<Docson tag="master" />
10+
<Suspense>
11+
<Docson tag="master" />
12+
</Suspense>

src/SyntaxLookup.res

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -251,15 +251,18 @@ let make = (
251251
// [2] Search exactly matches an item - trigger a route change, and allow the EFFECT to update the view state.
252252
// [3] Search does not match an item - immediately update the view state to show filtered items.
253253
let onSearchValueChange = value => {
254+
Console.log2("value changed", value)
254255
switch value {
255-
| "" => navigate("/syntax-lookup")
256+
| "" =>
257+
setState(_ => ShowAll)
258+
navigate("/syntax-lookup")
256259
| value =>
257260
switch findItemByExactName(value) {
258261
| None => {
259262
let filtered = searchItems(value)
260263
setState(_ => ShowFiltered(value, filtered))
261264
}
262-
| Some(item) => ReactRouter.navigate("/syntax-lookup/" ++ item.id)
265+
| Some(item) => navigate("/syntax-lookup/" ++ item.id)
263266
}
264267
}
265268
}
@@ -333,11 +336,13 @@ let make = (
333336
})
334337
}
335338

336-
let (searchValue, completionItems) = switch state {
337-
| ShowFiltered(search, items) => (search, items)
338-
| ShowAll => ("", allItems)
339-
| ShowDetails(item) => (item.name, [item])
340-
}
339+
let (searchValue, completionItems) = React.useMemo(() =>
340+
switch state {
341+
| ShowFiltered(search, items) => (search, items)
342+
| ShowAll => ("", allItems)
343+
| ShowDetails(item) => (item.name, [item])
344+
}
345+
, [state])
341346

342347
let onSearchClear = () => {
343348
onSearchValueChange("")

src/components/DocsonLazy.res

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let make = React.lazy_(() => import(Docson.make))

src/components/SearchBox.res

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ let make = (
4949

5050
let full = (ctrlKey ? "CTRL+" : "") ++ key
5151

52+
// TODO RR7 test keyboard input
5253
switch full {
5354
| "Escape" => onClear()
5455
| "Tab" =>
@@ -67,7 +68,6 @@ let make = (
6768
}
6869

6970
let onChange = evt => {
70-
ReactEvent.Form.preventDefault(evt)
7171
let value = ReactEvent.Form.target(evt)["value"]
7272
onValueChange(value)
7373
}
@@ -83,7 +83,6 @@ let make = (
8383
<Icon.MagnifierGlass
8484
className={(state === Active ? "text-fire" : "text-fire-70") ++ " w-4 h-4"}
8585
/>
86-
// TODO RR7: deleting input stops working with one character left...
8786
<input
8887
value
8988
ref={ReactDOM.Ref.domRef((Obj.magic(textInput): React.ref<Nullable.t<Dom.element>>))}
@@ -94,11 +93,7 @@ let make = (
9493
className="text-16 outline-hidden ml-4 w-full"
9594
type_="text"
9695
/>
97-
<button
98-
onFocus
99-
className={"value" /* TODO */ === "" ? "hidden" : "block"}
100-
onMouseDown=onMouseDownClear
101-
>
96+
<button onFocus className={value === "" ? "hidden" : "block"} onMouseDown=onMouseDownClear>
10297
<Icon.Close className="w-4 h-4 text-fire" />
10398
</button>
10499
</div>

0 commit comments

Comments
 (0)