Passed
Push — feature/netlify-search ( 939dfd...fbe251 )
by Kevin Van
05:37
created

src/components/Search.tsx   A

Complexity

Total Complexity 1
Complexity/F 1

Size

Lines of Code 33
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 28
mnd 0
bc 0
fnc 1
dl 0
loc 33
rs 10
bpm 0
cpm 1
noi 0
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A Search.tsx ➔ searchData 0 10 1
1
import React, { FunctionComponent, useState, MouseEvent, FormEvent, ChangeEvent } from "react"
2
3
import axios from "axios"
4
5
import "./Search.scss"
6
7
const Search: FunctionComponent = () => {
8
  return (
9
    <form action="https://www.google.be/search" method="get" className="search">
10
      <input type="hidden" name="q" id="q" value="site:https://www.kcvvelewijt.be" />
11
      <label htmlFor="search-str">Search</label>
12
      <input type="text" name="q" id="search-str" onChange={searchData} />
13
      <button type="submit" className="submit submit--search">
14
        Search with Google
15
      </button>
16
      <p id="result"></p>
17
    </form>
18
  )
19
20
  async function searchData(e: ChangeEvent<HTMLInputElement>) {
21
    console.log(e.target)
22
    console.log(
23
      `https://deploy-preview-384--kcvvelewijt.netlify.app/.netlify/functions/searchIndex?search=${e.target.value}&limit=25`
24
    )
25
    const result = await fetch(
26
      `https://deploy-preview-384--kcvvelewijt.netlify.app/.netlify/functions/searchIndex?search=${e.target.value}&limit=25`
27
    ).then((x) => x.json())
28
    console.log(result)
29
  }
30
}
31
32
export default Search
33