1- import { fetchCombinedData } from "./api.js" ;
1+ import { fetchCombinedData , fetchMockBoneData } from "./api.js" ;
22import { populateBonesetDropdown , setupDropdownListeners } from "./dropdowns.js" ;
33import { initializeSidebar } from "./sidebar.js" ;
44import { setupNavigation , setBoneAndSubbones , disableButtons } from "./navigation.js" ;
5- import { loadDescription } from "./description.js" ; // ✅ CORRECT function name
5+ import { loadDescription } from "./description.js" ;
6+ import { displayBoneData , clearViewer } from "./viewer.js" ;
67
78let combinedData = { bonesets : [ ] , bones : [ ] , subbones : [ ] } ;
9+ let mockBoneData = null ;
10+
11+ /**
12+ * Handles bone selection from dropdown
13+ * @param {string } boneId - The ID of the selected bone
14+ */
15+ function handleBoneSelection ( boneId ) {
16+ if ( ! mockBoneData ) {
17+ console . log ( "Mock data not available" ) ;
18+ return ;
19+ }
20+
21+ const bone = mockBoneData . bones . find ( b => b . id === boneId ) ;
22+ if ( ! bone ) {
23+ console . log ( `No mock data found for bone: ${ boneId } ` ) ;
24+ clearViewer ( ) ;
25+ return ;
26+ }
27+
28+ // Use the dedicated viewer module to display the bone
29+ displayBoneData ( bone ) ;
30+ }
831
932document . addEventListener ( "DOMContentLoaded" , async ( ) => {
1033 // 1. Sidebar behavior
1134 initializeSidebar ( ) ;
1235
13- // 2. Fetch data and populate dropdowns
36+ // 2. Load mock bone data using centralized API
37+ mockBoneData = await fetchMockBoneData ( ) ;
38+
39+ // 3. Fetch data and populate dropdowns
1440 combinedData = await fetchCombinedData ( ) ;
1541 populateBonesetDropdown ( combinedData . bonesets ) ;
1642 setupDropdownListeners ( combinedData ) ;
1743
18- // 3 . Hook up navigation buttons
44+ // 4 . Hook up navigation buttons
1945 const prevButton = document . getElementById ( "prev-button" ) ;
2046 const nextButton = document . getElementById ( "next-button" ) ;
2147 const subboneDropdown = document . getElementById ( "subbone-select" ) ;
2248 const boneDropdown = document . getElementById ( "bone-select" ) ;
2349
2450 setupNavigation ( prevButton , nextButton , subboneDropdown , loadDescription ) ;
2551
26- // 4 . Update navigation when bone changes
52+ // 5 . Update navigation when bone changes
2753 boneDropdown . addEventListener ( "change" , ( event ) => {
2854 const selectedBone = event . target . value ;
2955
@@ -34,15 +60,25 @@ document.addEventListener("DOMContentLoaded", async () => {
3460 setBoneAndSubbones ( selectedBone , relatedSubbones ) ;
3561 populateSubboneDropdown ( subboneDropdown , relatedSubbones ) ;
3662 disableButtons ( prevButton , nextButton ) ;
63+
64+ // Handle bone selection using dedicated function
65+ if ( selectedBone ) {
66+ handleBoneSelection ( selectedBone ) ;
67+ } else {
68+ clearViewer ( ) ;
69+ }
3770 } ) ;
3871
39- // 5 . Auto-select the first boneset
72+ // 6 . Auto-select the first boneset
4073 const boneset = combinedData . bonesets [ 0 ] ;
4174 if ( boneset ) {
4275 document . getElementById ( "boneset-select" ) . value = boneset . id ;
4376 const event = new Event ( "change" ) ;
4477 document . getElementById ( "boneset-select" ) . dispatchEvent ( event ) ;
4578 }
79+
80+ // 7. Initialize display
81+ clearViewer ( ) ;
4682} ) ;
4783
4884function populateSubboneDropdown ( dropdown , subbones ) {
0 commit comments