Skip to content

Commit 8aa6319

Browse files
committed
added math test models to sample sidebar
1 parent dc60d22 commit 8aa6319

File tree

1 file changed

+56
-1
lines changed

1 file changed

+56
-1
lines changed

src/components/SampleSidebar.tsx

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export const SampleSidebar: React.FC<SampleSidebarProps> = ({ onSelectModel }) =
3232
const [show, setShow] = useState(false);
3333
const [sampleModels, setSampleModels] = useState<Sample[]>([]);
3434
const [testModels, setTestModels] = useState<Sample[]>([]);
35+
const [mathTestModels, setMathTestModels] = useState<Sample[]>([]);
3536
const [loading, setLoading] = useState(false);
3637
const [error, setError] = useState<string | null>(null);
3738
const [debugData, setDebugData] = useState<unknown>(null);
@@ -72,11 +73,23 @@ export const SampleSidebar: React.FC<SampleSidebarProps> = ({ onSelectModel }) =
7273
if (!testResponse.ok) {
7374
throw new Error(`Failed to fetch test assets: ${testResponse.status}`);
7475
}
76+
77+
// Fetch test models
78+
const mathTestResponse = await fetch(
79+
'https://raw.githubusercontent.com/needle-tools/glTF-Interactivity-Sample-Assets/main/Tests/Interactivity/mathtests-index.json'
80+
);
7581

82+
if (!mathTestResponse.ok) {
83+
throw new Error(`Failed to fetch test assets: ${mathTestResponse.status}`);
84+
}
85+
86+
7687
const testData = await testResponse.json();
7788
console.log('Received test data:', testData);
89+
const mathTestData = await mathTestResponse.json();
90+
console.log('Received math test data:', testData);
7891

79-
setDebugData({ samples: sampleData, tests: testData });
92+
setDebugData({ samples: sampleData, tests: testData, mathtests : mathTestData });
8093

8194
// Make sure the data is an array before setting it
8295
if (Array.isArray(sampleData)) {
@@ -92,6 +105,14 @@ export const SampleSidebar: React.FC<SampleSidebarProps> = ({ onSelectModel }) =
92105
console.error('Received invalid test data format:', testData);
93106
setTestModels([]);
94107
}
108+
109+
if (Array.isArray(mathTestData)) {
110+
setMathTestModels(mathTestData);
111+
} else {
112+
console.error('Received invalid math test data format:', mathTestData);
113+
setTestModels([]);
114+
}
115+
95116
} catch (err) {
96117
console.error('Error fetching data:', err);
97118
setSampleModels([]);
@@ -248,6 +269,40 @@ export const SampleSidebar: React.FC<SampleSidebarProps> = ({ onSelectModel }) =
248269
</ListGroup>
249270
</>
250271
)}
272+
273+
274+
{mathTestModels.length > 0 && (
275+
<>
276+
<h5 className="mt-4 mb-2">Math Test Assets</h5>
277+
<a href="https://github.com/needle-tools/glTF-Interactivity-Sample-Assets/" target="_blank">See on GitHub</a>
278+
<ListGroup>
279+
{mathTestModels.map((model, index) => (
280+
<ListGroup.Item
281+
key={index}
282+
action
283+
onClick={() => handleSelectSample(model, true)}
284+
className="d-flex flex-column align-items-start"
285+
>
286+
<div className="d-flex w-100 justify-content-between">
287+
<h6 className="mb-1">{model.label || model.name}</h6>
288+
</div>
289+
{model.tags && Array.isArray(model.tags) && model.tags.length > 0 && (
290+
<div className="mt-1">
291+
{model.tags.map((tag, tagIndex) => (
292+
<span
293+
key={tagIndex}
294+
className="badge bg-secondary me-1"
295+
>
296+
{tag}
297+
</span>
298+
))}
299+
</div>
300+
)}
301+
</ListGroup.Item>
302+
))}
303+
</ListGroup>
304+
</>
305+
)}
251306
</>
252307
</Offcanvas.Body>
253308
</Offcanvas>

0 commit comments

Comments
 (0)