@@ -3,7 +3,7 @@ import { NextPage } from 'next'
33import Image from 'next/image'
44
55import { ParkingCard } from '@/components/common'
6- import { parkingNames , parkingLimit } from '@/constants/parkingNames'
6+ import { parkings } from '@/constants/parkingNames'
77import { ParkingData , Parking } from '@/type/parking.type'
88
99interface Props {
@@ -12,7 +12,7 @@ interface Props {
1212
1313export const getServerSideProps = async ( ) => {
1414 const parkingData = await Promise . all (
15- parkingNames . map ( async ( name ) => {
15+ parkings . map ( async ( { name, nameJP } ) => {
1616 const url = `http://view:3000/api/parkings/${ name } `
1717 const res = await fetch ( url )
1818
@@ -21,7 +21,7 @@ export const getServerSideProps = async () => {
2121 }
2222 const data = ( await res . json ( ) ) as Parking [ ]
2323 return {
24- name,
24+ name : nameJP ,
2525 data,
2626 }
2727 } ) ,
@@ -39,34 +39,52 @@ export const Home: NextPage<Props> = ({ parkingData }: Props) => (
3939 < div className = 'my-10 flex flex-col items-center' >
4040 < Card
4141 sx = { {
42- width : 'fit-content' ,
43- p : '2rem' ,
44- mxnWidth : '90%' ,
42+ width : '90%' ,
4543 display : 'flex' ,
4644 flexDirection : 'column' ,
4745 gap : '2rem' ,
4846 alignItems : 'center' ,
4947 boxShadow : '0 0 10px 0 rgba(0, 0, 0, 0.2)' ,
5048 } }
51- className = 'bg-white text-textBlack'
49+ className = 'bg-white p-4 text-textBlack md:p-8 '
5250 >
53- < div className = 'w-4/5 ' >
54- < Image src = '/images/map.png' alt = 'map' width = { 500 } height = { 500 } className = 'w-full' />
51+ < div className = 'flex w-full justify-center ' >
52+ < Image src = '/images/map.png' alt = 'map' width = { 500 } height = { 500 } className = 'w-full md:w-1/2 ' />
5553 </ div >
5654 < Typography variant = 'h5' fontWeight = 'bold' >
5755 現在の駐車状況
5856 </ Typography >
5957 < div className = 'gird-cols-1 grid gap-5 md:grid-cols-3' >
60- { parkingData . map ( ( { name, data } , index ) => (
61- < ParkingCard
62- key = { name }
63- name = { name }
64- currentCapacity = { data [ data . length - 1 ] . count }
65- maxCapacity = { parkingLimit [ index ] }
66- data = { data }
67- dataLimit = { 20 }
68- />
69- ) ) }
58+ { parkingData . map ( ( { name, data } , index ) => {
59+ if ( ! data . length )
60+ return (
61+ < Card
62+ sx = { {
63+ p : '1rem' ,
64+ backgroundColor : 'white' ,
65+ display : 'flex' ,
66+ flexDirection : 'column' ,
67+ gap : '1rem' ,
68+ minWidth : '300px' ,
69+ } }
70+ >
71+ < div className = 'flex flex-col gap-4' >
72+ < p className = 'text-xl' > { name } </ p >
73+ < p className = 'text-sm' > 読み込みに失敗しました</ p >
74+ </ div >
75+ </ Card >
76+ )
77+ return (
78+ < ParkingCard
79+ key = { name }
80+ name = { name }
81+ currentCapacity = { data [ data . length - 1 ] . count }
82+ maxCapacity = { parkings [ index ] . limit }
83+ data = { data }
84+ dataLimit = { 20 }
85+ />
86+ )
87+ } ) }
7088 </ div >
7189 </ Card >
7290 </ div >
0 commit comments