-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathposts.html
122 lines (114 loc) · 5.31 KB
/
posts.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="styles.css" rel="stylesheet" type="text/css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Posts</title>
<link rel="icon" href="Bloggerzz icon.png">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-U1DAWAznBHeqEIlVSCgzq+c9gqGAJn5c/t99JyeKa9xxaYpSvHU5awsuZVVFIhvj" crossorigin="anonymous"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KyZXEAg3QhqLMpG8r+8fhAXLRk2vvoC2f3B09zVXn8CA5QIVfZOJ3BCsw2P0p/We" crossorigin="anonymous">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a href="home.html" class="navbar-brand"><img src="Bloggerzz icon.png" width="50"/></a>
<div class="container-fluid">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link " href="home.html" >Feed</a>
</li>
<li class="nav-item">
<a class="nav-link" href="myposts.html" >Your posts</a>
</li>
<li class="nav-item">
<a class="nav-link" href="blog.html" >Add blog</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="public_content">
<div id="Blog" class="me-auto ms-auto">
<h1 id="header"></h1>
<h5 id="dateTime"></h5>
<h4 id="content" style="text-align: justify; margin: 20px;"></h4>
</div>
<div id="commentsSection" class="me-auto ms-auto">
<br>
<div>
<h5 id="commentor"></h5>
<div style="display:flex; width:50%;justify-content:space-between">
<input type="text" id="comment_content" class="form-control" placeholder="Enter your comments here.."/>
</br>
<button id="post_comment" class="btn btn-primary" onclick="postComment()">Post</button>
</div>
</div>
</br>
<div id="display_comments">
<h5>Comments</h5>
<div id="comment_user"></div>
<div id="comment_text"></div>
</div>
</div>
</div>
<script src="https://www.gstatic.com/firebasejs/7.17.1/firebase.js"></script>
<script src="firebase.js"></script>
<script>var linkkey=window.location.search;
var postskey=linkkey.slice(1,);
firebase.database().ref("blogs").once("value",function(snapshot){
snapshot.forEach(function(childSnapshot){
var childKey=childSnapshot.key;
var childValue=childSnapshot.val();
// document.getElementById("Blog").innerHTML+=childKey+postskey+'</br>';
if(childKey==postskey){
document.getElementById("header").innerHTML=childValue["heading"]+'</br>';
document.getElementById("content").innerHTML=childValue["blogtext"]+'</br></br>';
document.getElementById("dateTime").innerHTML='Posted on '+Date(childValue["date"]).slice(0,25)+'by '+childValue["author"]+'</br>';
if(childValue["status"]=="public"){
document.getElementById("commentsSection").style.display="block";
}
}
});
});
var commentor=sessionStorage.getItem("username");
document.getElementById("commentor").innerHTML=commentor;
let comments=firebase.database().ref("comments");
let commentText=document.getElementById("comment_content").value;
function postComment(){
if(commentText!=""){
function addComment(commentor,commentText,postskey){
let newComments=comments.push();
newComments.set({
commentor:commentor,
commentText:commentText,
blogkey:postskey,
});
alert("Your comment is posted! Refresh the page");
}
addComment(commentor,commentText,postskey)
}
else{
alert("You need to add something");
}
}
function dispComment(){
firebase.database().ref("comments").once("value",function(snapshot){
snapshot.forEach(function(childSnapshot){
var childKey=childSnapshot.key;
var childValue=childSnapshot.val();
if(postskey==childValue["blogkey"]){
let displaying='<div id="comm"><div id="comment_user" style="font-weight:bold">'+childValue["commentor"]+'</div><div id="comment_text">'+childValue["commentText"]+'</div></div>';
document.getElementById("comment_user").innerHTML+=displaying;
}
});
});
}
dispComment();
</script>
</body>
</html>