@@ -13,7 +13,6 @@ import {
1313 useRouterState ,
1414} from '@tanstack/react-router'
1515import { TanStackRouterDevtools } from '@tanstack/react-router-devtools'
16- import axios from 'redaxios'
1716import * as Dialog from '@radix-ui/react-dialog'
1817import type { ErrorComponentProps } from '@tanstack/react-router'
1918import './styles.css'
@@ -31,25 +30,34 @@ class NotFoundError extends Error {}
3130const fetchPhotos = async ( ) => {
3231 console . info ( 'Fetching photos...' )
3332 await new Promise ( ( r ) => setTimeout ( r , 500 ) )
34- return axios
35- . get < Array < PhotoType > > ( 'https://jsonplaceholder.typicode.com/photos' )
36- . then ( ( r ) => r . data . slice ( 0 , 10 ) )
33+ // Generate mock photos using picsum.photos since via.placeholder.com is down
34+ return Array . from ( { length : 10 } , ( _ , i ) => ( {
35+ id : String ( i + 1 ) ,
36+ title : `Photo ${ i + 1 } ` ,
37+ url : `https://picsum.photos/600/400?random=${ i + 1 } ` ,
38+ thumbnailUrl : `https://picsum.photos/200/200?random=${ i + 1 } ` ,
39+ albumId : '1' ,
40+ } ) )
3741}
3842
3943const fetchPhoto = async ( photoId : string ) => {
4044 console . info ( `Fetching photo with id ${ photoId } ...` )
4145 await new Promise ( ( r ) => setTimeout ( r , 500 ) )
42- const photo = await axios
43- . get < PhotoType > ( `https://jsonplaceholder.typicode.com/photos/${ photoId } ` )
44- . then ( ( r ) => r . data )
45- . catch ( ( err ) => {
46- if ( err . status === 404 ) {
47- throw new NotFoundError ( `Photo with id "${ photoId } " not found!` )
48- }
49- throw err
50- } )
51-
52- return photo
46+
47+ // Simulate photo not found for invalid IDs
48+ const photoIdNum = parseInt ( photoId , 10 )
49+ if ( isNaN ( photoIdNum ) || photoIdNum < 1 || photoIdNum > 10 ) {
50+ throw new NotFoundError ( `Photo with id "${ photoId } " not found!` )
51+ }
52+
53+ // Generate mock photo using picsum.photos
54+ return {
55+ id : photoId ,
56+ title : `Photo ${ photoId } ` ,
57+ url : `https://picsum.photos/600/400?random=${ photoId } ` ,
58+ thumbnailUrl : `https://picsum.photos/200/200?random=${ photoId } ` ,
59+ albumId : '1' ,
60+ }
5361}
5462
5563type PhotoModal = {
0 commit comments