updates
This commit is contained in:
@@ -24,7 +24,8 @@ const NOCODB_TOKEN = process.env.REACT_APP_NOCODB_TOKEN || '';
|
||||
const NOCODB_TABLES = {
|
||||
districts: 'm8cup7lesbet0sa',
|
||||
museums: 'm1c7od7mdirffvu',
|
||||
dailyStats: 'mc7qhbdh3mjjwl8'
|
||||
dailyStats: 'mc7qhbdh3mjjwl8',
|
||||
pilgrimStats: 'mmqgj0a0l5qxeqf'
|
||||
};
|
||||
|
||||
// Cache keys
|
||||
@@ -32,11 +33,43 @@ const CACHE_KEY = 'hihala_data_cache';
|
||||
const CACHE_TIMESTAMP_KEY = 'hihala_data_cache_timestamp';
|
||||
const CACHE_MAX_AGE_MS = 7 * 24 * 60 * 60 * 1000; // 7 days
|
||||
|
||||
export const umrahData: UmrahData = {
|
||||
2024: { 1: 11574494, 2: 10521465, 3: 3364627, 4: 7435625 },
|
||||
2025: { 1: 15222497, 2: 5443393, 3: null, 4: null }
|
||||
// Default umrah data (overridden by NocoDB PilgrimStats when available)
|
||||
export let umrahData: UmrahData = {
|
||||
2024: { 1: 15222497, 2: 10521465, 3: 6270868, 4: 7435625 },
|
||||
2025: { 1: 15222497, 2: 5443393, 3: 26643148, 4: 31591871 }
|
||||
};
|
||||
|
||||
// Fetch pilgrim stats from NocoDB and update umrahData
|
||||
export async function fetchPilgrimStats(): Promise<UmrahData> {
|
||||
try {
|
||||
const url = `${NOCODB_URL}/api/v2/tables/${NOCODB_TABLES.pilgrimStats}/records?limit=50`;
|
||||
const res = await fetch(url, { headers: { 'xc-token': NOCODB_TOKEN } });
|
||||
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
||||
const json = await res.json();
|
||||
const records = json.list || [];
|
||||
|
||||
const data: UmrahData = { 2024: {}, 2025: {} };
|
||||
for (const r of records) {
|
||||
const year = r.Year as number;
|
||||
const qStr = r.Quarter as string; // "Q1", "Q2", etc.
|
||||
const qNum = parseInt(qStr.replace('Q', ''));
|
||||
const total = r.TotalPilgrims as number;
|
||||
if (year && qNum && total) {
|
||||
if (!data[year]) data[year] = {};
|
||||
data[year][qNum] = total;
|
||||
}
|
||||
}
|
||||
|
||||
// Update the global umrahData
|
||||
umrahData = data;
|
||||
console.log('PilgrimStats loaded from NocoDB:', data);
|
||||
return data;
|
||||
} catch (err) {
|
||||
console.warn('Failed to fetch PilgrimStats, using defaults:', (err as Error).message);
|
||||
return umrahData;
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// Offline Cache Functions
|
||||
// ============================================
|
||||
|
||||
Reference in New Issue
Block a user