File size: 4,922 Bytes
dda1e85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import React, { useState, useEffect } from 'react';
import Sidebar from './components/Sidebar';
import AddressBar from './components/AddressBar';
import TabBar from './components/TabBar';
import WebView from './components/WebView';
import AIAssistant from './components/AIAssistant';
import SettingsModal from './components/SettingsModal';
import BookmarksPage from './pages/BookmarksPage';
import HistoryPage from './pages/HistoryPage';
import DownloadsPage from './pages/DownloadsPage';

const App = () => {
  const [tabs, setTabs] = useState([
    { id: 1, title: 'New Tab', url: 'https://www.google.com', active: true }
  ]);
  const [activeTabId, setActiveTabId] = useState(1);
  const [showAIAssistant, setShowAIAssistant] = useState(false);
  const [showSettings, setShowSettings] = useState(false);
  const [currentPage, setCurrentPage] = useState('browser'); // browser, bookmarks, history, downloads
  const [bookmarks, setBookmarks] = useState([]);
  const [history, setHistory] = useState([]);
  const [downloads, setDownloads] = useState([]);

  // Load data from localStorage
  useEffect(() => {
    const savedBookmarks = JSON.parse(localStorage.getItem('bookmarks') || '[]');
    const savedHistory = JSON.parse(localStorage.getItem('history') || '[]');
    const savedDownloads = JSON.parse(localStorage.getItem('downloads') || '[]');
    
    setBookmarks(savedBookmarks);
    setHistory(savedHistory);
    setDownloads(savedDownloads);
  }, []);

  // Save data to localStorage
  useEffect(() => {
    localStorage.setItem('bookmarks', JSON.stringify(bookmarks));
  }, [bookmarks]);

  useEffect(() => {
    localStorage.setItem('history', JSON.stringify(history));
  }, [history]);

  useEffect(() => {
    localStorage.setItem('downloads', JSON.stringify(downloads));
  }, [downloads]);

  const addTab = () => {
    const newTab = {
      id: Date.now(),
      title: 'New Tab',
      url: 'https://www.google.com',
      active: true
    };
    setTabs([...tabs.map(tab => ({ ...tab, active: false })), newTab]);
    setActiveTabId(newTab.id);
    setCurrentPage('browser');
  };

  const closeTab = (id) => {
    if (tabs.length <= 1) return;
    const newTabs = tabs.filter(tab => tab.id !== id);
    if (tabs.find(tab => tab.id === id)?.active) {
      newTabs[0].active = true;
      setActiveTabId(newTabs[0].id);
    }
    setTabs(newTabs);
  };

  const switchTab = (id) => {
    setTabs(tabs.map(tab => ({
      ...tab,
      active: tab.id === id
    })));
    setActiveTabId(id);
  };

  const updateTab = (id, updates) => {
    setTabs(tabs.map(tab => 
      tab.id === id ? { ...tab, ...updates } : tab
    ));
  };

  const addBookmark = (bookmark) => {
    setBookmarks([...bookmarks, bookmark]);
  };

  const removeBookmark = (url) => {
    setBookmarks(bookmarks.filter(b => b.url !== url));
  };

  const addToHistory = (entry) => {
    setHistory([entry, ...history.slice(0, 99)]); // Keep last 100 entries
  };

  const addDownload = (download) => {
    setDownloads([download, ...downloads]);
  };

  const activeTab = tabs.find(tab => tab.id === activeTabId) || tabs[0];

  return (
    <div className="flex h-screen bg-gray-900 text-white overflow-hidden">
      <Sidebar 
        currentPage={currentPage}
        setCurrentPage={setCurrentPage}
        showAIAssistant={showAIAssistant}
        setShowAIAssistant={setShowAIAssistant}
        setShowSettings={setShowSettings}
        addTab={addTab}
      />
      
      <div className="flex flex-col flex-1">
        <AddressBar 
          activeTab={activeTab}
          updateTab={updateTab}
          addTab={addTab}
          setCurrentPage={setCurrentPage}
        />
        
        <TabBar 
          tabs={tabs}
          activeTabId={activeTabId}
          switchTab={switchTab}
          closeTab={closeTab}
          addTab={addTab}
        />
        
        {currentPage === 'browser' ? (
          <WebView 
            activeTab={activeTab}
            updateTab={updateTab}
            addToHistory={addToHistory}
            addDownload={addDownload}
          />
        ) : currentPage === 'bookmarks' ? (
          <BookmarksPage 
            bookmarks={bookmarks}
            removeBookmark={removeBookmark}
            setCurrentPage={setCurrentPage}
          />
        ) : currentPage === 'history' ? (
          <HistoryPage 
            history={history}
            setCurrentPage={setCurrentPage}
          />
        ) : (
          <DownloadsPage 
            downloads={downloads}
            setCurrentPage={setCurrentPage}
          />
        )}
      </div>
      
      {showAIAssistant && (
        <AIAssistant 
          activeTab={activeTab}
          onClose={() => setShowAIAssistant(false)}
        />
      )}
      
      {showSettings && (
        <SettingsModal 
          onClose={() => setShowSettings(false)}
        />
      )}
    </div>
  );
};

export default App;