ai ile yapılan daha büyük güncelleme

This commit is contained in:
2026-07-28 10:48:10 +03:00
parent e71b6d4a91
commit ffd022ebe1
4 changed files with 81 additions and 28 deletions
+57 -17
View File
@@ -66,15 +66,18 @@ export function renderKaza(pb) {
</div>
<div class="bg-slate-900/40 border border-white/10 p-4 rounded-2xl mb-6">
<h3 class="text-sm font-semibold text-slate-300 mb-3">Kaza Namaz Ekle</h3>
<h3 class="text-sm font-semibold text-slate-300 mb-3">Kaza Namaz Ekle / Çıkar</h3>
<form id="addKazaForm" class="flex items-center gap-3">
<select id="kazaPrayerType" class="bg-slate-950 border border-slate-800 rounded-xl px-4 py-2 text-white text-sm">
${PRAYERS.map((p) => `<option value="${p.id}">${p.name}</option>`).join("")}
</select>
<input type="number" id="kazaCount" min="1" value="1" required class="w-20 bg-slate-950 border border-slate-800 rounded-xl px-4 py-2 text-white text-sm" />
<button type="submit" class="bg-indigo-600 hover:bg-indigo-700 text-white px-4 py-2 rounded-xl text-sm font-medium transition-all">
<button type="button" id="addKazaBtn" class="bg-indigo-600 hover:bg-indigo-700 text-white px-4 py-2 rounded-xl text-sm font-medium transition-all">
Ekle
</button>
<button type="button" id="removeKazaBtn" class="bg-rose-600 hover:bg-rose-700 text-white px-4 py-2 rounded-xl text-sm font-medium transition-all">
Çıkar
</button>
</form>
<p id="kazaMsg" class="text-xs mt-2 hidden"></p>
</div>
@@ -146,10 +149,11 @@ export function renderKaza(pb) {
} else {
refreshKazaStats(container, pb, profile);
const addForm = container.querySelector("#addKazaForm");
if (addForm) {
addForm.addEventListener("submit", async (e) => {
e.preventDefault();
const addBtn = container.querySelector("#addKazaBtn");
const removeBtn = container.querySelector("#removeKazaBtn");
if (addBtn) {
addBtn.addEventListener("click", async () => {
const prayerId = container.querySelector("#kazaPrayerType").value;
const countInput = container.querySelector("#kazaCount");
const count = Math.max(1, parseInt(countInput?.value || "1", 10));
@@ -163,21 +167,50 @@ export function renderKaza(pb) {
date: new Date().toISOString().split("T")[0],
});
if (msg) {
msg.textContent = `${count} kaza namaz eklendi!`;
msg.className = "text-xs mt-2 text-emerald-400";
msg.classList.remove("hidden");
}
showKazaMsg(msg, `${count} kaza namaz eklendi!`, true);
if (countInput) countInput.value = "1";
refreshKazaStats(container, pb, profile);
await refreshKazaStats(container, pb, profile);
} catch (err) {
console.error("Kaza eklenemedi:", err);
if (msg) {
msg.textContent = "Eklenemedi. PocketBase bağlantısını kontrol et.";
msg.className = "text-xs mt-2 text-rose-400";
msg.classList.remove("hidden");
showKazaMsg(msg, "Eklenemedi. PocketBase bağlantısını kontrol et.", false);
}
});
}
if (removeBtn) {
removeBtn.addEventListener("click", async () => {
const prayerId = container.querySelector("#kazaPrayerType").value;
const countInput = container.querySelector("#kazaCount");
const count = Math.max(1, parseInt(countInput?.value || "1", 10));
const msg = container.querySelector("#kazaMsg");
try {
const records = await pb.collection("kaza_logs").getFullList({
filter: `user = "${pb.authStore.model.id}" && prayerId = "${prayerId}"`,
sort: "-createdAt",
});
let remaining = count;
for (const record of records) {
if (remaining <= 0) break;
const recordCount = record.count || 1;
if (recordCount > remaining) {
await pb.collection("kaza_logs").update(record.id, {
count: recordCount - remaining,
});
remaining = 0;
} else {
await pb.collection("kaza_logs").delete(record.id);
remaining -= recordCount;
}
}
showKazaMsg(msg, `${count} kaza namaz çıkarıldı!`, true);
if (countInput) countInput.value = "1";
await refreshKazaStats(container, pb, profile);
} catch (err) {
console.error("Kaza çıkarılamadı:", err);
showKazaMsg(msg, "Çıkarılamadı. PocketBase bağlantısını kontrol et.", false);
}
});
}
@@ -227,6 +260,7 @@ async function refreshKazaStats(container, pb, profile) {
const todayKey = new Date().toISOString().split("T")[0];
const todayLogs = logs.filter((l) => l.date === todayKey);
profile.todayLogs = todayLogs;
localStorage.setItem("kaza_profile", JSON.stringify(profile));
if (logsContainer) {
logsContainer.innerHTML = logs
@@ -243,3 +277,9 @@ async function refreshKazaStats(container, pb, profile) {
.join("") || '<p class="text-xs text-slate-500">Henüz kayıt yok.</p>';
}
}
function showKazaMsg(el, text, success) {
el.textContent = text;
el.className = `text-xs mt-2 ${success ? "text-emerald-400" : "text-rose-400"}`;
el.classList.remove("hidden");
}