Skip to content

Commit dad2200

Browse files
committed
SyntaxLookupWidget -> src/SyntaxLookup
The SyntaxLookupWidget is not an isolated component anymore (it also does side-effectual logic to load the data), so it's better to call it a page and put it in the `src` directory instead.
1 parent 3aa8029 commit dad2200

File tree

4 files changed

+48
-43
lines changed

4 files changed

+48
-43
lines changed

pages/syntax-lookup.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ description: "Discover ReScript syntax constructs with our lookup tool"
44
canonical: "/docs/manual/latest/syntax-lookup"
55
---
66

7-
import { make as SyntaxLookupWidget } from "src/components/SyntaxLookupWidget"
7+
import { make as SyntaxLookup } from "src/SyntaxLookup"
88

9-
<SyntaxLookupWidget />
9+
<SyntaxLookup />

src/components/SyntaxLookupWidget.js renamed to src/SyntaxLookup.js

Lines changed: 22 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/SyntaxLookupWidget.res renamed to src/SyntaxLookup.res

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@ module MdxComp = {
1414
type props
1515
type t = Js.t<props> => React.element
1616

17-
let render: t => React.element = %raw(
18-
`
17+
let render: t => React.element = %raw(`
1918
function(c) {
2019
return React.createElement(c, {});
2120
}
22-
`
23-
)
21+
`)
2422

2523
/* @bs.get */
2624
/* external frontmatter: t => Js.Json.t = "frontmatter" */
@@ -43,6 +41,15 @@ module Category = {
4341
| Other => "Other"
4442
}
4543

44+
let fromString = (s: string): t => {
45+
switch s {
46+
| "decorators" => Decorators
47+
| "controlflow" => ControlFlow
48+
| "operators" => Operators
49+
| _ => Other
50+
}
51+
}
52+
4653
@react.component
4754
let make = (~title, ~children) => {
4855
<div>
@@ -54,6 +61,8 @@ module Category = {
5461
}
5562
}
5663

64+
// The data representing a syntax construct
65+
// handled in the widget
5766
type item = {
5867
id: string,
5968
keywords: array<string>,
@@ -63,15 +72,6 @@ type item = {
6372
component: MdxComp.t,
6473
}
6574

66-
let toCategory = (s: string): Category.t => {
67-
switch s {
68-
| "decorators" => Decorators
69-
| "controlflow" => ControlFlow
70-
| "operators" => Operators
71-
| _ => Other
72-
}
73-
}
74-
7575
let toItem = (syntaxData: syntaxData): item => {
7676
let file = syntaxData["file"]
7777
let id = syntaxData["id"]
@@ -84,8 +84,8 @@ let toItem = (syntaxData: syntaxData): item => {
8484
keywords: keywords,
8585
name: name,
8686
summary: summary,
87-
category: toCategory(category),
88-
component: requireSyntaxFile(file)
87+
category: Category.fromString(category),
88+
component: requireSyntaxFile(file),
8989
}
9090
item
9191
}
@@ -200,9 +200,12 @@ let make = () => {
200200
switch value {
201201
| "" => ShowAll
202202
| search =>
203-
let filtered = fuse->Fuse.search(search)->Belt.Array.map(m => {
204-
m["item"]
205-
})
203+
let filtered =
204+
fuse
205+
->Fuse.search(search)
206+
->Belt.Array.map(m => {
207+
m["item"]
208+
})
206209

207210
if Js.Array.length(filtered) === 1 {
208211
let item = Belt.Array.getExn(filtered, 0)
@@ -249,7 +252,9 @@ let make = () => {
249252
Js.Dict.set(acc, key, items)
250253
acc
251254
})
252-
})->Js.Dict.entries->Belt.Array.reduce([], (acc, entry) => {
255+
})
256+
->Js.Dict.entries
257+
->Belt.Array.reduce([], (acc, entry) => {
253258
let (title, items) = entry
254259
if Js.Array.length(items) === 0 {
255260
acc
File renamed without changes.

0 commit comments

Comments
 (0)