Skip to content

Commit eb13147

Browse files
committed
history improvements
1 parent 754e7a4 commit eb13147

File tree

2 files changed

+66
-6
lines changed

2 files changed

+66
-6
lines changed

examples/GUI/demo.css

+20-4
Original file line numberDiff line numberDiff line change
@@ -453,21 +453,37 @@ footer a:hover {
453453

454454
.query-history {
455455
position: absolute;
456-
top: 100%;
456+
top: 0;
457457
left: 0;
458458
right: 0;
459459
background: rgba(30, 40, 50, 0.95);
460-
border-top: 1px solid var(--border-subtle);
460+
border: 1px solid var(--border-subtle);
461461
max-height: 0;
462+
height: 0;
463+
opacity: 0;
464+
visibility: hidden;
462465
overflow: hidden;
463-
transition: max-height 0.3s ease;
466+
transition: all 0.3s ease;
464467
z-index: 100;
465-
box-shadow: var(--shadow-strong);
468+
box-shadow: none;
469+
border-radius: var(--radius-md);
470+
margin: 10px;
466471
}
467472

468473
.query-history.show {
469474
max-height: 300px;
475+
height: auto;
476+
opacity: 1;
477+
visibility: visible;
470478
overflow-y: auto;
479+
box-shadow: 0 0 20px rgba(79, 190, 255, 0.2), var(--shadow-strong);
480+
}
481+
482+
.query-history-empty {
483+
padding: 20px;
484+
text-align: center;
485+
color: var(--text-muted);
486+
font-style: italic;
471487
}
472488

473489
.history-item {

examples/GUI/gui.js

+46-2
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,14 @@ function addToHistory(query) {
583583
function updateHistoryUI() {
584584
elements.queryHistoryElm.innerHTML = '';
585585

586+
if (state.queryHistory.length === 0) {
587+
const emptyMessage = document.createElement('div');
588+
emptyMessage.className = 'query-history-empty';
589+
emptyMessage.textContent = 'No query history yet';
590+
elements.queryHistoryElm.appendChild(emptyMessage);
591+
return;
592+
}
593+
586594
state.queryHistory.forEach((item) => {
587595
const historyItem = createHistoryItem(item);
588596
elements.queryHistoryElm.appendChild(historyItem);
@@ -621,7 +629,29 @@ function truncateString(str, maxLength) {
621629
}
622630

623631
function toggleQueryHistory() {
624-
elements.queryHistoryElm.classList.toggle('show');
632+
// Don't open history if there are no items
633+
if (!elements.queryHistoryElm.classList.contains('show') && state.queryHistory.length === 0) {
634+
showNotification('No query history yet');
635+
return;
636+
}
637+
638+
const historyElement = elements.queryHistoryElm;
639+
const isVisible = historyElement.classList.contains('show');
640+
641+
if (!isVisible) {
642+
// Position the history panel over the editor
643+
const editorRect = editor.getWrapperElement().getBoundingClientRect();
644+
historyElement.style.width = `${editorRect.width - 20}px`;
645+
historyElement.style.top = '10px';
646+
historyElement.style.height = 'auto';
647+
historyElement.style.maxHeight = `${editorRect.height - 20}px`;
648+
}
649+
650+
historyElement.classList.toggle('show');
651+
}
652+
653+
function closeQueryHistory() {
654+
elements.queryHistoryElm.classList.remove('show');
625655
}
626656

627657
// Toggle history button
@@ -632,7 +662,21 @@ document.addEventListener('click', function(e) {
632662
if (elements.queryHistoryElm.classList.contains('show') &&
633663
!elements.queryHistoryElm.contains(e.target) &&
634664
e.target !== elements.toggleHistoryBtn) {
635-
elements.queryHistoryElm.classList.remove('show');
665+
closeQueryHistory();
666+
}
667+
});
668+
669+
// Close history when pressing Escape
670+
document.addEventListener('keydown', function(e) {
671+
if (e.key === 'Escape' && elements.queryHistoryElm.classList.contains('show')) {
672+
closeQueryHistory();
673+
}
674+
});
675+
676+
// Close history when editing code
677+
editor.on('change', function() {
678+
if (elements.queryHistoryElm.classList.contains('show')) {
679+
closeQueryHistory();
636680
}
637681
});
638682

0 commit comments

Comments
 (0)