-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.tsx
140 lines (121 loc) · 3.98 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
138
139
140
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/05/31 - Big Update", "2024/03/15 - Update for breaking changes", "2024/02/01 - Swap Fee", "2024/01/31 - msg.sender", "2024/01/23 - Dynamic Fees", "2024/01/08 - Quoter", "2023/12/15 - Update v4", "2023/12/11 - Custom Curves", "2023/12/03 - Static Hook Fee", "2023/11/28 - Updated pool initialization", "2023/11/28 - NoOp", "2023/11/13 - Make snippets concise", "2023/10/18 - Initial V4 Snippets"]
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="Uniswap v4 by Example | 0.8.22"
description="Learn Uniswap v4 using Solidity"
/>
<h1 className={styles.header}>
<a href="/">Uniswap v4 by Example</a>
</h1>
<div className={styles.subHeader}>v0.8.22</div>
<div className={styles.main}>
<p>
An introduction to integrating and using{" "}
<a href="https://github.com/uniswap/v4-core">Uniswap v4</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>
)
}