-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
72 lines (63 loc) · 2.17 KB
/
App.js
File metadata and controls
72 lines (63 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import React, { useEffect, useState } from 'react';
import Navigation from './src/Components/Navigation';
import * as RNLocalize from 'react-native-localize';
import { setLanguage } from './src/Redux/languageSlice';
import { setIp, setLocation } from './src/Redux/locationSlice';
import { Provider, useDispatch } from 'react-redux';
import { store } from './src/Redux/store';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { setTheme, loadTheme, saveTheme } from './src/Redux/themeSlice'
import Constants from 'expo-constants';
const AppContent = () => {
const dispatch = useDispatch();
const [ip, setIpState] = useState(null);
const [location, setLocationState] = useState(null);
const ip_geo_api = Constants.expoConfig.extra.ip_geo_api
useEffect(() => {
// IP adresini al
fetch('https://api.ipify.org?format=json')
.then(response => response.json())
.then(data => {
const ipAddress = data.ip;
setIpState(ipAddress);
dispatch(setIp(ipAddress));
// IP adresinden konum bilgisi al
return fetch(`https://api.ipgeolocation.io/ipgeo?apiKey=${ip_geo_api}ip=${ipAddress}`);
})
.then(response => response.json())
.then(data => {
setLocationState(data);
dispatch(setLocation(data));
})
.catch(error => console.error('Error fetching IP or location:', error));
}, [dispatch]);
useEffect(() => {
const locales = RNLocalize.getLocales();
const systemLanguage = locales[0].languageTag;
dispatch(setLanguage(systemLanguage));
}, [dispatch]);
useEffect(() => {
const fetchTheme = async () => {
try {
const storedTheme = await AsyncStorage.getItem('selectedTheme');
if (storedTheme) {
store.dispatch(setTheme(storedTheme)); // Redux store'a temayı kaydet
}
} catch (error) {
console.error('Tema AsyncStorage\'dan alınırken bir hata oluştu:', error);
}
};
fetchTheme(); // Tema bilgilerini almak için fonksiyonu çağır
}, []);
return (
<Navigation />
);
};
function App() {
return (
<Provider store={store}>
<AppContent />
</Provider>
);
}
export default App;