feat: implement Players component with data fetching and loading state; remove mock data and enhance error handling in database service

This commit is contained in:
Lars Behrends
2025-12-30 15:58:07 +01:00
parent c6ad8a92ec
commit ea2b803534
12 changed files with 184 additions and 341 deletions

View File

@@ -53,6 +53,17 @@ const Cities: React.FC<CitiesProps> = ({ onSelectCity }) => {
const [loading, setLoading] = useState(true);
useEffect(() => {
const loadData = async () => {
setLoading(true);
try {
await dbService.fetchAll();
} catch (error) {
console.warn('Failed to fetch fresh data:', error);
// Continue with cached data
}
setLoading(false);
};
const loadCities = () => {
// Get all organizations from database
const allOrgs = dbService.getOrgs();
@@ -63,7 +74,7 @@ const Cities: React.FC<CitiesProps> = ({ onSelectCity }) => {
// Count citizens (players with this organizationId)
const allPlayers = dbService.getPlayers();
const citizenCount = allPlayers.filter(player =>
player.stats.organizationId === city.id
player.organizationId === city.id
).length;
// Count businesses/projects in this city
@@ -87,11 +98,10 @@ const Cities: React.FC<CitiesProps> = ({ onSelectCity }) => {
setCities(cityOrgs);
setCitiesWithStats(citiesStats);
setLoading(false);
};
// Initial load
loadCities();
// Load fresh data on mount
loadData();
// Subscribe to updates
const unsub = dbService.subscribe(loadCities);