File size: 2,708 Bytes
85a4a41
4279593
 
85a4a41
 
4279593
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85a4a41
 
 
 
 
 
4279593
 
 
 
 
85a4a41
 
 
 
 
 
 
 
 
 
 
4279593
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85a4a41
4279593
 
 
 
 
85a4a41
 
4279593
 
 
85a4a41
 
 
 
 
 
 
 
 
 
 
 
4279593
 
 
 
85a4a41
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import React, { useState } from 'react';
import { BrowserRouter, Routes, Route } from 'react-router-dom';
import CircularProgress from '@mui/material/CircularProgress';
import Snackbar from '@mui/material/Snackbar';
import Alert from '@mui/material/Alert';
import logo from './Icons/settings-2.svg';
import './App.css';
import IntialSetting from './Components/IntialSetting.js';
import AiPage from './Components/AiPage.js';

function App() {
  return (
    <BrowserRouter>
      <Routes>
        <Route path='/' element={<Home />} />
        <Route path='/AiPage' element={<AiPage />} />
      </Routes>
    </BrowserRouter>
  );
}

function Home() {
  const [showSettings, setShowSettings] = useState(false);
  const [initializing, setInitializing] = useState(false);
  // Snackbar state
  const [snackbar, setSnackbar] = useState({
    open: false,
    message: "",
    severity: "success",
  });

  const handleInitializationStart = () => {
    setInitializing(true);
  };

  // Function to open the snackbar
  const openSnackbar = (message, severity = "success") => {
    setSnackbar({ open: true, message, severity });
  };

  // Function to close the snackbar
  const closeSnackbar = (event, reason) => {
    if (reason === 'clickaway') return;
    setSnackbar(prev => ({ ...prev, open: false }));
  };

  return (
    <div className="App">
      <header className="App-header">
        {initializing ? (
          <>
            <CircularProgress style={{ margin: '20px' }} />
            <p>Initializing the app. This may take a few minutes...</p>
          </>
        ) : (
          <>
            <img 
              src={logo} 
              className="App-logo" 
              alt="logo" 
              onClick={() => setShowSettings(true)}
              style={{ cursor: 'pointer' }}
            />
            <p>Enter the settings to proceed</p>
          </>
        )}

        {/* InitialSetting */}
        {showSettings && (
          <IntialSetting 
            trigger={showSettings} 
            setTrigger={setShowSettings}
            onInitializationStart={handleInitializationStart}
            openSnackbar={openSnackbar}
            closeSnackbar={closeSnackbar}
          />
        )}
      </header>
      
      {/* Render the Snackbar*/}
      <Snackbar
        open={snackbar.open}
        autoHideDuration={snackbar.severity === 'success' ? 3000 : null}
        onClose={closeSnackbar}
        anchorOrigin={{ vertical: 'top', horizontal: 'center' }}
      >
        <Alert onClose={closeSnackbar} severity={snackbar.severity} variant="filled" sx={{ width: '100%' }}>
          {snackbar.message}
        </Alert>
      </Snackbar>
    </div>
  );
}

export default App;