-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
209 lines (189 loc) · 9.29 KB
/
Copy pathscript.js
File metadata and controls
209 lines (189 loc) · 9.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/* =========================================
1. ফায়ারবেস ইনিশিয়ালাইজেশন (আপনার কনফিগারেশন)
========================================= */
const firebaseConfig = {
apiKey: "AIzaSyCqxhTm4jtRA6aQIN6dxYPu8JpEb9s8K2o",
authDomain: "star-shop-1fe3f.firebaseapp.com",
projectId: "star-shop-1fe3f",
storageBucket: "star-shop-1fe3f.firebasestorage.app",
messagingSenderId: "406302393334",
appId: "1:406302393334:web:e56bc053a710d1dd64bdd7"
};
// ফায়ারবেস অ্যাপ শুরু করা
if (!firebase.apps.length) {
firebase.initializeApp(firebaseConfig);
}
// ফায়ারবেস সার্ভিসসমূহ
const auth = firebase.auth();
const db = firebase.firestore();
/* =========================================
2. ডেমো ডেটা (বইয়ের তালিকা)
========================================= */
// বর্তমানে ডাটাবেসে বই না থাকলেও সাইট যাতে সুন্দর দেখায়, তাই এই ডেমো লিস্ট রাখা হলো।
// আপনি পরে Firestore থেকে ডাটা লোড করার কোড চালু করতে পারবেন।
const demoBooks = [
{
id: 1,
title: "অর্থনীতির সহজ পাঠ",
author: "মোঃ মঞ্জিরুল হক",
pages: "১২০",
size: "৩.৫ এমবি",
cover: "https://via.placeholder.com/300x450/0f172a/00d2ff?text=Economics+101",
description: "উচ্চ মাধ্যমিক ও স্নাতক শিক্ষার্থীদের জন্য অর্থনীতির জটিল বিষয়গুলোর সহজ বিশ্লেষণ।",
category: "Economics"
},
{
id: 2,
title: "গ্রাফিক্স ডিজাইন মাস্টারি",
author: "মোঃ মঞ্জিরুল হক",
pages: "৮৫",
size: "১০ এমবি",
cover: "https://via.placeholder.com/300x450/0f172a/3a7bd5?text=Graphics+Design",
description: "ফটোশপ এবং ইলাস্ট্রেটর ব্যবহার করে প্রফেশনাল ডিজাইন শেখার পূর্ণাঙ্গ গাইড।",
category: "Design"
},
{
id: 3,
title: "প্রাচীন বাংলার ইতিহাস",
author: "ইতিহাস বিভাগ",
pages: "২০০",
size: "৫.২ এমবি",
cover: "https://via.placeholder.com/300x450/0f172a/e2e8f0?text=History+BD",
description: "কৌটিল্যের অর্থশাস্ত্র থেকে শুরু করে বাংলাদেশের অভ্যুদয় পর্যন্ত ইতিহাসের ধারা।",
category: "History"
},
{
id: 4,
title: "ডিজিটাল মার্কেটিং সিক্রেটস",
author: "স্টারলাইন একাডেমি",
pages: "৫০",
size: "২ এমবি",
cover: "https://via.placeholder.com/300x450/0f172a/00d2ff?text=Digital+Marketing",
description: "ফেসবুক ও ইউটিউব কন্টেন্ট ক্রিয়েশন এবং মনিটাইজেশন গাইডলাইন।",
category: "Marketing"
}
];
/* =========================================
3. ভেরিয়েবল এবং এলিমেন্ট সিলেক্টর
========================================= */
const ebookList = document.getElementById('ebook-list');
const loadMoreBtn = document.getElementById('load-more-btn');
const modal = document.getElementById('ebook-modal');
const authModal = document.getElementById('auth-modal');
// মডাল এলিমেন্টস
const modalTitle = document.querySelector('.modal-body h3');
const modalCover = document.querySelector('.modal-cover');
const modalDesc = document.querySelector('.modal-description');
const modalAuthor = document.getElementById('author-name');
const modalPages = document.getElementById('page-count');
const modalSize = document.getElementById('file-size');
/* =========================================
4. বই রেন্ডার করা (UI আপডেট)
========================================= */
function renderBooks(books) {
ebookList.innerHTML = '';
books.forEach((book, index) => {
const bookCard = document.createElement('div');
bookCard.classList.add('ebook-card');
// এনিমেশন
bookCard.style.animation = `fadeIn 0.5s ease forwards ${index * 0.1}s`;
bookCard.style.opacity = '0';
bookCard.innerHTML = `
<div style="text-align: center; overflow: hidden; border-radius: 10px; margin-bottom: 15px;">
<img src="${book.cover}" alt="${book.title}" style="width: 100%; height: 250px; object-fit: cover; transition: transform 0.3s;">
</div>
<h3 style="color: var(--primary-color); font-size: 1.2rem; margin-bottom: 5px;">${book.title}</h3>
<p style="color: #94a3b8; font-size: 0.9rem; margin-bottom: 15px;">${book.author}</p>
<button class="cta-button" onclick="openBookModal(${book.id})" style="width: 100%; font-size: 0.9rem; padding: 8px 0;">বিস্তারিত দেখুন</button>
`;
ebookList.appendChild(bookCard);
});
// CSS এনিমেশন স্টাইল যোগ করা
if (!document.getElementById('dynamic-styles')) {
const styleSheet = document.createElement("style");
styleSheet.id = 'dynamic-styles';
styleSheet.innerText = `
@keyframes fadeIn {
from { opacity: 0; transform: translateY(20px); }
to { opacity: 1; transform: translateY(0); }
}
`;
document.head.appendChild(styleSheet);
}
}
/* =========================================
5. মডাল ওপেন ফাংশন
========================================= */
window.openBookModal = function(bookId) {
const book = demoBooks.find(b => b.id === bookId);
if (book) {
modalTitle.innerText = book.title;
modalCover.src = book.cover;
modalDesc.innerText = book.description;
modalAuthor.innerText = book.author;
modalPages.innerText = book.pages;
modalSize.innerText = book.size;
modal.style.display = 'block';
}
};
/* =========================================
6. ইভেন্ট লিসেনার (Load More & Modals)
========================================= */
if(loadMoreBtn){
loadMoreBtn.addEventListener('click', () => {
alert("শীঘ্রই আরও বই যুক্ত করা হবে! আমাদের সাথেই থাকুন।");
});
}
// পেজ লোড হলে বই দেখাও
document.addEventListener('DOMContentLoaded', () => {
renderBooks(demoBooks);
checkAuthState(); // ব্যবহারকারী লগইন আছে কিনা চেক করুন
});
/* =========================================
7. অথেনটিকেশন লজিক (লগইন/সাইনআপ)
========================================= */
const loginForm = document.getElementById('login-form');
if(loginForm) {
loginForm.addEventListener('submit', (e) => {
e.preventDefault();
const email = e.target.querySelector('input[type="email"]').value;
const password = e.target.querySelector('input[type="password"]').value;
const submitBtn = e.target.querySelector('button');
submitBtn.innerText = "লগইন হচ্ছে...";
// ফায়ারবেস লগইন ফাংশন
auth.signInWithEmailAndPassword(email, password)
.then((userCredential) => {
// সফল হলে
alert("লগইন সফল হয়েছে! স্বাগতম।");
authModal.style.display = 'none';
updateUIForUser(userCredential.user);
})
.catch((error) => {
// ভুল হলে
alert("ত্রুটি: " + error.message);
})
.finally(() => {
submitBtn.innerText = "লগইন করুন";
});
});
}
// লগইন অবস্থা চেক করা এবং UI আপডেট করা
function checkAuthState() {
auth.onAuthStateChanged((user) => {
if (user) {
updateUIForUser(user);
} else {
console.log("No user logged in");
}
});
}
function updateUIForUser(user) {
const loginBtn = document.getElementById('open-auth-modal-btn');
if(loginBtn) {
loginBtn.innerText = "ড্যাশবোর্ড";
loginBtn.href = "dashboard.html";
loginBtn.onclick = null; // মডাল ওপেন ইভেন্ট রিমুভ করা
loginBtn.style.background = "var(--primary-color)";
loginBtn.style.color = "#000";
}
}