kaza namazı hesaplama düzeltildi.

This commit is contained in:
2026-07-31 04:24:10 +02:00
parent ff6191a473
commit d533c6a196
3 changed files with 156 additions and 86 deletions
+25 -18
View File
@@ -1,4 +1,4 @@
import { gregorianToHijri, calculateMissedPrayers } from "../utils/hijri.js";
import { gregorianToHijri } from "../utils/hijri.js";
import {
fetchWeather,
getWeatherIcon,
@@ -21,7 +21,7 @@ export function renderDesktop(selectedCity = "Edremit", pb) {
<div class="fixed top-0 right-0 h-screen w-80 md:w-96 bg-slate-900/85 border-l border-white/10 p-6 shadow-2xl z-20 flex flex-col justify-between overflow-y-auto">
<div class="space-y-6">
<!-- CANLI DİJİTAL SAAT WİDGET'I -->
<!-- CANLI DİJİTAL SAAT WIDGET'I -->
<div class="bg-slate-950/60 border border-white/10 p-5 rounded-3xl text-center space-y-1 shadow-inner">
<p class="text-xs font-semibold text-indigo-400 tracking-widest uppercase">CANLI SAAT</p>
<div id="liveClock" class="text-4xl font-black text-white tracking-wider font-mono">
@@ -30,11 +30,11 @@ export function renderDesktop(selectedCity = "Edremit", pb) {
<p class="text-[11px] text-slate-400 font-medium">${dateStr}</p>
</div>
<!-- GENEL KAZA İLERLEME WİDGET'I -->
<!-- GENEL KAZA İLERLEME WIDGET'I -->
<div id="desktopKazaProgressWidget" class="bg-slate-950/60 border border-white/10 p-4 rounded-2xl space-y-2">
<div class="flex items-center justify-between text-xs">
<span class="font-bold text-indigo-300 flex items-center gap-1.5">
<span>🎯</span> KAZA İLERLEMESİ
<span>📊</span> KAZA İLERLEMESİ
</span>
<span id="desktopKazaPct" class="font-extrabold text-emerald-400">%0</span>
</div>
@@ -49,7 +49,7 @@ export function renderDesktop(selectedCity = "Edremit", pb) {
<!-- HİCRİ TAKVİM -->
<div class="space-y-1">
<div class="flex items-center gap-2 text-xs font-semibold text-emerald-400">
<span>📅</span> HİCRİ TAKVİM
<span>🌙</span> HİCRİ TAKVİM
</div>
<p class="text-white font-bold text-base">${hijri.day} ${hijri.monthName} ${hijri.year}</p>
<p class="text-xs text-slate-400">${hijri.weekday}</p>
@@ -81,7 +81,6 @@ export function renderDesktop(selectedCity = "Edremit", pb) {
</div>
<span class="text-slate-400 group-hover:translate-x-1 transition-transform text-xs">➔</span>
</div>
</div>
`;
@@ -106,33 +105,36 @@ export function renderDesktop(selectedCity = "Edremit", pb) {
function startClock(container) {
const clockEl = container.querySelector("#liveClock");
if (!clockEl) return;
const update = () => {
const now = new Date();
clockEl.textContent = now.toLocaleTimeString("tr-TR");
};
update();
setInterval(update, 1000);
}
// PocketBase üzerindeki sabit hedeflere (target_*) göre kaza durumunu okuma
async function loadDesktopKazaProgress(container, pb) {
const user = pb.authStore.model;
if (!user) return;
const birthDate = user.birthDate || user.birthdate;
if (!birthDate) return;
const calc = calculateMissedPrayers(birthDate, user.gender || "male", 12);
let totalMissed =
calc.fajr + calc.dhuhr + calc.asr + calc.maghrib + calc.isha + calc.vitr ||
0;
let totalTarget = 0;
let totalCompleted = 0;
try {
const record = await pb
.collection("kaza_logs")
.getFirstListItem(`user = "${user.id}"`);
if (record) {
totalTarget =
(record.target_fajr || 0) +
(record.target_dhuhr || 0) +
(record.target_asr || 0) +
(record.target_maghrib || 0) +
(record.target_isha || 0) +
(record.target_vitr || 0);
totalCompleted =
(record.fajr || 0) +
(record.dhuhr || 0) +
@@ -143,10 +145,11 @@ async function loadDesktopKazaProgress(container, pb) {
}
} catch {}
const remaining = Math.max(0, totalTarget - totalCompleted);
const pct =
totalMissed > 0
? Math.min(100, Math.round((totalCompleted / totalMissed) * 100))
: 100;
totalTarget > 0
? Math.min(100, Math.round((totalCompleted / totalTarget) * 100))
: 0;
const bar = container.querySelector("#desktopKazaBar");
const pctText = container.querySelector("#desktopKazaPct");
@@ -155,20 +158,23 @@ async function loadDesktopKazaProgress(container, pb) {
if (bar) bar.style.width = `${pct}%`;
if (pctText) pctText.textContent = `%${pct}`;
if (subText)
subText.textContent = `${totalCompleted} kılınan / ${Math.max(0, totalMissed - totalCompleted)} kalan`;
subText.textContent = `${totalCompleted} kılınan / ${remaining} kalan`;
}
async function loadWeather(container, selectedCity) {
const widget = container.querySelector("#weatherWidget");
if (!widget) return;
const data = await fetchWeather(selectedCity);
if (!data) {
widget.innerHTML = `<span class="text-xs text-rose-400">Hava durumu alınamadı</span>`;
return;
}
const icon = getWeatherIcon(data.weathercode);
const desc = getWeatherDesc(data.weathercode);
const temp = Math.round(data.temperature);
widget.innerHTML = `
<div class="flex items-center justify-between">
<div>
@@ -188,6 +194,7 @@ async function loadWeather(container, selectedCity) {
async function loadImsakiye(container, selectedCity) {
const widget = container.querySelector("#imsakiyeWidget");
if (!widget) return;
const times = await fetchPrayerTimes(selectedCity);
if (!times) {
widget.innerHTML = `<span class="text-xs text-rose-400">Vakitler alınamadı</span>`;