PocketBase admin paneli ve db bağlantısı güncellendi
This commit is contained in:
25
admin.js
25
admin.js
@@ -1,8 +1,8 @@
|
||||
import PocketBase from 'https://cdnjs.cloudflare.com/ajax/libs/pocketbase/0.21.1/pocketbase.es.mjs';
|
||||
|
||||
// 1. PocketBase Bağlantısı
|
||||
// 'https://pocketbase.batuhanerkek.com' kısmını kendi domaininle değiştir
|
||||
const pb = new PocketBase('https://pocketbase.batuhanerkek.com');
|
||||
// Tarayıcıdaki PocketBase panel adresinle (db. veya pocketbase.) birebir aynı olmalıdır.
|
||||
const pb = new PocketBase('https://db.batuhanerkek.com');
|
||||
|
||||
const loginCard = document.getElementById("login-card");
|
||||
const adminPanel = document.getElementById("admin-panel");
|
||||
@@ -32,6 +32,7 @@ loginForm.addEventListener("submit", async (event) => {
|
||||
event.preventDefault();
|
||||
const formData = new FormData(loginForm);
|
||||
try {
|
||||
// PocketBase 'users' koleksiyonu üzerinden giriş yapar
|
||||
await pb.collection('users').authWithPassword(
|
||||
formData.get("email"),
|
||||
formData.get("password")
|
||||
@@ -54,9 +55,10 @@ blogForm.addEventListener("submit", async (event) => {
|
||||
event.preventDefault();
|
||||
const formData = new FormData(blogForm);
|
||||
|
||||
// PocketBase 'posts' koleksiyonundaki alan isimleriyle birebir aynı olmalıdır
|
||||
const newPost = {
|
||||
title: formData.get("title").trim(),
|
||||
tags: JSON.stringify(currentTags), // PocketBase için dizi formatı
|
||||
tags: JSON.stringify(currentTags), // PocketBase'de tags alanı JSON ise bu format uygundur
|
||||
summary: formData.get("summary").trim(),
|
||||
content: formData.get("content").trim(),
|
||||
date: formData.get("date"),
|
||||
@@ -79,7 +81,7 @@ blogForm.addEventListener("submit", async (event) => {
|
||||
async function loadPosts() {
|
||||
try {
|
||||
const records = await pb.collection('posts').getFullList({
|
||||
sort: '-created',
|
||||
sort: '-created', // En yeni yazıyı en üstte gösterir
|
||||
});
|
||||
|
||||
postsList.innerHTML = records.map(post => `
|
||||
@@ -93,7 +95,7 @@ async function loadPosts() {
|
||||
}
|
||||
}
|
||||
|
||||
// Yazı Silme Fonksiyonu (Global yapıyoruz)
|
||||
// Yazı Silme Fonksiyonu
|
||||
window.deletePost = async (id) => {
|
||||
if (confirm("Bu yazıyı silmek istediğinize emin misiniz?")) {
|
||||
try {
|
||||
@@ -117,6 +119,7 @@ window.removeTag = (index) => {
|
||||
renderTags();
|
||||
};
|
||||
|
||||
// Enter ile etiket ekleme
|
||||
tagsInput.addEventListener("keydown", (event) => {
|
||||
if (event.key === "Enter") {
|
||||
event.preventDefault();
|
||||
@@ -129,7 +132,17 @@ tagsInput.addEventListener("keydown", (event) => {
|
||||
}
|
||||
});
|
||||
|
||||
// Sayfa yüklendiğinde oturum kontrolü
|
||||
// Inputtan odak çıkınca da etiket ekleme (Hızlı kullanım için eklendi)
|
||||
tagsInput.addEventListener("blur", () => {
|
||||
const tag = tagsInput.value.trim();
|
||||
if (tag && !currentTags.includes(tag)) {
|
||||
currentTags.push(tag);
|
||||
renderTags();
|
||||
}
|
||||
tagsInput.value = "";
|
||||
});
|
||||
|
||||
// Sayfa yüklendiğinde mevcut oturumu kontrol et
|
||||
if (pb.authStore.isValid) {
|
||||
setAuthState(true);
|
||||
}
|
||||
Reference in New Issue
Block a user