RobinsAIWorld commited on
Commit
e84c628
·
verified ·
1 Parent(s): 2345497

🐳 10/02 - 14:07 - 1. Validation identifies when I broke the json but it still shows SUCCESS! and green with the error, whihc is highgly confusing. It should show red X and the error not green success

Browse files
Files changed (1) hide show
  1. script.js +32 -10
script.js CHANGED
@@ -1,5 +1,5 @@
1
  document.addEventListener('DOMContentLoaded', function() {
2
- // Sample JSON data
3
  const sampleJSON = {
4
  "name": "John Doe",
5
  "age": 30,
@@ -94,9 +94,10 @@ document.addEventListener('DOMContentLoaded', function() {
94
  try {
95
  const data = JSON.parse(e.target.result);
96
  loadJSON(data);
97
- showNotification('File loaded successfully!');
98
  } catch (error) {
99
- showNotification('Error loading file: Invalid JSON');
 
100
  }
101
  };
102
  reader.readAsText(file);
@@ -449,13 +450,13 @@ document.addEventListener('DOMContentLoaded', function() {
449
  let displayValue = type === 'key' ? currentValue : JSON.stringify(currentValue);
450
 
451
  // Remove quotes from display for editing
452
- if (displayValue.startsWith('"') && displayValue.endsWith('"')) {
453
  displayValue = displayValue.slice(1, -1);
454
  }
455
 
456
  const input = document.createElement('input');
457
  input.type = 'text';
458
- input.value = displayValue;
459
  input.className = `editable-field ${type}-input`;
460
 
461
  // Replace span with input
@@ -709,12 +710,16 @@ document.addEventListener('DOMContentLoaded', function() {
709
  isApplyingChanges = false;
710
  rightEditorModified = false;
711
  if (showMsg) {
712
- showNotification('Changes applied successfully!');
713
  }
714
  return true;
715
  } catch (e) {
716
  jsonOutput.style.borderColor = '#ef4444';
717
  validationStatus.innerHTML = '<i class="fas fa-exclamation-circle text-red-500"></i><span class="text-red-600">Invalid JSON</span>';
 
 
 
 
718
  return false;
719
  }
720
  }
@@ -747,7 +752,8 @@ document.addEventListener('DOMContentLoaded', function() {
747
 
748
  } catch (e) {
749
  jsonOutput.style.borderColor = '#ef4444';
750
- validationStatus.innerHTML = '<i class="fas fa-exclamation-circle text-red-500"></i><span class="text-red-600">Invalid JSON</span>';
 
751
  }
752
  });
753
 
@@ -787,15 +793,31 @@ document.addEventListener('DOMContentLoaded', function() {
787
  });
788
  });
789
 
790
- // Show notification
791
- function showNotification(message) {
792
  const notificationContent = notification.querySelector('p');
 
 
 
793
  notificationContent.textContent = message;
 
 
 
 
 
 
 
 
 
 
 
 
 
794
  notification.classList.add('show');
795
 
796
  setTimeout(() => {
797
  notification.classList.remove('show');
798
- }, 3000);
799
  }
800
 
801
  // Save to history for undo/redo
 
1
  document.addEventListener('DOMContentLoaded', function() {
2
+ ======= Sample JSON data
3
  const sampleJSON = {
4
  "name": "John Doe",
5
  "age": 30,
 
94
  try {
95
  const data = JSON.parse(e.target.result);
96
  loadJSON(data);
97
+ showNotification('File loaded successfully!', false);
98
  } catch (error) {
99
+ const errorMessage = error.message || 'Invalid JSON format';
100
+ showNotification('Error loading file: ' + errorMessage, true);
101
  }
102
  };
103
  reader.readAsText(file);
 
450
  let displayValue = type === 'key' ? currentValue : JSON.stringify(currentValue);
451
 
452
  // Remove quotes from display for editing
453
+ if (displayValue && displayValue.startsWith('"') && displayValue.endsWith('"')) {
454
  displayValue = displayValue.slice(1, -1);
455
  }
456
 
457
  const input = document.createElement('input');
458
  input.type = 'text';
459
+ input.value = displayValue !== undefined ? displayValue : '';
460
  input.className = `editable-field ${type}-input`;
461
 
462
  // Replace span with input
 
710
  isApplyingChanges = false;
711
  rightEditorModified = false;
712
  if (showMsg) {
713
+ showNotification('Changes applied successfully!', false);
714
  }
715
  return true;
716
  } catch (e) {
717
  jsonOutput.style.borderColor = '#ef4444';
718
  validationStatus.innerHTML = '<i class="fas fa-exclamation-circle text-red-500"></i><span class="text-red-600">Invalid JSON</span>';
719
+ const errorMessage = e.message || 'Unknown JSON syntax error';
720
+ if (showMsg) {
721
+ showNotification('Invalid JSON: ' + errorMessage, true);
722
+ }
723
  return false;
724
  }
725
  }
 
752
 
753
  } catch (e) {
754
  jsonOutput.style.borderColor = '#ef4444';
755
+ const errorMessage = e.message || 'Invalid JSON syntax';
756
+ validationStatus.innerHTML = '<i class="fas fa-exclamation-circle text-red-500"></i><span class="text-red-600">Invalid JSON: ' + errorMessage + '</span>';
757
  }
758
  });
759
 
 
793
  });
794
  });
795
 
796
+ // Show notification (success by default)
797
+ function showNotification(message, isError = false) {
798
  const notificationContent = notification.querySelector('p');
799
+ const notificationTitle = notification.querySelector('h4');
800
+ const notificationIcon = notification.querySelector('i');
801
+
802
  notificationContent.textContent = message;
803
+
804
+ if (isError) {
805
+ notificationTitle.textContent = 'Error!';
806
+ notificationIcon.className = 'fas fa-times-circle text-red-500 text-xl mt-0.5 mr-3';
807
+ notification.classList.remove('border-green-500');
808
+ notification.classList.add('border-red-500');
809
+ } else {
810
+ notificationTitle.textContent = 'Success!';
811
+ notificationIcon.className = 'fas fa-check-circle text-green-500 text-xl mt-0.5 mr-3';
812
+ notification.classList.remove('border-red-500');
813
+ notification.classList.add('border-green-500');
814
+ }
815
+
816
  notification.classList.add('show');
817
 
818
  setTimeout(() => {
819
  notification.classList.remove('show');
820
+ }, 4000);
821
  }
822
 
823
  // Save to history for undo/redo