Skip to content

Commit 92e9f0a

Browse files
fix paths
1 parent e10c7e4 commit 92e9f0a

2 files changed

Lines changed: 82 additions & 30 deletions

File tree

filesystem-explorer.js

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Library file for cluster0.
3737
This contains shared code that can be imported by problems in this cluster.
3838
"""`,
3939

40-
"580_c_kefa_and_park_5570/": {
40+
"580_c_kefa_and_park_5570": {
4141
"PROBLEM.md": `# 580_C. Kefa and Park
4242
4343
**ID:** 580_c_kefa_and_park_5570
@@ -85,7 +85,7 @@ while i<len(q):
8585
i+=1
8686
print(a)`,
8787
"tags.txt": "dfs and similar\\ngraphs\\ntrees",
88-
"tests/": {
88+
"tests": {
8989
"input_1.txt": "7 1\\n1 0 1 1 0 0 0\\n1 2\\n1 3\\n2 4\\n2 5\\n3 6\\n3 7",
9090
"output_1.txt": "2",
9191
"input_2.txt": "4 1\\n1 1 0 0\\n1 2\\n1 3\\n1 4",
@@ -109,7 +109,7 @@ print(a)`,
109109
}
110110
},
111111

112-
"116_c_party_7303/": {
112+
"116_c_party_7303": {
113113
"PROBLEM.md": `# 116_C. Party
114114
115115
**ID:** 116_c_party_7303
@@ -177,7 +177,7 @@ for i in range(n):
177177
178178
print(max([findDepth(a, i) for i in roots]))`,
179179
"tags.txt": "dfs and similar\\ngraphs\\ntrees",
180-
"tests/": {
180+
"tests": {
181181
"input_1.txt": "5\\n-1\\n1\\n2\\n1\\n-1",
182182
"output_1.txt": "3",
183183
"input_2.txt": "12\\n-1\\n8\\n9\\n-1\\n4\\n2\\n11\\n1\\n-1\\n6\\n-1\\n10",
@@ -201,7 +201,7 @@ print(max([findDepth(a, i) for i in roots]))`,
201201
}
202202
},
203203

204-
"292_b_network_topology_9930/": {
204+
"292_b_network_topology_9930": {
205205
"PROBLEM.md": `# 292_B. Network Topology
206206
207207
**ID:** 292_b_network_topology_9930
@@ -248,7 +248,7 @@ elif c1==n-1 and cs==1:
248248
else:
249249
print("unknown topology")`,
250250
"tags.txt": "graphs\\nimplementation",
251-
"tests/": {
251+
"tests": {
252252
"input_1.txt": "4 3\\n1 2\\n2 3\\n3 4",
253253
"output_1.txt": "bus topology",
254254
"input_2.txt": "4 4\\n1 2\\n2 3\\n3 4\\n4 1",
@@ -272,7 +272,7 @@ else:
272272
}
273273
},
274274

275-
"913_b_christmas_spruce_7977/": {
275+
"913_b_christmas_spruce_7977": {
276276
"PROBLEM.md": `# 913_B. Christmas Spruce
277277
278278
**ID:** 913_b_christmas_spruce_7977
@@ -321,7 +321,7 @@ if __name__ == '__main__':
321321
322322
print("Yes")`,
323323
"tags.txt": "implementation\\ntrees",
324-
"tests/": {
324+
"tests": {
325325
"input_1.txt": "4\\n1\\n1\\n1",
326326
"output_1.txt": "Yes",
327327
"input_2.txt": "8\\n1\\n1\\n1\\n1\\n3\\n3\\n3",
@@ -345,7 +345,7 @@ if __name__ == '__main__':
345345
}
346346
},
347347

348-
"982_c_cut_em_all_5275/": {
348+
"982_c_cut_em_all_5275": {
349349
"PROBLEM.md": `# 982_C. Cut 'em all!
350350
351351
**ID:** 982_c_cut_em_all_5275
@@ -403,7 +403,7 @@ t = threading.Thread(target=main)
403403
t.start()
404404
t.join()`,
405405
"tags.txt": "dfs and similar\\ndp\\ngraphs\\ngreedy\\ntrees",
406-
"tests/": {
406+
"tests": {
407407
"input_1.txt": "4\\n2 4\\n4 1\\n3 1",
408408
"output_1.txt": "1",
409409
"input_2.txt": "2\\n1 2",
@@ -446,10 +446,15 @@ t.join()`,
446446
<h3>🗂️ MiniCode CodeContests Collection (Before Refactoring)</h3>
447447
<div class="filesystem-path">
448448
<span class="path-segment" data-path="">📁 cluster0</span>
449-
${this.currentPath.map((segment, index) =>
450-
`<span class="path-separator">/</span>
451-
<span class="path-segment" data-path="${this.currentPath.slice(0, index + 1).join('/')}">${segment}</span>`
452-
).join('')}
449+
${this.currentPath.map((segment, index) => {
450+
const pathToHere = this.currentPath.slice(0, index + 1).join('/');
451+
// Check if this is a valid navigation target (not the final file)
452+
const isValidNavTarget = index < this.currentPath.length - 1 || typeof this.getCurrentDirectory() === 'object';
453+
const clickHandler = isValidNavTarget ? `data-path="${pathToHere}"` : '';
454+
const className = isValidNavTarget ? 'path-segment' : 'path-segment path-segment-file';
455+
return `<span class="path-separator">/</span>
456+
<span class="${className}" ${clickHandler}>${segment}</span>`;
457+
}).join('')}
453458
</div>
454459
</div>
455460
<div class="filesystem-content">
@@ -527,7 +532,28 @@ t.join()`,
527532
if (path === '') {
528533
this.currentPath = [];
529534
} else {
530-
this.currentPath = path.split('/').filter(p => p);
535+
const segments = path.split('/').filter(p => p);
536+
// For the filesystem structure, problems are at root level
537+
// So we just need to validate that the full path exists
538+
let current = this.filesystem;
539+
let validPath = [];
540+
541+
for (const segment of segments) {
542+
if (current && typeof current === 'object' && current[segment] !== undefined) {
543+
current = current[segment];
544+
validPath.push(segment);
545+
} else {
546+
break;
547+
}
548+
}
549+
550+
// Only navigate if we found a valid directory path
551+
if (validPath.length === segments.length && typeof current === 'object') {
552+
this.currentPath = validPath;
553+
} else if (validPath.length > 0) {
554+
// Navigate to the deepest valid directory
555+
this.currentPath = validPath;
556+
}
531557
}
532558
this.render();
533559
}

filesystem-refactored.js

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ def run_with_threading(func):
582582
# Common input patterns
583583
M = lambda: map(int, input().split())`,
584584

585-
"580_c_kefa_and_park_5570/": {
585+
"580_c_kefa_and_park_5570": {
586586
"PROBLEM.md": `# 580_C. Kefa and Park
587587
588588
**ID:** 580_c_kefa_and_park_5570
@@ -729,7 +729,7 @@ else
729729
exit 1
730730
fi`,
731731
"tags.txt": "dfs and similar\\ngraphs\\ntrees",
732-
"tests/": {
732+
"tests": {
733733
"input_1.txt": "7 1\\n1 0 1 1 0 0 0\\n1 2\\n1 3\\n2 4\\n2 5\\n3 6\\n3 7",
734734
"output_1.txt": "2",
735735
"input_2.txt": "4 1\\n1 1 0 0\\n1 2\\n1 3\\n1 4",
@@ -753,7 +753,7 @@ fi`,
753753
}
754754
},
755755

756-
"116_c_party_7303/": {
756+
"116_c_party_7303": {
757757
"PROBLEM.md": `# 116_C. Party
758758
759759
**ID:** 116_c_party_7303
@@ -878,7 +878,7 @@ else
878878
exit 1
879879
fi`,
880880
"tags.txt": "dfs and similar\\ngraphs\\ntrees",
881-
"tests/": {
881+
"tests": {
882882
"input_1.txt": "5\\n-1\\n1\\n2\\n1\\n-1",
883883
"output_1.txt": "3",
884884
"input_2.txt": "12\\n-1\\n8\\n9\\n-1\\n4\\n2\\n11\\n1\\n-1\\n6\\n-1\\n10",
@@ -902,7 +902,7 @@ fi`,
902902
}
903903
},
904904

905-
"292_b_network_topology_9930/": {
905+
"292_b_network_topology_9930": {
906906
"PROBLEM.md": `# 292_B. Network Topology
907907
908908
**ID:** 292_b_network_topology_9930
@@ -1033,7 +1033,7 @@ else
10331033
exit 1
10341034
fi`,
10351035
"tags.txt": "graphs\\nimplementation",
1036-
"tests/": {
1036+
"tests": {
10371037
"input_1.txt": "4 3\\n1 2\\n2 3\\n3 4",
10381038
"output_1.txt": "bus topology",
10391039
"input_2.txt": "4 4\\n1 2\\n2 3\\n3 4\\n4 1",
@@ -1057,7 +1057,7 @@ fi`,
10571057
}
10581058
},
10591059

1060-
"913_b_christmas_spruce_7977/": {
1060+
"913_b_christmas_spruce_7977": {
10611061
"PROBLEM.md": `# 913_B. Christmas Spruce
10621062
10631063
**ID:** 913_b_christmas_spruce_7977
@@ -1190,7 +1190,7 @@ else
11901190
exit 1
11911191
fi`,
11921192
"tags.txt": "implementation\\ntrees",
1193-
"tests/": {
1193+
"tests": {
11941194
"input_1.txt": "4\\n1\\n1\\n1",
11951195
"output_1.txt": "Yes",
11961196
"input_2.txt": "8\\n1\\n1\\n1\\n1\\n3\\n3\\n3",
@@ -1214,7 +1214,7 @@ fi`,
12141214
}
12151215
},
12161216

1217-
"982_c_cut_em_all_5275/": {
1217+
"982_c_cut_em_all_5275": {
12181218
"PROBLEM.md": `# 982_C. Cut 'em all!
12191219
12201220
**ID:** 982_c_cut_em_all_5275
@@ -1343,7 +1343,7 @@ else
13431343
exit 1
13441344
fi`,
13451345
"tags.txt": "dfs and similar\\ndp\\ngraphs\\ngreedy\\ntrees",
1346-
"tests/": {
1346+
"tests": {
13471347
"input_1.txt": "4\\n2 4\\n4 1\\n3 1",
13481348
"output_1.txt": "1",
13491349
"input_2.txt": "2\\n1 2",
@@ -1386,10 +1386,15 @@ fi`,
13861386
<h3>🗂️ MiniCode CodeContests Collection (After Refactoring)</h3>
13871387
<div class="filesystem-path">
13881388
<span class="path-segment" data-path="">📁 cluster0</span>
1389-
${this.currentPath.map((segment, index) =>
1390-
`<span class="path-separator">/</span>
1391-
<span class="path-segment" data-path="${this.currentPath.slice(0, index + 1).join('/')}">${segment}</span>`
1392-
).join('')}
1389+
${this.currentPath.map((segment, index) => {
1390+
const pathToHere = this.currentPath.slice(0, index + 1).join('/');
1391+
// Check if this is a valid navigation target (not the final file)
1392+
const isValidNavTarget = index < this.currentPath.length - 1 || typeof this.getCurrentDirectory() === 'object';
1393+
const clickHandler = isValidNavTarget ? `data-path="${pathToHere}"` : '';
1394+
const className = isValidNavTarget ? 'path-segment' : 'path-segment path-segment-file';
1395+
return `<span class="path-separator">/</span>
1396+
<span class="${className}" ${clickHandler}>${segment}</span>`;
1397+
}).join('')}
13931398
</div>
13941399
</div>
13951400
<div class="filesystem-content">
@@ -1467,7 +1472,28 @@ fi`,
14671472
if (path === '') {
14681473
this.currentPath = [];
14691474
} else {
1470-
this.currentPath = path.split('/').filter(p => p);
1475+
const segments = path.split('/').filter(p => p);
1476+
// For the filesystem structure, problems are at root level
1477+
// So we just need to validate that the full path exists
1478+
let current = this.filesystem;
1479+
let validPath = [];
1480+
1481+
for (const segment of segments) {
1482+
if (current && typeof current === 'object' && current[segment] !== undefined) {
1483+
current = current[segment];
1484+
validPath.push(segment);
1485+
} else {
1486+
break;
1487+
}
1488+
}
1489+
1490+
// Only navigate if we found a valid directory path
1491+
if (validPath.length === segments.length && typeof current === 'object') {
1492+
this.currentPath = validPath;
1493+
} else if (validPath.length > 0) {
1494+
// Navigate to the deepest valid directory
1495+
this.currentPath = validPath;
1496+
}
14711497
}
14721498
this.render();
14731499
}

0 commit comments

Comments
 (0)