genel olarak yapılan düzeltmeler
This commit is contained in:
+81
-48
@@ -1,4 +1,4 @@
|
||||
import { calculateMissedPrayers, getHijriBirthDate } from "../utils/hijri.js";
|
||||
import { calculateMissedPrayers, getHijribirthdate } from "../utils/hijri.js";
|
||||
|
||||
const PRAYERS = [
|
||||
{ id: "fajr", name: "SABAH", arabic: "Fecr" },
|
||||
@@ -12,7 +12,7 @@ const PRAYERS = [
|
||||
export function renderKaza(pb) {
|
||||
// Sıfır localStorage! Her şey PocketBase authStore modelinden okunuyor.
|
||||
const user = pb.authStore.model;
|
||||
const birthDate = user?.birthDate || user?.birthdate;
|
||||
const birthdate = user?.birthdate || user?.birthdate;
|
||||
const gender = user?.gender || "male";
|
||||
|
||||
const html = `
|
||||
@@ -30,7 +30,7 @@ export function renderKaza(pb) {
|
||||
</div>
|
||||
|
||||
${
|
||||
!birthDate
|
||||
!birthdate
|
||||
? `
|
||||
<div class="bg-slate-900/50 border border-white/10 p-6 rounded-2xl my-auto text-center max-w-md mx-auto w-full">
|
||||
<h3 class="text-base font-bold text-white mb-2">Doğum Tarihi Gerekli</h3>
|
||||
@@ -38,7 +38,7 @@ export function renderKaza(pb) {
|
||||
<form id="profileForm" class="space-y-4">
|
||||
<div class="text-left">
|
||||
<label class="block text-xs text-slate-300 mb-1">Doğum Tarihi</label>
|
||||
<input type="date" id="birthDateInput" required class="w-full bg-slate-950 border border-slate-800 rounded-xl px-4 py-2.5 text-white text-sm focus:border-indigo-500 focus:outline-none" />
|
||||
<input type="date" id="birthdateInput" required class="w-full bg-slate-950 border border-slate-800 rounded-xl px-4 py-2.5 text-white text-sm focus:border-indigo-500 focus:outline-none" />
|
||||
</div>
|
||||
<div class="text-left">
|
||||
<label class="block text-xs text-slate-300 mb-1">Cinsiyet</label>
|
||||
@@ -63,7 +63,7 @@ export function renderKaza(pb) {
|
||||
<span id="overallPercentage" class="text-sm font-extrabold text-emerald-400">%0</span>
|
||||
</div>
|
||||
<div class="w-full h-3.5 bg-slate-900 rounded-full overflow-hidden border border-white/5 p-0.5">
|
||||
<div id="overallProgressBar" class="h-full bg-gradient-to-r from-indigo-500 via-purple-500 to-emerald-400 rounded-full transition-all duration-700 ease-out w-[0%]"></div>
|
||||
<div id="overallProgressBar" class="h-full bg-linear-to-r from-indigo-500 via-purple-500 to-emerald-400 rounded-full transition-all duration-700 ease-out w-[0%]"></div>
|
||||
</div>
|
||||
<div class="flex justify-between items-center text-[10px] text-slate-400 mt-2">
|
||||
<span>Kılınan: <b id="totalCompletedText" class="text-white">0</b> vakit</span>
|
||||
@@ -82,7 +82,7 @@ export function renderKaza(pb) {
|
||||
<div id="progress-${p.id}" class="bg-emerald-400 h-full w-[0%] transition-all duration-500"></div>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
`,
|
||||
).join("")}
|
||||
</div>
|
||||
|
||||
@@ -120,46 +120,59 @@ export function renderKaza(pb) {
|
||||
html,
|
||||
initEvents: (container) => {
|
||||
container.querySelector("#closeBtn")?.addEventListener("click", () => {
|
||||
window.dispatchEvent(new CustomEvent("navigate", { detail: "desktop" }));
|
||||
window.dispatchEvent(
|
||||
new CustomEvent("navigate", { detail: "desktop" }),
|
||||
);
|
||||
});
|
||||
|
||||
if (!birthDate) {
|
||||
container.querySelector("#profileForm")?.addEventListener("submit", async (e) => {
|
||||
e.preventDefault();
|
||||
const bInput = container.querySelector("#birthDateInput").value;
|
||||
const gInput = container.querySelector("#genderInput").value;
|
||||
if (!birthdate) {
|
||||
container
|
||||
.querySelector("#profileForm")
|
||||
?.addEventListener("submit", async (e) => {
|
||||
e.preventDefault();
|
||||
const bInput = container.querySelector("#birthdateInput").value;
|
||||
const gInput = container.querySelector("#genderInput").value;
|
||||
|
||||
try {
|
||||
await pb.collection("users").update(pb.authStore.model.id, {
|
||||
birthDate: bInput,
|
||||
gender: gInput,
|
||||
});
|
||||
pb.authStore.model.birthDate = bInput;
|
||||
pb.authStore.model.gender = gInput;
|
||||
window.dispatchEvent(new CustomEvent("navigate", { detail: "kaza" }));
|
||||
} catch (err) {
|
||||
alert("Profil kaydedilemedi. PocketBase bağlantısını kontrol edin.");
|
||||
}
|
||||
});
|
||||
try {
|
||||
await pb.collection("users").update(pb.authStore.model.id, {
|
||||
birthdate: bInput,
|
||||
gender: gInput,
|
||||
});
|
||||
pb.authStore.model.birthdate = bInput;
|
||||
pb.authStore.model.gender = gInput;
|
||||
window.dispatchEvent(
|
||||
new CustomEvent("navigate", { detail: "kaza" }),
|
||||
);
|
||||
} catch (err) {
|
||||
alert(
|
||||
"Profil kaydedilemedi. PocketBase bağlantısını kontrol edin.",
|
||||
);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
refreshKazaStats(container, pb, birthDate, gender);
|
||||
refreshKazaStats(container, pb, birthdate, gender);
|
||||
|
||||
container.querySelector("#addKazaBtn")?.addEventListener("click", async () => {
|
||||
await handleKazaLog(container, pb, birthDate, gender, 1);
|
||||
});
|
||||
container
|
||||
.querySelector("#addKazaBtn")
|
||||
?.addEventListener("click", async () => {
|
||||
await handleKazaLog(container, pb, birthdate, gender, 1);
|
||||
});
|
||||
|
||||
container.querySelector("#removeKazaBtn")?.addEventListener("click", async () => {
|
||||
await handleKazaLog(container, pb, birthDate, gender, -1);
|
||||
});
|
||||
container
|
||||
.querySelector("#removeKazaBtn")
|
||||
?.addEventListener("click", async () => {
|
||||
await handleKazaLog(container, pb, birthdate, gender, -1);
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
async function handleKazaLog(container, pb, birthDate, gender, multiplier) {
|
||||
async function handleKazaLog(container, pb, birthdate, gender, multiplier) {
|
||||
const prayerId = container.querySelector("#kazaPrayerType").value;
|
||||
const countInput = container.querySelector("#kazaCount");
|
||||
const count = Math.max(1, parseInt(countInput?.value || "1", 10)) * multiplier;
|
||||
const count =
|
||||
Math.max(1, parseInt(countInput?.value || "1", 10)) * multiplier;
|
||||
const msg = container.querySelector("#kazaMsg");
|
||||
|
||||
try {
|
||||
@@ -170,16 +183,26 @@ async function handleKazaLog(container, pb, birthDate, gender, multiplier) {
|
||||
date: new Date().toISOString().split("T")[0],
|
||||
});
|
||||
|
||||
showKazaMsg(msg, count > 0 ? `🎉 ${count} vakit kaza kılındı olarak işlendi!` : `${Math.abs(count)} vakit düşüldü.`, true);
|
||||
showKazaMsg(
|
||||
msg,
|
||||
count > 0
|
||||
? `🎉 ${count} vakit kaza kılındı olarak işlendi!`
|
||||
: `${Math.abs(count)} vakit düşüldü.`,
|
||||
true,
|
||||
);
|
||||
if (countInput) countInput.value = "1";
|
||||
await refreshKazaStats(container, pb, birthDate, gender);
|
||||
await refreshKazaStats(container, pb, birthdate, gender);
|
||||
} catch (err) {
|
||||
showKazaMsg(msg, "İşlem kaydedilemedi! PocketBase izinlerini veya bağlantısını kontrol edin.", false);
|
||||
showKazaMsg(
|
||||
msg,
|
||||
"İşlem kaydedilemedi! PocketBase izinlerini veya bağlantısını kontrol edin.",
|
||||
false,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function refreshKazaStats(container, pb, birthDate, gender) {
|
||||
const calc = calculateMissedPrayers(birthDate, gender);
|
||||
async function refreshKazaStats(container, pb, birthdate, gender) {
|
||||
const calc = calculateMissedPrayers(birthdate, gender);
|
||||
let logsByPrayer = {};
|
||||
let logs = [];
|
||||
|
||||
@@ -191,7 +214,8 @@ async function refreshKazaStats(container, pb, birthDate, gender) {
|
||||
|
||||
logs = records;
|
||||
records.forEach((l) => {
|
||||
logsByPrayer[l.prayerId] = (logsByPrayer[l.prayerId] || 0) + (l.count || 0);
|
||||
logsByPrayer[l.prayerId] =
|
||||
(logsByPrayer[l.prayerId] || 0) + (l.count || 0);
|
||||
});
|
||||
} catch (err) {
|
||||
console.error("Loglar çekilemedi:", err);
|
||||
@@ -213,15 +237,22 @@ async function refreshKazaStats(container, pb, birthDate, gender) {
|
||||
|
||||
if (remainEl) remainEl.textContent = remaining;
|
||||
if (progressEl) {
|
||||
const pct = missed > 0 ? Math.min(100, Math.round((completed / missed) * 100)) : 100;
|
||||
const pct =
|
||||
missed > 0
|
||||
? Math.min(100, Math.round((completed / missed) * 100))
|
||||
: 100;
|
||||
progressEl.style.width = `${pct}%`;
|
||||
}
|
||||
});
|
||||
|
||||
// Genel İlerleme Çubuğu ve Yüzde Hesaplama
|
||||
const overallPct = grandTotalMissed > 0
|
||||
? Math.min(100, Math.round((grandTotalCompleted / grandTotalMissed) * 100))
|
||||
: 100;
|
||||
const overallPct =
|
||||
grandTotalMissed > 0
|
||||
? Math.min(
|
||||
100,
|
||||
Math.round((grandTotalCompleted / grandTotalMissed) * 100),
|
||||
)
|
||||
: 100;
|
||||
|
||||
const bar = container.querySelector("#overallProgressBar");
|
||||
const pctText = container.querySelector("#overallPercentage");
|
||||
@@ -231,7 +262,8 @@ async function refreshKazaStats(container, pb, birthDate, gender) {
|
||||
if (bar) bar.style.width = `${overallPct}%`;
|
||||
if (pctText) pctText.textContent = `%${overallPct}`;
|
||||
if (compText) compText.textContent = grandTotalCompleted;
|
||||
if (remText) remText.textContent = Math.max(0, grandTotalMissed - grandTotalCompleted);
|
||||
if (remText)
|
||||
remText.textContent = Math.max(0, grandTotalMissed - grandTotalCompleted);
|
||||
|
||||
// İşlem Geçmişi
|
||||
const logsContainer = container.querySelector("#logsContainer");
|
||||
@@ -244,12 +276,13 @@ async function refreshKazaStats(container, pb, birthDate, gender) {
|
||||
const isPlus = log.count > 0;
|
||||
return `
|
||||
<div class="flex items-center justify-between bg-slate-950/30 border border-white/5 rounded-xl px-4 py-2">
|
||||
<span class="text-xs text-slate-300 font-medium">${prayer?.name || log.prayerId} - <span class="text-slate-500">${log.date || ''}</span></span>
|
||||
<span class="text-xs font-bold ${isPlus ? "text-emerald-400" : "text-rose-400"}">${isPlus ? '+' : ''}${log.count}</span>
|
||||
<span class="text-xs text-slate-300 font-medium">${prayer?.name || log.prayerId} - <span class="text-slate-500">${log.date || ""}</span></span>
|
||||
<span class="text-xs font-bold ${isPlus ? "text-emerald-400" : "text-rose-400"}">${isPlus ? "+" : ""}${log.count}</span>
|
||||
</div>
|
||||
`;
|
||||
})
|
||||
.join("") || '<p class="text-xs text-slate-500">Henüz kayıt bulunmuyor.</p>';
|
||||
.join("") ||
|
||||
'<p class="text-xs text-slate-500">Henüz kayıt bulunmuyor.</p>';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,4 +291,4 @@ function showKazaMsg(el, text, success) {
|
||||
el.textContent = text;
|
||||
el.className = `text-xs mt-2.5 ${success ? "text-emerald-400 font-medium" : "text-rose-400"}`;
|
||||
el.classList.remove("hidden");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user