Skip to content

Commit 41a08dc

Browse files
authored
Merge pull request #25 from Annguyn/frontend
enhance(CompactLocationCard): improve layout and remove redundant sec…
2 parents 8aa1997 + 06a0c6e commit 41a08dc

File tree

1 file changed

+44
-48
lines changed

1 file changed

+44
-48
lines changed

website/components/home/CompactLocationCard.tsx

Lines changed: 44 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,37 @@ export default function CompactLocationCard({
121121
hour12: false
122122
});
123123

124+
// Format city and country to short codes
125+
const formatCityCountry = (city: string, country: string): string => {
126+
const cityMap: { [key: string]: string } = {
127+
'Ho Chi Minh City': 'HCM',
128+
'Hanoi': 'HN',
129+
'Da Nang': 'DN',
130+
};
131+
const countryMap: { [key: string]: string } = {
132+
'Vietnam': 'VN',
133+
'Viet Nam': 'VN',
134+
};
135+
136+
const cityCode = cityMap[city] || city.substring(0, 3).toUpperCase();
137+
const countryCode = countryMap[country] || country.substring(0, 2).toUpperCase();
138+
139+
return `${cityCode}, ${countryCode}`;
140+
};
141+
142+
// Format datetime from lastUpdated and since
143+
const formatDateTime = (lastUpdated: string, since: string): string => {
144+
// Extract time from lastUpdated (e.g., "22:15" or "Updated 22:15")
145+
const timeMatch = lastUpdated.match(/(\d{1,2}):(\d{2})/);
146+
const time = timeMatch ? `${timeMatch[1]}:${timeMatch[2]}` : lastUpdated.replace(/Updated\s*/i, '').trim();
147+
148+
// Extract date from since (e.g., "12/6/2025" or "Since 12/6/2025")
149+
const dateMatch = since.match(/(\d{1,2}\/\d{1,2}\/\d{4})/);
150+
const date = dateMatch ? dateMatch[1] : since.replace(/Since\s*/i, '').trim();
151+
152+
return `${time} ${date}`;
153+
};
154+
124155
return (
125156
<motion.div
126157
initial={{ opacity: 0, y: 20 }}
@@ -130,17 +161,11 @@ export default function CompactLocationCard({
130161
>
131162
{/* Header - UrbanReflex Teal banner */}
132163
<div className="bg-gradient-to-r from-[#008EA0] to-[#64BABE] px-4 py-3">
133-
<h2 className="text-lg font-semibold text-white">{name}</h2>
134-
</div>
135-
136-
{/* Location below header */}
137-
<div className="px-4 py-2 bg-white border-b border-[#64BABE]/30">
138-
<p className="text-sm text-gray-900 font-medium">{city}, {country}</p>
139-
{type && (
140-
<p className="text-xs text-gray-600 mt-0.5">
141-
<span className="font-medium">Type:</span> {type}
142-
</p>
143-
)}
164+
<div className="text-white">
165+
<p className="text-xl font-semibold mb-1">{formatCityCountry(city, country)}</p>
166+
<h2 className="text-lg font-semibold">{name}</h2>
167+
<p className="text-sm font-medium mt-1">{formatDateTime(lastUpdated, since)}</p>
168+
</div>
144169
</div>
145170

146171
{/* Body - White background with sections */}
@@ -157,48 +182,19 @@ export default function CompactLocationCard({
157182
</div>
158183
)}
159184

160-
{/* Provider Section */}
161-
<div className="px-4 py-3 border-b border-[#64BABE]/30">
162-
<p className="text-sm text-gray-800">
163-
<span className="font-bold text-[#008EA0]">Provider:</span> <span className="text-gray-700">{provider}</span>
164-
</p>
165-
</div>
166-
167-
{/* Reporting Section */}
168-
<div className="px-4 py-3 border-b border-[#64BABE]/30 bg-gradient-to-br from-white to-[#64BABE]/5">
169-
<p className="text-sm text-gray-800">
170-
<span className="font-bold text-[#008EA0]">Reporting:</span> <span className="text-gray-700">{lastUpdated}</span>
171-
</p>
172-
<p className="text-xs text-[#008EA0] mt-0.5 font-medium">Since {since}</p>
173-
</div>
174-
175185
{/* Latest Readings Section */}
176186
<div className="px-4 py-3 border-b border-[#64BABE]/30">
177-
<p className="text-sm font-bold text-[#008EA0] mb-3 flex items-center gap-2">
178-
<span>Latest readings {localTime} (local time)</span>
187+
<p className="text-xs font-semibold text-[#008EA0] mb-2.5">
188+
Latest readings {localTime} (local time)
179189
</p>
180-
<div className="space-y-2.5">
190+
<div className="grid grid-cols-2 gap-2">
181191
{latestReadings.map((measurement, index) => (
182-
<div key={index} className="flex items-center justify-between p-2 rounded-lg bg-gradient-to-r from-white to-[#64BABE]/5 border border-[#64BABE]/20 hover:border-[#008EA0]/40 transition-colors">
183-
<span className="text-sm font-semibold text-gray-800">
192+
<div key={index} className="p-2 rounded-lg bg-gradient-to-br from-[#64BABE]/5 to-white border border-[#64BABE]/20 hover:border-[#008EA0]/40 transition-all hover:shadow-sm">
193+
<div className="text-[10px] font-medium text-gray-600 mb-0.5 uppercase tracking-wide">
184194
{getParameterDisplayName(measurement.parameter)}
185-
</span>
186-
<div className="flex items-center gap-3">
187-
<span className="text-sm font-bold text-[#008EA0]">
188-
{measurement.value} {measurement.unit}
189-
</span>
190-
{/* Small trend indicator - UrbanReflex style */}
191-
<div className="w-8 h-4 flex items-end justify-center">
192-
<svg width="24" height="12" viewBox="0 0 24 12" className="text-[#64BABE]">
193-
<path
194-
d="M0,10 Q6,6 12,7 T24,5"
195-
stroke="currentColor"
196-
strokeWidth="1.5"
197-
fill="none"
198-
strokeLinecap="round"
199-
/>
200-
</svg>
201-
</div>
195+
</div>
196+
<div className="text-sm font-bold text-[#008EA0]">
197+
{measurement.value} <span className="text-xs font-semibold text-gray-600">{measurement.unit}</span>
202198
</div>
203199
</div>
204200
))}

0 commit comments

Comments
 (0)