Skip to content

Commit 28fe715

Browse files
committed
Added js debugging
1 parent 15974ec commit 28fe715

1 file changed

Lines changed: 40 additions & 25 deletions

File tree

script.js

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -316,20 +316,28 @@ window.addEventListener('hashchange', () => {
316316
if (!hash) {
317317
navigateToHome();
318318
} else if (hash.startsWith('view/')) {
319-
const parts = hash.split('/');
320-
const platform = parts[1];
321-
const problemName = decodeURIComponent(parts.slice(2).join('/'));
322-
const problem = state.data[platform]?.find(p => p.name === problemName);
323-
if (problem) {
324-
state.currentView = 'problem';
325-
state.currentPlatform = platform;
326-
state.currentProblem = problem;
327-
render();
319+
// Remove 'view/' prefix first
320+
const remainder = hash.substring(5);
321+
// Split only on the first slash to separate platform from problem name
322+
const firstSlashIndex = remainder.indexOf('/');
323+
if (firstSlashIndex === -1) {
324+
navigateToHome();
328325
} else {
329-
// Problem not found, go to platform list
330-
state.currentView = 'list';
331-
state.currentPlatform = platform;
332-
render();
326+
const platform = remainder.substring(0, firstSlashIndex);
327+
const problemName = decodeURIComponent(remainder.substring(firstSlashIndex + 1));
328+
console.log('hashchange - Looking for problem:', problemName, 'in platform:', platform);
329+
const problem = state.data[platform]?.find(p => p.name === problemName);
330+
if (problem) {
331+
state.currentView = 'problem';
332+
state.currentPlatform = platform;
333+
state.currentProblem = problem;
334+
render();
335+
} else {
336+
// Problem not found, go to platform list
337+
state.currentView = 'list';
338+
state.currentPlatform = platform;
339+
render();
340+
}
333341
}
334342
} else if (['leetcode', 'kattis', 'vicutils'].includes(hash)) {
335343
navigateToPlatform(hash);
@@ -353,19 +361,26 @@ window.addEventListener('hashchange', () => {
353361
const hash = window.location.hash.slice(1);
354362

355363
if (hash.startsWith('view/')) {
356-
const parts = hash.split('/');
357-
const platform = parts[1];
358-
const problemName = decodeURIComponent(parts.slice(2).join('/'));
359-
console.log('Looking for problem:', problemName, 'in platform:', platform);
360-
console.log('Available problems:', state.data[platform]?.map(p => p.name));
361-
const problem = state.data[platform]?.find(p => p.name === problemName);
362-
if (problem) {
363-
state.currentView = 'problem';
364-
state.currentPlatform = platform;
365-
state.currentProblem = problem;
366-
} else {
367-
console.warn('Problem not found:', problemName);
364+
// Remove 'view/' prefix first
365+
const remainder = hash.substring(5);
366+
// Split only on the first slash to separate platform from problem name
367+
const firstSlashIndex = remainder.indexOf('/');
368+
if (firstSlashIndex === -1) {
368369
state.currentView = 'platforms';
370+
} else {
371+
const platform = remainder.substring(0, firstSlashIndex);
372+
const problemName = decodeURIComponent(remainder.substring(firstSlashIndex + 1));
373+
console.log('Looking for problem:', problemName, 'in platform:', platform);
374+
console.log('Available problems:', state.data[platform]?.map(p => p.name));
375+
const problem = state.data[platform]?.find(p => p.name === problemName);
376+
if (problem) {
377+
state.currentView = 'problem';
378+
state.currentPlatform = platform;
379+
state.currentProblem = problem;
380+
} else {
381+
console.warn('Problem not found:', problemName);
382+
state.currentView = 'platforms';
383+
}
369384
}
370385
} else if (['leetcode', 'kattis', 'vicutils'].includes(hash)) {
371386
state.currentView = 'list';

0 commit comments

Comments
 (0)