Skip to content

Commit c16b2c1

Browse files
committed
Adding nice UI - cards instead of files tree
1 parent efb3147 commit c16b2c1

File tree

1 file changed

+70
-36
lines changed

1 file changed

+70
-36
lines changed

docs/index.html

Lines changed: 70 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,48 @@
66
<style>
77
body {
88
font-family: sans-serif;
9-
display: flex;
10-
height: 100vh;
119
margin: 0;
12-
}
13-
#sidebar {
14-
width: 300px;
15-
background: #f4f4f4;
1610
padding: 1rem;
17-
overflow-y: auto;
18-
border-right: 1px solid #ddd;
11+
background: #f7f7f7;
12+
}
13+
h1, h2 {
14+
text-align: center;
15+
}
16+
#container {
17+
display: flex;
18+
flex-wrap: wrap;
19+
justify-content: center;
20+
gap: 1rem;
1921
}
20-
#content {
21-
flex: 1;
22+
.card {
23+
background: white;
24+
border-radius: 10px;
25+
box-shadow: 0 2px 6px rgba(0,0,0,0.1);
2226
padding: 1rem;
23-
overflow: auto;
27+
width: 200px;
28+
text-align: center;
29+
cursor: pointer;
30+
transition: transform 0.2s;
2431
}
25-
ul {
26-
list-style-type: none;
27-
padding-left: 1rem;
32+
.card:hover {
33+
transform: scale(1.05);
2834
}
29-
li {
35+
#backBtn {
36+
display: none;
37+
margin-bottom: 1rem;
3038
cursor: pointer;
31-
margin: 0.2rem 0;
39+
background: #ddd;
40+
border: none;
41+
padding: 0.5rem 1rem;
42+
border-radius: 5px;
3243
}
3344
pre {
3445
background: #1e1e1e;
3546
color: #dcdcdc;
3647
padding: 1rem;
3748
border-radius: 8px;
3849
overflow-x: auto;
50+
white-space: pre-wrap;
3951
}
4052
</style>
4153
<!-- Highlight.js -->
@@ -44,21 +56,27 @@
4456
<script>hljs.highlightAll();</script>
4557
</head>
4658
<body>
47-
<div id="sidebar"><strong>📁 תפריט קבצים</strong><div id="tree"></div></div>
48-
<div id="content"><em>בחר קובץ מהתפריט כדי לצפות בקוד.</em></div>
59+
<h1>LeetCode Solutions</h1>
60+
<h2 id="pathTitle">Click to view solutions</h2>
61+
<button id="backBtn">⬅ Back</button>
62+
<div id="container"></div>
63+
<div id="codeViewer"></div>
4964

5065
<script>
5166
const owner = "efrat-dev";
5267
const repo = "algo-ds-leetcode";
5368
const branch = "main";
5469
const baseUrl = `https://raw.githubusercontent.com/${owner}/${repo}/${branch}/`;
5570

71+
let fullTree = {};
72+
let history = [];
73+
5674
fetch(`https://api.github.com/repos/${owner}/${repo}/git/trees/${branch}?recursive=1`)
5775
.then(res => res.json())
5876
.then(data => {
5977
const files = data.tree.filter(item => item.type === "blob" && item.path.endsWith(".cs"));
60-
const treeData = buildTree(files.map(f => f.path));
61-
renderTree(treeData, document.getElementById("tree"));
78+
fullTree = buildTree(files.map(f => f.path));
79+
renderLevel(fullTree, "Click to view solutions");
6280
});
6381

6482
function buildTree(paths) {
@@ -68,42 +86,58 @@
6886
let curr = root;
6987
for (let i = 0; i < parts.length; i++) {
7088
const part = parts[i];
71-
if (!curr[part]) curr[part] = (i === parts.length - 1) ? path : {};
89+
if (!curr[part]) {
90+
curr[part] = (i === parts.length - 1) ? path : {};
91+
}
7292
curr = curr[part];
7393
}
7494
}
7595
return root;
7696
}
7797

78-
function renderTree(tree, container) {
79-
const ul = document.createElement("ul");
80-
for (const key in tree) {
81-
const li = document.createElement("li");
82-
if (typeof tree[key] === "string") {
83-
li.textContent = key;
84-
li.onclick = () => loadFile(tree[key]);
85-
} else {
86-
li.innerHTML = `📁 ${key}`;
87-
renderTree(tree[key], li);
88-
}
89-
ul.appendChild(li);
98+
function renderLevel(level, title) {
99+
const container = document.getElementById("container");
100+
container.innerHTML = "";
101+
document.getElementById("codeViewer").innerHTML = "";
102+
document.getElementById("pathTitle").innerText = title;
103+
document.getElementById("backBtn").style.display = history.length ? "inline-block" : "none";
104+
105+
for (const key in level) {
106+
const card = document.createElement("div");
107+
card.className = "card";
108+
card.innerText = key.replace(/\.cs$/, "");
109+
card.onclick = () => {
110+
if (typeof level[key] === "string") {
111+
loadFile(level[key]);
112+
} else {
113+
history.push({ level, title });
114+
renderLevel(level[key], key);
115+
}
116+
};
117+
container.appendChild(card);
90118
}
91-
container.appendChild(ul);
92119
}
93120

94121
function loadFile(path) {
95122
const url = baseUrl + path;
96123
fetch(url)
97124
.then(res => res.text())
98125
.then(code => {
99-
document.getElementById("content").innerHTML = `
100-
<h3>${path}</h3>
126+
document.getElementById("container").innerHTML = "";
127+
document.getElementById("pathTitle").innerText = path;
128+
document.getElementById("codeViewer").innerHTML = `
101129
<pre><code class="language-csharp">${escapeHtml(code)}</code></pre>
102130
`;
103131
hljs.highlightAll();
132+
document.getElementById("backBtn").style.display = "inline-block";
104133
});
105134
}
106135

136+
document.getElementById("backBtn").onclick = () => {
137+
const prev = history.pop();
138+
renderLevel(prev.level, prev.title);
139+
};
140+
107141
function escapeHtml(text) {
108142
return text.replace(/[&<>"']/g, m => ({
109143
'&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#039;'

0 commit comments

Comments
 (0)