File size: 1,025 Bytes
1efb9e6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
'use client'

import { useState } from 'react'
import { Modal } from './components/Modal';
import { SearchBar } from './components/SearchBar';
import { ImageGrid } from './components/ImageGrid';

export default function Home() {

  // Application state
  const [images, setImages] = useState(null);
  const [currentImage, setCurrentImage] = useState(null);

  const search = async (text) => {
    if (!text) return;

    const params = new URLSearchParams();
    params.append('text', text);
    params.append('threshold', 0.1);
    params.append('limit', 100);

    // Make a request to the /classify route on the server.
    const result = await fetch(`/search?${params.toString()}`);

    const json = await result.json();
    setImages(json);
  };

  return (
    <main className="mx-auto max-w-[1960px] p-4 relative">
      <Modal currentImage={currentImage} setCurrentImage={setCurrentImage} />
      <SearchBar search={search} />
      <ImageGrid images={images} setCurrentImage={setCurrentImage} />
    </main>
  )
}