mirror of
https://github.com/nunocoracao/blowfish.git
synced 2025-02-02 03:22:33 -06:00
fixed bug with like button
This commit is contained in:
parent
a1e01348c8
commit
d2b9ff9c0b
2 changed files with 19 additions and 12 deletions
|
@ -63,20 +63,23 @@
|
|||
|
||||
if (liked) {
|
||||
liked_article = true
|
||||
document.querySelectorAll("button[id='likes_button']")[0].textContent = "Remove Like"
|
||||
document.querySelectorAll("span[id='likes_button_heart']")[0].style.display = ""
|
||||
document.querySelectorAll("span[id='likes_button_emtpty_heart']")[0].style.display = "none"
|
||||
document.querySelectorAll("span[id='likes_button_text']")[0].innerText = "Remove Like"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function like_article(id_likes) {
|
||||
console.log("add")
|
||||
liked_article = true
|
||||
localStorage.setItem(id_likes, true);
|
||||
document.querySelectorAll("button[id='likes_button']")[0].innerText = "Remove Like"
|
||||
auth.signInAnonymously()
|
||||
.then(() => {
|
||||
var docRef = db.collection('likes').doc(id_likes)
|
||||
docRef.get().then((doc) => {
|
||||
liked_article = true
|
||||
localStorage.setItem(id_likes, true);
|
||||
document.querySelectorAll("span[id='likes_button_heart']")[0].style.display = ""
|
||||
document.querySelectorAll("span[id='likes_button_emtpty_heart']")[0].style.display = "none"
|
||||
document.querySelectorAll("span[id='likes_button_text']")[0].innerText = "Remove Like"
|
||||
if (doc.exists) {
|
||||
db.collection('likes').doc(id_likes).update({
|
||||
likes: firebase.firestore.FieldValue.increment(1)
|
||||
|
@ -96,14 +99,15 @@
|
|||
}
|
||||
|
||||
function remove_like_article(id_likes) {
|
||||
console.log("remove")
|
||||
liked_article = false
|
||||
localStorage.removeItem(id_likes);
|
||||
document.querySelectorAll("button[id='likes_button']")[0].innerText = "Like"
|
||||
auth.signInAnonymously()
|
||||
.then(() => {
|
||||
var docRef = db.collection('likes').doc(id_likes)
|
||||
docRef.get().then((doc) => {
|
||||
liked_article = false
|
||||
localStorage.removeItem(id_likes);
|
||||
document.querySelectorAll("span[id='likes_button_heart']")[0].style.display = "none"
|
||||
document.querySelectorAll("span[id='likes_button_emtpty_heart']")[0].style.display = ""
|
||||
document.querySelectorAll("span[id='likes_button_text']")[0].innerText = "Like"
|
||||
if (doc.exists) {
|
||||
db.collection('likes').doc(id_likes).update({
|
||||
likes: firebase.firestore.FieldValue.increment(-1)
|
||||
|
@ -151,4 +155,4 @@
|
|||
{{ end }}
|
||||
</footer>
|
||||
</article>
|
||||
{{ end }}
|
||||
{{ end }}
|
|
@ -5,10 +5,13 @@
|
|||
|
||||
|
||||
<button id="likes_button"
|
||||
style="height: 24px; padding-top: 0;"
|
||||
style="height: 24px; padding-top: 0px; padding-bottom: 5px; padding-left: 10px; padding-right: 10px"
|
||||
class="!rounded-md bg-primary-600 px-4 py-2 !text-neutral !no-underline hover:!bg-primary-500 dark:bg-primary-800 dark:hover:!bg-primary-700"
|
||||
onclick="process_article()">
|
||||
{{ partial "icon.html" "like" }}
|
||||
<span id="likes_button_heart" style="display:none">{{ partial "icon.html" "heart" }} </span>
|
||||
<span id="likes_button_emtpty_heart">{{ partial "icon.html" "heart-empty" }}</span>
|
||||
|
||||
<span id="likes_button_text">Like</span>
|
||||
</button>
|
||||
|
||||
</span>
|
||||
|
|
Loading…
Reference in a new issue