Refactor CityProfile and PlayerProfile components for improved data fetching and error handling; add NPC management modals for banner, gallery, and logo with enhanced user experience and error feedback.

This commit is contained in:
Lars Behrends
2025-12-30 13:56:00 +01:00
parent 5eb2eca110
commit c6ad8a92ec
14 changed files with 2539 additions and 102 deletions

View File

@@ -24,16 +24,32 @@ const CityProfile: React.FC = () => {
return;
}
// Load city data
const cityData = dbService.getOrg(id);
if (cityData) {
setCity(cityData);
} else {
navigate('/cities');
return;
}
// Fetch fresh data from database on mount/reload
const loadCityData = async () => {
try {
await dbService.fetchAll();
const cityData = dbService.getOrg(id);
if (cityData) {
setCity(cityData);
} else {
navigate('/cities');
return;
}
} catch (error) {
console.warn('Failed to fetch fresh city data:', error);
// Fallback to cached data
const cityData = dbService.getOrg(id);
if (cityData) {
setCity(cityData);
} else {
navigate('/cities');
return;
}
}
setLoading(false);
};
setLoading(false);
loadCityData();
}, [id, navigate]);
useEffect(() => {
@@ -42,7 +58,7 @@ const CityProfile: React.FC = () => {
const loadCityData = () => {
// Load residents (players in this city)
const allPlayers = dbService.getPlayers();
const cityResidents = allPlayers.filter(p => p.stats.organizationId === city.id);
const cityResidents = allPlayers.filter(p => p.organizationId === city.id);
setResidents(cityResidents);
// Load ventures (projects in this city)