Skip to content

Commit bcd90f9

Browse files
committed
all existing boards can now be loaded into the editor
1 parent 79780ee commit bcd90f9

File tree

3 files changed

+48
-43
lines changed

3 files changed

+48
-43
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ node_modules
33

44
public/dist
55
public/pinouts/*.svg
6+
public/index.json

public/index.html

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -16,52 +16,12 @@
1616
<div class="panel panel-editor">
1717
<div id="editor"></div>
1818
<p>
19-
<label for="example-select">Load an Example:</label>
19+
<label for="example-select">Load an existing definition:</label>
2020
<select name="examples" id="example-select">
21-
<option value="">--Please choose an example--</option>
21+
<option value="">pick a board</option>
2222
</select>
2323
</p>
24-
<script>
25-
document.addEventListener('DOMContentLoaded', () => {
26-
const selectElement = document.getElementById('example-select');
2724

28-
fetch('index.json')
29-
.then(response => {
30-
if (!response.ok) {
31-
throw new Error(`HTTP error! status: ${response.status}`);
32-
}
33-
return response.json();
34-
})
35-
.then(data => {
36-
// Sort examples alphabetically by title
37-
const sortedExamples = Object.entries(data).sort(([, titleA], [, titleB]) =>
38-
titleA.localeCompare(titleB)
39-
);
40-
41-
sortedExamples.forEach(([path, title]) => {
42-
const option = document.createElement('option');
43-
option.value = path;
44-
option.textContent = title;
45-
selectElement.appendChild(option);
46-
});
47-
})
48-
.catch(error => {
49-
console.error('Error loading or parsing index.json:', error);
50-
// Optionally disable the select or show an error message
51-
selectElement.disabled = true;
52-
const errorOption = document.createElement('option');
53-
errorOption.textContent = 'Error loading examples';
54-
selectElement.appendChild(errorOption);
55-
});
56-
57-
selectElement.addEventListener('change', (event) => {
58-
const selectedPath = event.target.value;
59-
if (selectedPath) {
60-
window.location.search = `?load=${encodeURIComponent(selectedPath)}`;
61-
}
62-
});
63-
});
64-
</script>
6525

6626
<p>
6727
<b>Learn more</b> about the tool and available config options in the
@@ -82,5 +42,49 @@
8242
<p>
8343
<small>A tool made by <a href="https://www.splitbrain.org">splitbrain</a></small>
8444
</p>
45+
46+
47+
<script>
48+
// load existing definitions
49+
document.addEventListener('DOMContentLoaded', () => {
50+
const selectElement = document.getElementById('example-select');
51+
52+
fetch('index.json')
53+
.then(response => {
54+
if (!response.ok) {
55+
throw new Error(`HTTP error! status: ${response.status}`);
56+
}
57+
return response.json();
58+
})
59+
.then(data => {
60+
// Sort examples alphabetically by title
61+
const sortedExamples = Object.entries(data).sort(([, titleA], [, titleB]) =>
62+
titleA.localeCompare(titleB)
63+
);
64+
65+
sortedExamples.forEach(([path, title]) => {
66+
const option = document.createElement('option');
67+
option.value = path;
68+
option.textContent = title;
69+
selectElement.appendChild(option);
70+
});
71+
})
72+
.catch(error => {
73+
console.error('Error loading or parsing index.json:', error);
74+
// Optionally disable the select or show an error message
75+
selectElement.disabled = true;
76+
const errorOption = document.createElement('option');
77+
errorOption.textContent = 'Error loading examples';
78+
selectElement.appendChild(errorOption);
79+
});
80+
81+
selectElement.addEventListener('change', (event) => {
82+
const selectedPath = event.target.value;
83+
if (selectedPath) {
84+
window.location.search = `?load=${encodeURIComponent(selectedPath)}`;
85+
}
86+
});
87+
});
88+
</script>
8589
</body>
8690
</html>

src/Editor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export class Editor {
9494
if (savedYaml) {
9595
this.ace.setValue(savedYaml, -1);
9696
} else {
97-
this.ace.setValue("# Hi!\n# New here? Load an example from below!", -1);
97+
this.ace.setValue("# Hi!\n# New here? Load an existing definition from below!", -1);
9898
}
9999
}
100100
}

0 commit comments

Comments
 (0)