-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e779e2f
commit 00b5093
Showing
8 changed files
with
35,554 additions
and
7,884 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* File: PrayerTimes.js | ||
* Project: watcher | ||
* File Created: Saturday, 22nd April 2023 7:41:41 pm | ||
* Author: Umar Aamer ([email protected]) | ||
* ----- | ||
* Last Modified: Saturday, 22nd April 2023 7:41:42 pm | ||
* ----- | ||
* Copyright 2020 - 2023 While Geek, https://umar.tech | ||
*/ | ||
import React, { useState, useEffect } from "react"; | ||
import useLocation from "../hooks/useLocation"; | ||
|
||
export const PrayerTimes = () => { | ||
const [prayerTimes, setPrayerTimes] = useState({}); | ||
const [isLoading, setIsLoading] = useState(true); | ||
|
||
const { latitude, longitude } = useLocation(); | ||
|
||
const today = new Date(); | ||
|
||
const year = today.getFullYear(); | ||
|
||
const month = today.getMonth() + 1; | ||
|
||
const date = today.getDate(); | ||
|
||
useEffect(() => { | ||
const fetchPrayerTimes = async () => { | ||
try { | ||
const response = await fetch( | ||
`https://api.aladhan.com/v1/calendar/${year}/${month}?latitude=${latitude}&longitude=${longitude}&method=1` | ||
); | ||
|
||
const data = await response.json(); | ||
|
||
const todayPrayerData = data.data[date - 1].timings; | ||
|
||
|
||
const formattedData = []; | ||
|
||
for (let key in todayPrayerData) { | ||
formattedData.push({ | ||
key, | ||
value: todayPrayerData[key], | ||
}); | ||
} | ||
|
||
setPrayerTimes(formattedData); | ||
setIsLoading(false); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
}; | ||
|
||
fetchPrayerTimes(); | ||
}, []); | ||
|
||
if (isLoading) { | ||
return <div>Loading prayer times...</div>; | ||
} | ||
|
||
return ( | ||
<div> | ||
<h2> | ||
{prayerTimes[0].key} - {prayerTimes[0].value}</h2> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* File: config.js | ||
* Project: watcher | ||
* File Created: Saturday, 22nd April 2023 9:28:19 pm | ||
* Author: Umar Aamer ([email protected]) | ||
* ----- | ||
* Last Modified: Saturday, 22nd April 2023 9:28:20 pm | ||
* ----- | ||
* Copyright <<year>> - 2023 WhileGeek, https://umar.tech | ||
*/ | ||
export const config = { | ||
coordinates: { | ||
lat: "33.6461432", | ||
lng: "73.0523224", | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* File: useLocation.js | ||
* Project: watcher | ||
* File Created: Saturday, 22nd April 2023 9:29:15 pm | ||
* Author: Umar Aamer ([email protected]) | ||
* ----- | ||
* Last Modified: Saturday, 22nd April 2023 9:29:15 pm | ||
* ----- | ||
* Copyright <<year>> - 2023 WhileGeek, https://umar.tech | ||
*/ | ||
import { useState, useEffect } from 'react'; | ||
import { config } from '../config'; | ||
|
||
const useLocation = () => { | ||
const [location, setLocation] = useState({ | ||
latitude: config.coordinates.lat, | ||
longitude: config.coordinates.lng, | ||
}); | ||
|
||
useEffect(() => { | ||
if (navigator.geolocation) { | ||
navigator.geolocation.getCurrentPosition( | ||
position => { | ||
setLocation({ | ||
latitude: position.coords.latitude, | ||
longitude: position.coords.longitude | ||
}); | ||
}, | ||
error => { | ||
console.error(error); | ||
} | ||
); | ||
} else { | ||
console.error('Geolocation is not supported by this browser.'); | ||
} | ||
}, []); | ||
|
||
return location; | ||
}; | ||
|
||
export default useLocation; |
Oops, something went wrong.