Skip to content

Commit 080fa22

Browse files
Merge pull request #253 from oss-slu/250-use-existing-functions-in-apijs-where-appropriate
Refactor and remove /bone-data endpoint usages
2 parents 8c21481 + 148c90f commit 080fa22

File tree

2 files changed

+4
-25
lines changed

2 files changed

+4
-25
lines changed

templates/js/dropdowns.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { loadDescription } from "./description.js";
33
import { displayBoneImages, clearImages, showPlaceholder } from "./imageDisplay.js";
44
import { loadAndDrawAnnotations, clearAnnotations } from "./annotationOverlay.js";
5+
import {fetchBoneData} from "./api.js";
56

67
// Show the placeholder ASAP
78
document.addEventListener("DOMContentLoaded", () => {
@@ -40,14 +41,7 @@ async function loadBoneImages(boneId, options = {}) {
4041
return;
4142
}
4243
try {
43-
const res = await fetch(`${API_BASE}/api/bone-data/?boneId=${encodeURIComponent(boneId)}`);
44-
if (!res.ok) {
45-
console.warn("bone-data API error:", res.status, boneId);
46-
showPlaceholder();
47-
if (stage) { clearAnnotations(stage); stage.classList.remove("with-annotations"); }
48-
return;
49-
}
50-
const data = await res.json();
44+
const data = await fetchBoneData(boneId);
5145
const images = Array.isArray(data.images) ? data.images : [];
5246
if (images.length === 0) {
5347
showPlaceholder();

templates/js/quiz.js

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// quiz.js - Quiz functionality for Digital Bones Box
22

3-
import { fetchCombinedData } from "./api.js";
3+
import {fetchBoneData, fetchCombinedData} from "./api.js";
44

55
class QuizManager {
66
constructor() {
@@ -120,7 +120,6 @@ class QuizManager {
120120
itemName: correctItem.name,
121121
correctAnswer: correctItem.name,
122122
allAnswers: this.shuffleArray([correctItem.name, ...wrongAnswers]),
123-
imageUrl: this.getImageUrl(correctItem.id)
124123
};
125124

126125
this.questions.push(question);
@@ -160,26 +159,12 @@ class QuizManager {
160159
return shuffled;
161160
}
162161

163-
/**
164-
* Get image URL for an item....
165-
*/
166-
getImageUrl(itemId) {
167-
// Use the API endpoint that serves bone images
168-
return `http://127.0.0.1:8000/api/bone-data/?boneId=${encodeURIComponent(itemId)}`;
169-
}
170-
171162
/**
172163
* Fetch and display bone image from API
173164
*/
174165
async fetchBoneImage(itemId, container) {
175166
try {
176-
const response = await fetch(`http://127.0.0.1:8000/api/bone-data/?boneId=${encodeURIComponent(itemId)}`);
177-
178-
if (!response.ok) {
179-
throw new Error(`HTTP error! status: ${response.status}`);
180-
}
181-
182-
const data = await response.json();
167+
const data = fetchBoneData(itemId);
183168

184169
console.log(`Bone data for ${itemId}:`, data); // DEBUG
185170

0 commit comments

Comments
 (0)