GuaccO commited on
Commit
00ccdc3
·
verified ·
1 Parent(s): 40b4024

Allow to attach files with drag& drop also allow this types and more: .js ; .ts ;.jsx ;.tsx; .sql etc

Browse files
Files changed (3) hide show
  1. index.html +14 -1
  2. script.js +106 -2
  3. style.css +19 -2
index.html CHANGED
@@ -86,7 +86,20 @@
86
  <label class="block text-sm font-medium text-gray-700 mb-1">Deployment Hook URL</label>
87
  <input type="text" id="hookUrl" placeholder="https://api.supabase.com/v1/hooks/..." class="w-full px-3 py-2 border border-gray-300 rounded-md">
88
  </div>
89
- <button id="saveConfig" class="mt-6 bg-green-600 hover:bg-green-700 text-white py-2 px-6 rounded-lg">
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  Save Configuration
91
  </button>
92
  </div>
 
86
  <label class="block text-sm font-medium text-gray-700 mb-1">Deployment Hook URL</label>
87
  <input type="text" id="hookUrl" placeholder="https://api.supabase.com/v1/hooks/..." class="w-full px-3 py-2 border border-gray-300 rounded-md">
88
  </div>
89
+
90
+ <div id="dropZone" class="mt-4 border-2 border-dashed border-gray-300 rounded-lg p-8 text-center bg-gray-50 hover:bg-gray-100 transition-colors">
91
+ <div class="flex flex-col items-center justify-center">
92
+ <i data-feather="upload" class="w-12 h-12 text-gray-400 mb-2"></i>
93
+ <p class="text-gray-600">Drag & drop files here or click to browse</p>
94
+ <input type="file" id="fileInput" class="hidden" multiple>
95
+ <p class="text-xs text-gray-500 mt-2">Supported: .js, .ts, .jsx, .tsx, .sql, .json</p>
96
+ </div>
97
+ </div>
98
+ <div id="fileList" class="mt-2 hidden">
99
+ <h3 class="text-sm font-medium text-gray-700">Selected Files:</h3>
100
+ <ul id="fileItems" class="text-sm text-gray-600"></ul>
101
+ </div>
102
+ <button id="saveConfig" class="mt-6 bg-green-600 hover:bg-green-700 text-white py-2 px-6 rounded-lg">
103
  Save Configuration
104
  </button>
105
  </div>
