@@ -43,6 +43,12 @@ function error(e) {
4343
4444 updateStatus ( 'error' , `Error: ${ e . message } ` ) ;
4545
46+ // Clear loading spinner in the current tab when an error occurs
47+ const tabOutputElm = document . querySelector ( `#${ currentTabId } .results-content` ) ;
48+ if ( tabOutputElm ) {
49+ tabOutputElm . innerHTML = `<div class="no-results error-result">Query failed: ${ e . message } </div>` ;
50+ }
51+
4652 setTimeout ( ( ) => {
4753 errorElm . style . opacity = 0 ;
4854 setTimeout ( ( ) => {
@@ -102,7 +108,7 @@ function execute(commands, tabId = currentTabId) {
102108 const executionTime = toc ( "Executing SQL" ) ;
103109
104110 if ( ! results ) {
105- error ( { message : event . data . error } ) ;
111+ error ( { message : event . data . error || "Unknown error occurred" } ) ;
106112 return ;
107113 }
108114
@@ -125,6 +131,11 @@ function execute(commands, tabId = currentTabId) {
125131 }
126132
127133 worker . postMessage ( { action : 'exec' , sql : commands } ) ;
134+
135+ // Set up error handling for the worker
136+ worker . onerror = function ( e ) {
137+ error ( e ) ;
138+ } ;
128139}
129140
130141// Create an HTML table
@@ -172,7 +183,11 @@ function execEditorContents() {
172183 createNewTab ( ) ;
173184 }
174185
175- execute ( editor . getValue ( ) + ';' ) ;
186+ try {
187+ execute ( editor . getValue ( ) + ';' ) ;
188+ } catch ( e ) {
189+ error ( e ) ;
190+ }
176191
177192 // Add visual feedback for button click
178193 execBtn . classList . add ( 'active' ) ;
@@ -298,6 +313,7 @@ function showNotification(message) {
298313// Initialize resizable panels
299314function initResizer ( ) {
300315 const editorPanel = document . querySelector ( '.editor-panel' ) ;
316+ const isMobileView = window . matchMedia ( '(max-width: 768px)' ) . matches ;
301317
302318 panelResizerElm . addEventListener ( 'mousedown' , function ( e ) {
303319 isResizing = true ;
@@ -312,7 +328,7 @@ function initResizer() {
312328 let newWidth ;
313329
314330 // Check if we're in mobile view (flexbox column)
315- const isMobileView = window . getComputedStyle ( document . querySelector ( '.app-container' ) ) . flexDirection === 'column' ;
331+ const isMobileView = window . matchMedia ( '(max-width: 768px)' ) . matches ;
316332
317333 if ( isMobileView ) {
318334 // In mobile view, resize height instead of width
@@ -341,6 +357,15 @@ function initResizer() {
341357 panelResizerElm . classList . remove ( 'active' ) ;
342358 }
343359 } ) ;
360+
361+ // Set initial width/height based on view
362+ if ( isMobileView ) {
363+ editorPanel . style . height = '50%' ;
364+ editorPanel . style . width = '' ;
365+ } else {
366+ editorPanel . style . width = '50%' ;
367+ editorPanel . style . height = '' ;
368+ }
344369}
345370
346371// Initialize tabs
@@ -368,6 +393,12 @@ function initTabs() {
368393 }
369394 }
370395 } ) ;
396+
397+ // Initialize the first tab
398+ const firstTab = document . querySelector ( '.tab[data-tab="tab1"]' ) ;
399+ if ( firstTab ) {
400+ setActiveTab ( 'tab1' ) ;
401+ }
371402}
372403
373404// Create a new results tab
@@ -535,116 +566,23 @@ window.addEventListener('resize', function() {
535566 }
536567} ) ;
537568
538- // Add CSS for new elements
539- const style = document . createElement ( 'style' ) ;
540- style . textContent = `
541- .loading {
542- display: flex;
543- align-items: center;
544- justify-content: center;
545- flex-direction: column;
546- height: 100px;
547- color: rgba(255, 255, 255, 0.7);
548- }
549-
550- .spinner {
551- width: 30px;
552- height: 30px;
553- border: 3px solid rgba(79, 190, 255, 0.3);
554- border-radius: 50%;
555- border-top-color: #4fbeff;
556- animation: spin 1s ease-in-out infinite;
557- margin-bottom: 15px;
558- }
559-
560- @keyframes spin {
561- to { transform: rotate(360deg); }
562- }
563-
564- .table-wrapper {
565- margin-bottom: 20px;
566- }
567-
568- .table-caption {
569- color: rgba(255, 255, 255, 0.6);
570- font-size: 0.85em;
571- margin-bottom: 8px;
572- text-align: right;
573- }
574-
575- .no-results {
576- color: rgba(255, 255, 255, 0.5);
577- text-align: center;
578- padding: 30px;
579- }
580-
581- .notification {
582- position: fixed;
583- bottom: -60px;
584- left: 50%;
585- transform: translateX(-50%);
586- background: rgba(40, 60, 80, 0.9);
587- color: #fff;
588- padding: 12px 20px;
589- border-radius: 8px;
590- box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
591- transition: bottom 0.3s ease;
592- z-index: 1000;
593- border-left: 3px solid #4fbeff;
594- }
595-
596- .notification.show {
597- bottom: 20px;
598- }
599-
600- .button.active {
601- transform: translateY(1px);
602- box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3) inset;
603- }
604-
605- .results-header, .editor-header {
606- display: flex;
607- justify-content: space-between;
608- align-items: center;
609- margin-bottom: 8px;
610- color: rgba(255, 255, 255, 0.7);
611- font-weight: 500;
612- }
613-
614- .actions {
615- display: flex;
616- flex-wrap: wrap;
617- margin: 15px 0;
618- }
619-
620- .github-corner:hover .octo-arm {
621- animation: octocat-wave 560ms ease-in-out;
622- }
623-
624- @keyframes octocat-wave {
625- 0%, 100% { transform: rotate(0); }
626- 20%, 60% { transform: rotate(-25deg); }
627- 40%, 80% { transform: rotate(10deg); }
628- }
629-
630- @media (max-width: 500px) {
631- .github-corner:hover .octo-arm {
632- animation: none;
633- }
634- .github-corner .octo-arm {
635- animation: octocat-wave 560ms ease-in-out;
636- }
637- }
638- ` ;
639- document . head . appendChild ( style ) ;
640-
641569// Add keyboard shortcuts info
642570document . addEventListener ( 'DOMContentLoaded' , function ( ) {
643571 const editorHeader = document . querySelector ( '.editor-header' ) ;
644572 if ( editorHeader ) {
645573 const shortcuts = document . createElement ( 'div' ) ;
646574 shortcuts . className = 'shortcuts' ;
647- shortcuts . innerHTML = '<span title="Execute: Ctrl/Cmd+Enter, Save: Ctrl/Cmd+S">Keyboard shortcuts</span>' ;
575+ shortcuts . innerHTML = `
576+ <span title="Execute: Ctrl/Cmd+Enter">
577+ <span class="shortcut-key">Ctrl+Enter</span>
578+ </span>
579+ <span title="Save DB: Ctrl/Cmd+S">
580+ <span class="shortcut-key">Ctrl+S</span>
581+ </span>
582+ <span title="Toggle History: Ctrl+Space">
583+ <span class="shortcut-key">Ctrl+Space</span>
584+ </span>
585+ ` ;
648586 editorHeader . appendChild ( shortcuts ) ;
649587 }
650588} ) ;
0 commit comments