'use client' import { InputField, Wrapper } from '@/components' import { SearchDocument } from '@/generated/graphql/graphql' import { useQuery } from '@apollo/client/react' import { Image } from '@chakra-ui/react' import { Box, Button, Flex, Text } from '@chakra-ui/react' import { Form, Formik } from 'formik' // import { readFileSync } from 'fs' import { useState } from 'react' const Home: React.FC = () => { const [imageFile, setImageFile] = useState(null) const { refetch, loading } = useQuery(SearchDocument, { skip: true }) const [results, setResults] = useState<{ __typename?: string, image: string, text: string }[]>([]) return (
{ if (imageFile) { setResults([]) const reader = new FileReader() reader.readAsArrayBuffer(imageFile) reader.onloadend = async () => { const b64 = Buffer.from(reader.result as string, 'base64').toString('base64') const result = await refetch({ image: b64, limit: 10 }) setResults(result.data!.search) setImageFile(null) setValues({ image: '' }) } } }} > {({ isSubmitting }) => (
{ setResults([]) if (e.currentTarget.files) { setImageFile(e.currentTarget.files[0]) } }} /> { imageFile && Selected image: {imageFile.name} } )}
{ results?.map(r => ( {r.text {r.text} )) }
) } export default Home