Update prayer time calculation logic and integrate new 'adhan' package for improved accuracy. Remove 'hijri-date' dependency and enhance localization support for city names in multiple languages. Adjust package versions in package.json and package-lock.json.
This commit is contained in:
@@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react';
|
||||
import { View, Text, StyleSheet, ImageBackground, Pressable } from 'react-native';
|
||||
import Colors from '@/constants/Colors';
|
||||
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
|
||||
import prayerTimeCalculator, { cities } from '@/utils/prayerTimeCalculator';
|
||||
import { getPrayerTimes, cities } from '@/utils/prayerTimeCalculator';
|
||||
import i18n from '@/i18n';
|
||||
|
||||
type Prayer = {
|
||||
@@ -24,14 +24,12 @@ export default function PrayerTimeCard() {
|
||||
const [prayerTimes, setPrayerTimes] = useState<Prayer[]>([]);
|
||||
const [nextPrayer, setNextPrayer] = useState<{ name: string; time: string } | null>(null);
|
||||
const [remainingTime, setRemainingTime] = useState('');
|
||||
const [selectedCity, setSelectedCity] = useState<'Makkah' | 'Medina' | 'Jeddah'>('Makkah');
|
||||
const [selectedCity, setSelectedCity] = useState<keyof typeof cities>('Makkah');
|
||||
|
||||
useEffect(() => {
|
||||
const city = cities[selectedCity];
|
||||
const times = prayerTimeCalculator.getTimes(new Date(), city.coords, city.timezone, 0, '24h');
|
||||
|
||||
const times = getPrayerTimes(selectedCity);
|
||||
const prayers: Prayer[] = Object.keys(prayerIconMapping).map(key => ({
|
||||
name: key.charAt(0).toUpperCase() + key.slice(1),
|
||||
name: i18n.t(key),
|
||||
time: times[key] || '-----',
|
||||
icon: prayerIconMapping[key],
|
||||
}));
|
||||
@@ -56,7 +54,6 @@ export default function PrayerTimeCard() {
|
||||
}
|
||||
|
||||
setNextPrayer(nextPrayerInfo);
|
||||
|
||||
}, [selectedCity]);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -90,9 +87,9 @@ export default function PrayerTimeCard() {
|
||||
<View style={styles.overlay}>
|
||||
<View style={styles.header}>
|
||||
<View style={styles.citySelector}>
|
||||
{Object.keys(cities).map(city => (
|
||||
<Pressable key={city} onPress={() => setSelectedCity(city as any)} style={[styles.cityButton, selectedCity === city && styles.activeCity]}>
|
||||
<Text style={styles.cityButtonText}>{city}</Text>
|
||||
{(Object.keys(cities) as Array<keyof typeof cities>).map(city => (
|
||||
<Pressable key={city} onPress={() => setSelectedCity(city)} style={[styles.cityButton, selectedCity === city && styles.activeCity]}>
|
||||
<Text style={styles.cityButtonText}>{i18n.t(city)}</Text>
|
||||
</Pressable>
|
||||
))}
|
||||
</View>
|
||||
|
||||
Reference in New Issue
Block a user