diff --git a/src/main.js b/src/main.js index cc4ae62..1ab247f 100755 --- a/src/main.js +++ b/src/main.js @@ -10,7 +10,7 @@ const app = document.getElementById("app"); let activeTab = "desktop"; let sidebarOpen = window.innerWidth >= 768; -let selectedCity = localStorage.getItem("selected_city") || "İstanbul"; +let selectedCity = localStorage.getItem("selected_city"); async function render() { const user = pb.authStore.model; @@ -61,7 +61,7 @@ async function render() {
-
+
- - -
-
+
+
${ avatarUrl ? `Avatar` diff --git a/src/pages/desktop.js b/src/pages/desktop.js index 294fa1d..97312e8 100644 --- a/src/pages/desktop.js +++ b/src/pages/desktop.js @@ -13,7 +13,8 @@ export function renderDesktop(selectedCity = "İstanbul") { }); const html = ` -
+
+
@@ -121,7 +122,11 @@ async function loadImsakiye(container, selectedCity) { widget.innerHTML = ` 🌅 İmsak: ${times.imsak}
- 🕌 İftar: ${times.maghrib} + 🌅 Güneş: ${times.sunrise}
+ 🌅 Öğle: ${times.dhuhr}
+ 🌅 İkindi: ${times.asr}
+ 🕌 Akşam: ${times.maghrib} + 🌅 Yatsı: ${times.isha}
`; } diff --git a/src/pages/kaza.js b/src/pages/kaza.js index f89470d..fecae06 100644 --- a/src/pages/kaza.js +++ b/src/pages/kaza.js @@ -66,15 +66,18 @@ export function renderKaza(pb) {
-

Kaza Namaz Ekle

+

Kaza Namaz Ekle / Çıkar

- +
@@ -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("") || '

Henüz kayıt yok.

'; } } + +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"); +} diff --git a/src/utils/locations.js b/src/utils/locations.js index 644f375..d1df8b2 100644 --- a/src/utils/locations.js +++ b/src/utils/locations.js @@ -29,6 +29,14 @@ export const TURKISH_CITIES = [ { name: "Isparta", lat: 37.7648, lon: 30.5566 }, { name: "Bolu", lat: 40.7356, lon: 31.6061 }, { name: "Zonguldak", lat: 41.4564, lon: 31.7987 }, + { name: "Edremit", lat: 39.5961, lon: 27.0244 }, + { name: "Bandırma", lat: 40.3210, lon: 27.9765 }, + { name: "Ayvalık", lat: 39.3186, lon: 26.6956 }, + { name: "Gönen", lat: 40.0500, lon: 27.9167 }, + { name: "Burhaniye", lat: 39.5000, lon: 26.9667 }, + { name: "Kadıköy", lat: 40.9833, lon: 29.0833 }, + { name: "Beşiktaş", lat: 41.0436, lon: 29.0053 }, + { name: "Üsküdar", lat: 41.0267, lon: 29.0167 }, ]; export function getCityByName(name) {