Skip to content

Commit

Permalink
Fixes errors not being handled properly
Browse files Browse the repository at this point in the history
Also adds some more visual feedback (the pattern input box turns a light red)
  • Loading branch information
cheeezburga committed Oct 15, 2024
1 parent f67a47a commit 1d9ffd9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
4 changes: 4 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@
color: var(--text-color);
border: 1px solid var(--box-border-color);
}
#pattern.input-error {
background-color: #ffe6e6 !important;
border-color: #ff4d4d !important;
}
.box {
border: 2px solid var(--box-border-color);
border-radius: 8px;
Expand Down
16 changes: 9 additions & 7 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Parser from './js/parser.js';
import Combinator from './js/combinator.js';
import ResultProcessor from './js/resultProcessor.js';

let patternInput;
let tooltip;
let copyNotification;
let allData = null;
Expand All @@ -19,8 +20,8 @@ let totalPagesSpan;
let displayCount;

document.addEventListener('DOMContentLoaded', () => {
const patternInput = document.getElementById('pattern');
const themeToggleButton = document.getElementById('theme-toggle');
patternInput = document.getElementById('pattern');
patternsContent = document.getElementById('patternsContent');
statsContent = document.getElementById('statsContent');
prevPageButton = document.getElementById('prev-page');
Expand Down Expand Up @@ -69,13 +70,14 @@ function debounce(func, delay) {
}

function parsePattern() {
const pattern = document.getElementById('pattern').value;
const pattern = patternInput.value;

// no pattern :(
if (!pattern.trim()) {
patternsContent.innerText = 'Enter a pattern to get started.';
statsContent.innerHTML = '';
resetPagination();
patternInput.classList.remove('input-error');
return;
}

Expand All @@ -93,9 +95,7 @@ function parsePattern() {
const MAX_COMBINATIONS = 100000; // should this be configurable?

if (estimatedCombinations > MAX_COMBINATIONS) {
console.log('Too many combinations!');
displayError('Too many combinations!');
resetPagination();
return;
}

Expand All @@ -115,10 +115,10 @@ function parsePattern() {
updatePagination();
displayStatistics();
showPage(currentPage);

patternInput.classList.remove('input-error');
} catch (error) {
console.error('Invalid syntax pattern: ', error);
displayError('Invalid syntax pattern!');
resetPagination();
}
}

Expand Down Expand Up @@ -260,10 +260,12 @@ function positionTooltip(e) {
}

function displayError(message) {
resetPagination();

patternsContent.innerHTML = `<p class="error">${message}</p>`;
statsContent.innerHTML = '';

resetPagination();
patternInput.classList.add('input-error');
}

function initializeTheme() {
Expand Down

0 comments on commit 1d9ffd9

Please sign in to comment.