File size: 1,121 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
```javascript
import React, { useState } from 'react';
import { 
  ArrowLeftIcon, 
  ArrowRightIcon, 
  ArrowPathIcon, 
  MicrophoneIcon,
  MagnifyingGlassIcon
} from '@heroicons/react/24/outline';

const AddressBar = ({ activeTab, updateTab, addTab, setCurrentPage }) => {
  const [inputValue, setInputValue] = useState(activeTab?.url || '');
  const [isListening, setIsListening] = useState(false);

  const handleKeyDown = (e) => {
    if (e.key === 'Enter') {
      handleSubmit();
    }
  };

  const handleSubmit = () => {
    let url = inputValue.trim();
    
    // If it looks like a search query, redirect to Google search
    if (!url.includes('.') && url.split(' ').length > 0) {
      url = `https://www.google.com/search?q=${encodeURIComponent(url)}`;
    } 
    // If no protocol specified, add https://
    else if (!url.startsWith('http://') && !url.startsWith('https://')) {
      url = `https://${url}`;
    }
    
    updateTab(activeTab.id, { url });
    setInputValue(url);
  };

  const handleVoiceSearch = () => {
    if ('webkitSpeechRecognition' in window) {
      const recognition = new window