-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.tsx
137 lines (118 loc) · 3.67 KB
/
index.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import React, { useState, useEffect } from "react"
import { useSearchParams } from "react-router-dom"
import SEO from "../components/SEO"
import SearchBar from "../components/SearchBar"
import useDebounce from "../hooks/useDebounce"
import { search, unique } from "../lib/search"
import styles from "./index.module.css"
import youTube from "../components/youtube.png"
import { ROUTES, ROUTES_BY_CATEGORY, TRANSLATIONS } from "../nav"
const UPDATES = ["2024/4/30 - Initial Snippets", "2024/5/4 - Added Lender Actions", "2024/6/28 - Added lenderInfo and removeQuoteToken"]
export default function HomePage() {
const [query, setQuery] = useState("")
const [searchParams, setSearchParams] = useSearchParams()
const [searchResults, setSearchResults] = useState<{
[key: string]: boolean
} | null>(null)
useEffect(() => {
const q = searchParams.get("q")
if (q != null && q.length > 0) {
setQuery(q)
_search(q, false)
}
}, [])
function _search(query: string, save: boolean) {
const q = query.trim()
if (q.length == 0) {
setSearchResults(null)
if (save) {
setSearchParams({ q: "" })
}
return
}
const words = unique(q.split(" "))
const pages: { [key: string]: boolean } = {}
for (const word of words) {
const res = search(word)
for (const page of res) {
pages[page] = true
}
}
setSearchResults(pages)
if (save) {
setSearchParams({ q })
}
}
const _searchWithDelay = useDebounce((query: string) => _search(query, true), 500, [])
function onChangeSearchQuery(query: string) {
setQuery(query)
_searchWithDelay(query)
}
function renderLinks() {
if (searchResults) {
if (Object.keys(searchResults).length == 0) {
return <div>No results</div>
}
return (
<ul className={styles.list}>
{ROUTES.filter(({ path }) => searchResults[path]).map(({ path, title }) => (
<li className={styles.listItem} key={path}>
<a href={path}>{title}</a>
</li>
))}
</ul>
)
}
return (
<>
{ROUTES_BY_CATEGORY.map(({ routes, title }, i) => (
<div key={i}>
{title && <h3 className={styles.category}>{title}</h3>}
<ul className={styles.list}>
{routes.map(({ path, title }) => (
<li className={styles.listItem} key={path}>
<a href={path}>{title}</a>
</li>
))}
</ul>
</div>
))}
{/* <div>
<h3 className={styles.category}>Translations</h3>
{TRANSLATIONS.map(({ lang, url }) => (
<li className={styles.listItem} key={url}>
<a href={url} target="__blank">
{lang}
</a>
</li>
))}
</div> */}
</>
)
}
return (
<div className={styles.component}>
<SEO title="Ajna by Example | 0.8.18" description="Learn Ajna using Solidity" />
<h1 className={styles.header}>
<a href="/">Ajna by Example</a>
</h1>
<div className={styles.subHeader}>v0.8.18</div>
<div className={styles.main}>
<p>
An introduction to integrating and using{" "}
<a href="https://github.com/ajna-finance/ajna-core">Ajna</a> through simple
examples
</p>
<div className={styles.updates}>
{UPDATES.map((text, i) => (
<div key={i}>{text}</div>
))}
</div>
<div className={styles.search}>
<SearchBar value={query} onChange={onChangeSearchQuery} />
</div>
{renderLinks()}
</div>
</div>
)
}