-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotice.html
More file actions
105 lines (85 loc) · 2.61 KB
/
Copy pathnotice.html
File metadata and controls
105 lines (85 loc) · 2.61 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
<!DOCTYPE html>
<html>
<head>
<title>Notices - Smart College Navigation</title>
<link rel="stylesheet" href="style.css">
<style>
.notice-container {
padding: 20px;
}
.notice {
background: #f2f2f2;
padding: 15px;
margin-bottom: 10px;
border-radius: 6px;
}
input, textarea {
width: 100%;
padding: 8px;
margin-bottom: 10px;
}
button {
padding: 8px 15px;
cursor: pointer;
}
</style>
</head>
<body>
<header>
<h1>College Notices 📰</h1>
<button onclick="window.location.href='dashboard.html'">Back</button>
</header>
<div class="notice-container">
<h3>Add Notice (Admin)</h3>
<input type="text" id="noticeTitle" placeholder="Notice Title">
<textarea id="noticeContent" placeholder="Notice Content"></textarea>
<button id="addNoticeBtn">Add Notice</button>
<hr>
<h3>All Notices</h3>
<div id="noticesList"></div>
</div>
<script type="module">
import { initializeApp } from "https://www.gstatic.com/firebasejs/12.9.0/firebase-app.js";
import { getFirestore, collection, addDoc, onSnapshot, query, orderBy } from "https://www.gstatic.com/firebasejs/12.9.0/firebase-firestore.js";
const firebaseConfig = {
apiKey: "AIzaSyBzMLug_TU5BW7fxEpAND4KiyVjeWcxcrs",
authDomain: "college-location-app.firebaseapp.com",
projectId: "college-location-app",
storageBucket: "college-location-app.firebasestorage.app",
messagingSenderId: "1000054805371",
appId: "1:1000054805371:web:93f13c5f877dba7b6863de"
};
const app = initializeApp(firebaseConfig);
const db = getFirestore(app);
const noticesList = document.getElementById("noticesList");
const q = query(collection(db, "notices"), orderBy("timestamp", "desc"));
onSnapshot(q, (snapshot) => {
noticesList.innerHTML = "";
snapshot.forEach((doc) => {
const notice = doc.data();
noticesList.innerHTML += `
<div class="notice">
<h4>${notice.title}</h4>
<p>${notice.content}</p>
</div>
`;
});
});
document.getElementById("addNoticeBtn").addEventListener("click", async () => {
const title = document.getElementById("noticeTitle").value;
const content = document.getElementById("noticeContent").value;
if (title === "" || content === "") {
alert("Please fill all fields");
return;
}
await addDoc(collection(db, "notices"), {
title: title,
content: content,
timestamp: new Date()
});
document.getElementById("noticeTitle").value = "";
document.getElementById("noticeContent").value = "";
});
</script>
</body>
</html>