File size: 2,120 Bytes
171eb01
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4113b5b
171eb01
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import React, { useState } from 'react';
import Header from './components/Header';
import InputSection from './components/InputSection';
import Results from './components/Results';

function App() {
  const [result, setResult] = useState(null);
  const [loading, setLoading] = useState(false);

  const handleAnalyze = async (data) => {
    setLoading(true);
    try {
      let payload = {};
      if (data.type === 'text') {
        payload = { text: data.content };
      }
      // Note: File upload would need FormData, keeping it simple JSON for text for now

      const response = await fetch('/api/analyze/', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
        },
        body: JSON.stringify(payload),
      });

      if (!response.ok) {
        throw new Error('Analysis failed');
      }

      const resultData = await response.json();
      // Attach original text for the report
      setResult({ ...resultData, originalText: payload.text || "Uploaded File Content" });
    } catch (error) {
      console.error("Error analyzing:", error);
      alert("Failed to connect to local backend. Make sure Django is running!");
    } finally {
      setLoading(false);
    }
  };

  const handleReset = () => {
    setResult(null);
  };

  return (
    <>
      <Header />
      <main className="w-full flex-1 flex flex-col items-center px-4 pb-12">
        {!result && !loading && (
          <InputSection onAnalyze={handleAnalyze} />
        )}

        {loading && (
          <div className="mt-12 flex flex-col items-center">
            <div className="w-12 h-12 border-4 border-blue-500 border-t-transparent rounded-full animate-spin mb-4"></div>
            <p className="text-secondary animate-pulse">Analyzing patterns...</p>
          </div>
        )}

        {result && (
          <Results result={result} onReset={handleReset} />
        )}
      </main>

      <footer className="w-full py-6 text-center text-[rgba(255,255,255,0.2)] text-sm">
        &copy; 2026 DetectAI Project. POC Version.
      </footer>
    </>
  );
}

export default App;