@@ -2,11 +2,11 @@ import React, { useState, useCallback, useRef, useEffect } from 'react';
22import SearchBar from './components/SearchBar' ;
33import Lightbox from './components/Lightbox' ;
44import SearchResults from './components/SearchResults' ;
5- import { searchByText , searchByImage , getImageUrl , getEmbeddingStats } from './services/api' ;
5+ import { searchByText , searchByImage , getEmbeddingStats , getIiifInfo } from './services/api' ;
66import './App.css' ;
77
88function App ( ) {
9- const [ photos , setPhotos ] = useState ( [ ] ) ;
9+ const [ maps , setMaps ] = useState ( [ ] ) ;
1010 const [ searchQuery , setSearchQuery ] = useState ( '' ) ;
1111 const [ isLoading , setIsLoading ] = useState ( false ) ;
1212 const [ error , setError ] = useState ( null ) ;
@@ -32,9 +32,9 @@ function App() {
3232 fetchEmbeddingStats ( ) ;
3333 } , [ ] ) ;
3434
35- const formatPhotosForGallery = ( results ) => {
35+ const formatItemsForGallery = ( results ) => {
3636 return results . map ( result => ( {
37- src : getImageUrl ( result . id , 200 ) ,
37+ src : result . metadata . paths . thumbnail ,
3838 width : 200 ,
3939 height : 150 ,
4040 alt : result . file_name ,
@@ -50,7 +50,7 @@ function App() {
5050
5151 try {
5252 const results = await searchByText ( query , resultsPerPage , currentPage ) ;
53- setPhotos ( formatPhotosForGallery ( results ) ) ;
53+ setMaps ( formatItemsForGallery ( results ) ) ;
5454 setHasMore ( results . length >= resultsPerPage ) ;
5555 } catch ( error ) {
5656 console . error ( 'Error performing search:' , error ) ;
@@ -66,7 +66,7 @@ function App() {
6666
6767 try {
6868 const results = await searchByImage ( image , resultsPerPage , currentPage ) ;
69- setPhotos ( formatPhotosForGallery ( results ) ) ;
69+ setMaps ( formatItemsForGallery ( results ) ) ;
7070 setHasMore ( results . length >= resultsPerPage ) ;
7171 } catch ( error ) {
7272 console . error ( 'Error performing search:' , error ) ;
@@ -84,21 +84,28 @@ function App() {
8484 }
8585 } , [ currentPage ] ) ;
8686
87- const handleLightboxOpened = useCallback ( ( index ) => {
88- const selectedItem = photos [ index ] . originalData ;
89- const imageUrl = getImageUrl ( selectedItem . id , 1600 ) ;
87+ const handleLightboxOpened = useCallback ( async ( selectedMap ) => {
88+ try {
89+ const iiifInfo = await getIiifInfo ( selectedMap . originalData . metadata . iiif_id ) ;
9090
91- setSelectedMap ( imageUrl ) ;
92- } , [ photos ] ) ;
91+ setSelectedMap ( {
92+ ...selectedMap . originalData ,
93+ iiifInfo : iiifInfo
94+ } ) ;
95+ } catch ( error ) {
96+ console . error ( "Failed to get IIIF info:" , error ) ;
97+ setError ( 'Failed to get IIIF info from Library of Congress\'s API. Please try again.' ) ;
98+ }
99+ } , [ setSelectedMap ] ) ;
93100
94101 const handleLightboxClosed = useCallback ( ( ) => {
95102 setSelectedMap ( null ) ;
96- } , [ ] ) ;
103+ } , [ setSelectedMap ] ) ;
97104
98105 const handleSearchModeChanged = useCallback ( ( mode ) => {
99106 setSearchMode ( mode ) ;
100107 setCurrentPage ( 1 ) ;
101- setPhotos ( [ ] ) ;
108+ setMaps ( [ ] ) ;
102109 setHasMore ( false ) ;
103110
104111 if ( mode === 'text' ) {
@@ -135,7 +142,7 @@ function App() {
135142 </ p >
136143 ) }
137144 < SearchResults
138- photos = { photos }
145+ items = { maps }
139146 isLoading = { isLoading }
140147 error = { error }
141148 onClick = { handleLightboxOpened }
@@ -147,7 +154,7 @@ function App() {
147154
148155 < Lightbox
149156 isVisible = { ! ! selectedMap }
150- imageUrl = { selectedMap }
157+ data = { selectedMap }
151158 onBack = { handleLightboxClosed }
152159 />
153160 </ div >
0 commit comments