File size: 1,361 Bytes
a2e4e8f
58973c7
 
 
 
a2e4e8f
58973c7
 
 
50f8987
58973c7
 
 
 
 
 
 
a2e4e8f
58973c7
 
 
 
 
a2e4e8f
 
 
 
 
 
 
58973c7
a2e4e8f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58973c7
 
 
58d3e00
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
import { TextField, Button, Box, Alert } from '@mui/material';
import { useState } from 'react';

function DocumentInput() {
  const [url, setUrl] = useState('');
  const [showSuccess, setShowSuccess] = useState(false);

  const handleSubmit = async () => {
    try {
      const response = await fetch('/api/crawl/', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
        },
        body: JSON.stringify({ url }),
      });
      if (!response.ok) throw new Error('Network response was not ok');
      setShowSuccess(true);
    } catch (error) {
      console.error('Error:', error);
    }
  };

  const handleUrlChange = (e: React.ChangeEvent<HTMLInputElement>) => {
    setUrl(e.target.value);
    if (showSuccess) {
      setShowSuccess(false);
    }
  };

  return (
    <Box sx={{ mb: 4 }}>
      <Box sx={{ display: 'flex', gap: 2, mb: 2 }}>
        <TextField
          fullWidth
          label="Source Documentation"
          value={url}
          onChange={handleUrlChange}
        />
        <Button variant="contained" onClick={handleSubmit}>
          Pull Source Docs
        </Button>
      </Box>
      {showSuccess && (
        <Alert severity="success" sx={{ mt: 1 }}>
          Source documentation imported successfully!
        </Alert>
      )}
    </Box>
  );
}
export default DocumentInput;