mirror of
https://github.com/nunocoracao/blowfish.git
synced 2025-04-21 01:51:54 +02: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) {
|
if (liked) {
|
||||||
liked_article = true
|
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) {
|
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()
|
auth.signInAnonymously()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
var docRef = db.collection('likes').doc(id_likes)
|
var docRef = db.collection('likes').doc(id_likes)
|
||||||
docRef.get().then((doc) => {
|
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) {
|
if (doc.exists) {
|
||||||
db.collection('likes').doc(id_likes).update({
|
db.collection('likes').doc(id_likes).update({
|
||||||
likes: firebase.firestore.FieldValue.increment(1)
|
likes: firebase.firestore.FieldValue.increment(1)
|
||||||
|
@ -96,14 +99,15 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function remove_like_article(id_likes) {
|
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()
|
auth.signInAnonymously()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
var docRef = db.collection('likes').doc(id_likes)
|
var docRef = db.collection('likes').doc(id_likes)
|
||||||
docRef.get().then((doc) => {
|
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) {
|
if (doc.exists) {
|
||||||
db.collection('likes').doc(id_likes).update({
|
db.collection('likes').doc(id_likes).update({
|
||||||
likes: firebase.firestore.FieldValue.increment(-1)
|
likes: firebase.firestore.FieldValue.increment(-1)
|
||||||
|
@ -151,4 +155,4 @@
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</footer>
|
</footer>
|
||||||
</article>
|
</article>
|
||||||
{{ end }}
|
{{ end }}
|
|
@ -5,10 +5,13 @@
|
||||||
|
|
||||||
|
|
||||||
<button id="likes_button"
|
<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"
|
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()">
|
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>
|
</button>
|
||||||
|
|
||||||
</span>
|
</span>
|
||||||
|
|
Loading…
Add table
Reference in a new issue