File size: 4,385 Bytes
ebb04db
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import React, { useRef, useState } from 'react';
import { UploadCloud, Image as ImageIcon, Video, X, Loader2 } from 'lucide-react';

const FileUpload = ({ onUpload, isProcessing, file }) => {
  const [dragActive, setDragActive] = useState(false);
  const inputRef = useRef(null);

  const handleDrag = (e) => {
    e.preventDefault();
    e.stopPropagation();
    if (e.type === "dragenter" || e.type === "dragover") {
      setDragActive(true);
    } else if (e.type === "dragleave") {
      setDragActive(false);
    }
  };

  const handleDrop = (e) => {
    e.preventDefault();
    e.stopPropagation();
    setDragActive(false);
    if (e.dataTransfer.files && e.dataTransfer.files[0]) {
      onUpload(e.dataTransfer.files[0]);
    }
  };

  const handleChange = (e) => {
    e.preventDefault();
    if (e.target.files && e.target.files[0]) {
      onUpload(e.target.files[0]);
    }
  };

  const isVideo = file?.type.startsWith('video/');

  return (
    <div style={{ display: 'flex', flexDirection: 'column', gap: '1rem' }}>

      {!file ? (

        <div 

          style={{ 

            border: `2px dashed ${dragActive ? 'var(--color-neon-blue)' : 'rgba(140, 155, 186, 0.3)'}`,

            borderRadius: '12px',

            padding: '2rem 1rem',

            textAlign: 'center',

            backgroundColor: dragActive ? 'rgba(0, 229, 255, 0.05)' : 'rgba(0,0,0,0.2)',

            transition: 'all 0.3s ease',

            cursor: 'pointer'

          }}

          onDragEnter={handleDrag}

          onDragLeave={handleDrag}

          onDragOver={handleDrag}

          onDrop={handleDrop}

          onClick={() => inputRef.current.click()}

        >

          <input

            ref={inputRef}

            type="file"

            accept="image/*,video/*"

            onChange={handleChange}

            style={{ display: "none" }}

          />

          <UploadCloud 

            size={40} 

            color={dragActive ? 'var(--color-neon-blue)' : 'var(--color-text-muted)'} 

            style={{ margin: '0 auto 1rem', transition: 'all 0.3s ease' }} 

          />

          <p style={{ margin: '0 0 0.5rem', fontWeight: 500 }}>

            Drag and drop feed here

          </p>

          <p style={{ margin: 0, fontSize: '0.8rem', color: 'var(--color-text-muted)' }}>

            Support for Image or Video formats

          </p>

        </div>

      ) : (

        <div style={{ position: 'relative', borderRadius: '12px', overflow: 'hidden', border: '1px solid rgba(255,255,255,0.1)', background: '#000' }}>

          {isVideo ? (

            <video 

              src={URL.createObjectURL(file)} 

              controls 

              style={{ width: '100%', display: 'block', opacity: isProcessing ? 0.5 : 1 }} 

            />

          ) : (

            <img 

              src={URL.createObjectURL(file)} 

              alt="Uploaded feed" 

              style={{ width: '100%', display: 'block', objectFit: 'cover', maxHeight: '250px', opacity: isProcessing ? 0.5 : 1 }} 

            />

          )}



          {isProcessing && (

            <div style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', background: 'rgba(0,0,0,0.5)' }}>

              <Loader2 className="animate-pulse" size={32} color="var(--color-neon-blue)" style={{ animation: 'spin 2s linear infinite' }} />

              <p style={{ marginTop: '1rem', color: 'var(--color-neon-blue)', fontWeight: 'bold' }} className="glow-text">

                ANALYZING FEED...

              </p>

            </div>

          )}

        </div>

      )}



      {file && !isProcessing && (

         <button 

           className="btn-primary" 

           onClick={() => onUpload(null)} 

           style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', gap: '0.5rem' }}

         >

           <UploadCloud size={18} /> Load New Feed

         </button>

      )}

    </div>
  );
};

// Add standard spin keyframes if not present
if (typeof document !== 'undefined') {
  const style = document.createElement('style');
  style.innerHTML = `

    @keyframes spin { 100% { transform: rotate(360deg); } }

  `;
  document.head.appendChild(style);
}

export default FileUpload;