script.js CHANGED
@@ -46,6 +46,97 @@ document.addEventListener('DOMContentLoaded', () => {
46
  simulateLoadBranches(e.target.value);
47
  }
48
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
 
50
  // Save configuration
51
  document.getElementById('saveConfig').addEventListener('click', () => {
@@ -54,8 +145,21 @@ document.addEventListener('DOMContentLoaded', () => {
54
  const hookUrl = document.getElementById('hookUrl').value;
55
 
56
  if (repo && branch && hookUrl) {
57
- alert('Configuration saved successfully!');
58
- // In a real app, this would save to your backend or Supabase
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  } else {
60
  alert('Please complete all configuration fields');
61
  }
 
46
  simulateLoadBranches(e.target.value);
47
  }
48
  });
49
+ // File upload handling
50
+ const dropZone = document.getElementById('dropZone');
51
+ const fileInput = document.getElementById('fileInput');
52
+ const fileList = document.getElementById('fileList');
53
+ const fileItems = document.getElementById('fileItems');
54
+ let uploadedFiles = [];
55
+
56
+ // Handle drag and drop
57
+ dropZone.addEventListener('click', () => fileInput.click());
58
+
59
+ ['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
60
+ dropZone.addEventListener(eventName, preventDefaults, false);
61
+ });
62
+
63
+ function preventDefaults(e) {
64
+ e.preventDefault();
65
+ e.stopPropagation();
66
+ }
67
+
68
+ ['dragenter', 'dragover'].forEach(eventName => {
69
+ dropZone.addEventListener(eventName, highlight, false);
70
+ });
71
+
72
+ ['dragleave', 'drop'].forEach(eventName => {
73
+ dropZone.addEventListener(eventName, unhighlight, false);
74
+ });
75
+
76
+ function highlight() {
77
+ dropZone.classList.add('border-indigo-500', 'bg-indigo-50');
78
+ }
79
+
80
+ function unhighlight() {
81
+ dropZone.classList.remove('border-indigo-500', 'bg-indigo-50');
82
+ }
83
+
84
+ dropZone.addEventListener('drop', handleDrop, false);
85
+ fileInput.addEventListener('change', handleFiles, false);
86
+
87
+ function handleDrop(e) {
88
+ const dt = e.dataTransfer;
89
+ const files = dt.files;
90
+ handleFiles({ target: { files } });
91
+ }
92
+
93
+ function handleFiles(e) {
94
+ const files = e.target.files;
95
+ const allowedTypes = ['.js', '.ts', '.jsx', '.tsx', '.sql', '.json'];
96
+
97
+ Array.from(files).forEach(file => {
98
+ const ext = '.' + file.name.split('.').pop().toLowerCase();
99
+ if (!allowedTypes.includes(ext)) {
100
+ alert(`File type ${ext} is not allowed`);
101
+ return;
102
+ }
103
+
104
+ uploadedFiles.push(file);
105
+ updateFileList();
106
+ });
107
+ }
108
+
109
+ function updateFileList() {
110
+ if (uploadedFiles.length === 0) {
111
+ fileList.classList.add('hidden');
112
+ return;
113
+ }
114
+
115
+ fileItems.innerHTML = '';
116
+ uploadedFiles.forEach((file, index) => {
117
+ const li = document.createElement('li');
118
+ li.className = 'flex items-center justify-between py-1';
119
+ li.innerHTML = `
120
+ <span>${file.name} (${(file.size / 1024).toFixed(2)} KB)</span>
121
+ <button data-index="${index}" class="text-red-500 hover:text-red-700">
122
+ <i data-feather="trash-2" class="w-4 h-4"></i>
123
+ </button>
124
+ `;
125
+ fileItems.appendChild(li);
126
+ });
127
+
128
+ fileList.classList.remove('hidden');
129
+ feather.replace();
130
+
131
+ // Add event listeners to delete buttons
132
+ document.querySelectorAll('#fileItems button').forEach(btn => {
133
+ btn.addEventListener('click', (e) => {
134
+ const index = e.target.closest('button').dataset.index;
135
+ uploadedFiles.splice(index, 1);
136
+ updateFileList();
137
+ });
138
+ });
139
+ }
140
 
141
  // Save configuration
142
  document.getElementById('saveConfig').addEventListener('click', () => {
 
145
  const hookUrl = document.getElementById('hookUrl').value;
146
 
147
  if (repo && branch && hookUrl) {
148
+ if (uploadedFiles.length > 0) {
149
+ // Upload files along with config
150
+ const formData = new FormData();
151
+ uploadedFiles.forEach(file => {
152
+ formData.append('files', file);
153
+ });
154
+ formData.append('repo', repo);
155
+ formData.append('branch', branch);
156
+ formData.append('hookUrl', hookUrl);
157
+
158
+ // In a real app, send to backend
159
+ alert('Configuration and files saved successfully!');
160
+ } else {
161
+ alert('Configuration saved successfully!');
162
+ }
163
  } else {
164
  alert('Please complete all configuration fields');
165
  }
style.css CHANGED
@@ -26,7 +26,24 @@ input:focus, select:focus {
26
  from { opacity: 0; transform: translateY(5px); }
27
  to { opacity: 1; transform: translateY(0); }
28
  }
29
-
30
  .status-message {
31
  animation: fadeIn 0.3s ease-out;
32
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  from { opacity: 0; transform: translateY(5px); }
27
  to { opacity: 1; transform: translateY(0); }
28
  }
 
29
  .status-message {
30
  animation: fadeIn 0.3s ease-out;
31
+ }
32
+
33
+ /* Drag and drop styles */
34
+ #dropZone {
35
+ cursor: pointer;
36
+ transition: all 0.2s ease;
37
+ }
38
+
39
+ #dropZone.border-indigo-500 {
40
+ border-color: #6366f1;
41
+ }
42
+
43
+ #fileItems button {
44
+ transition: color 0.2s ease;
45
+ }
46
+
47
+ #fileItems button:hover {
48
+ transform: scale(1.1);
49
+ }