voting system fixes for exported articles

This commit is contained in:
sairaj mote 2022-01-18 16:34:41 +05:30
parent 111fa4f0d3
commit f958d0b119
5 changed files with 38 additions and 20 deletions

View File

@ -4429,7 +4429,7 @@ customElements.define('tags-input', class extends HTMLElement {
e.preventDefault() e.preventDefault()
} }
if (e.target.value.trim() !== '') { if (e.target.value.trim() !== '') {
if (e.key === 'Enter' || e.key === ',' || e.key === '/' || e.code === 'Space') { if (e.key === 'Enter' || e.key === ',' || e.key === '/') {
const tagValue = e.target.value.trim() const tagValue = e.target.value.trim()
if (this.tags.has(tagValue)) { if (this.tags.has(tagValue)) {
this.tagsWrapper.querySelector(`[data-value="${tagValue}"]`).animate([ this.tagsWrapper.querySelector(`[data-value="${tagValue}"]`).animate([

View File

@ -758,6 +758,7 @@ sm-copy {
.content-card--empty .content__area { .content-card--empty .content__area {
min-height: calc(60vh + 3rem); min-height: calc(60vh + 3rem);
height: 100%; height: 100%;
max-height: calc(60vh + 3rem);
} }
.content-card .submit-entry { .content-card .submit-entry {
border-radius: 0.2rem; border-radius: 0.2rem;

2
css/main.min.css vendored

File diff suppressed because one or more lines are too long

View File

@ -719,6 +719,7 @@ sm-copy {
.content__area { .content__area {
min-height: calc(60vh + 3rem); min-height: calc(60vh + 3rem);
height: 100%; height: 100%;
max-height: calc(60vh + 3rem);
} }
} }
.submit-entry { .submit-entry {

View File

@ -564,7 +564,7 @@
</div> </div>
<div class="grid gap-0-5"> <div class="grid gap-0-5">
<h5>Add tags</h5> <h5>Add tags</h5>
<tags-input id="article_tags" limit="10" required></tags-input> <tags-input id="article_tags" limit="10"></tags-input>
</div> </div>
<sm-button variant="primary" onclick="publishArticle()">Request publishing</sm-button> <sm-button variant="primary" onclick="publishArticle()">Request publishing</sm-button>
</sm-form> </sm-form>
@ -12814,7 +12814,7 @@
<template id="voting_enabled"> <template id="voting_enabled">
<footer class="grid gap-1-5"> <footer class="grid gap-1-5">
<h4>Loved the article? Don't forget leave a like.</h4> <h4>Loved the article? Don't forget leave a like.</h4>
<button id="upvote_button" class="button upvote" onclick="upvote(this)"> <button id="upvote_button" class="button upvote">
<svg class="icon" xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" <svg class="icon" xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px"
fill="#000000"> fill="#000000">
<path d="M0 0h24v24H0z" fill="none" /> <path d="M0 0h24v24H0z" fill="none" />
@ -13063,8 +13063,21 @@
}) })
return anime return anime
} }
// Use when a function needs to be executed after user finishes changes
const debounce = (callback, wait) => {
let timeoutId = null;
return (...args) => {
window.clearTimeout(timeoutId);
timeoutId = window.setTimeout(() => {
callback.apply(null, args);
}, wait);
};
}
let tempVoteCount = 0
getRef('upvote_button').addEventListener('mouseup', function () { getRef('upvote_button').addEventListener('mouseup', function () {
if (isLoggedIn) { if (isLoggedIn) {
tempVoteCount++;
const animOptions = { const animOptions = {
fill: 'forwards', fill: 'forwards',
duration: 300, duration: 300,
@ -13087,13 +13100,13 @@
], animOptions).onfinish = e => e.target.cancel() ], animOptions).onfinish = e => e.target.cancel()
} }
}) })
function animateLikeCount() { function animateLikeCount(voteCount = 1) {
const animOptions = { const animOptions = {
fill: 'forwards', fill: 'forwards',
duration: 150, duration: 150,
ease: 'easing', ease: 'easing',
} }
totalVotes++ totalVotes += voteCount
getRef('like_count').animate(slideOutUp, animOptions) getRef('like_count').animate(slideOutUp, animOptions)
.onfinish = (e) => { .onfinish = (e) => {
e.target.cancel() e.target.cancel()
@ -13108,20 +13121,20 @@
tempCount.remove() tempCount.remove()
} }
} }
function upvote(elem) { getRef('upvote_button').addEventListener('click', debounce(() => {
if (isLoggedIn) { if (isLoggedIn) {
// animateLikeCount()
floCloudAPI.sendGeneralData({ floCloudAPI.sendGeneralData({
articleID: currentArticleID, voteCount: tempVoteCount,
}, `article_${currentArticleID}_votes`) }, `article_${currentArticleID}_votes`)
.then(res => { .then(res => {
console.log('upvoted') tempVoteCount = 0
console.log('up voted')
}) })
.catch(err => console.log(err)) .catch(err => console.log(err))
} else { } else {
showPopup('sign_in_popup') showPopup('sign_in_popup')
} }
} }, 300))
const slideInLeft = [ const slideInLeft = [
{ {
opacity: 0, opacity: 0,
@ -13248,26 +13261,29 @@
//floDapps.setAppObjectStores({sampleObs1:{}, sampleObs2:{options{autoIncrement:true, keyPath:'SampleKey'}, Indexes:{sampleIndex:{}}}}) //floDapps.setAppObjectStores({sampleObs1:{}, sampleObs2:{options{autoIncrement:true, keyPath:'SampleKey'}, Indexes:{sampleIndex:{}}}})
let firstLoad = true let firstLoad = true
floDapps.setMidStartup(() => new Promise(async (resolve, reject) => { floDapps.setMidStartup(() => new Promise(async (resolve, reject) => {
await floCloudAPI.requestObjectData('RMT') await floCloudAPI.requestObjectData('articles')
totalVotes = floGlobals.appObjects.articles[currentArticleID].votes
await floCloudAPI.requestGeneralData(`article_${currentArticleID}_votes`, { await floCloudAPI.requestGeneralData(`article_${currentArticleID}_votes`, {
callback: (d, e) => { lowerVectorClock: floGlobals.appObjects.articles[currentArticleID].lastCountedVC,
callback: (allVotes, e) => {
if (firstLoad) { if (firstLoad) {
const allVotes = floGlobals.generalData[`article_${currentArticleID}_votes|${floGlobals.adminID}|${floGlobals.application}`] let first = true
for (const vote in allVotes) { for (const vote in allVotes) {
const { message: { articleID } } = allVotes[vote] if (first) {
if (allVotes[vote].message.articleID === currentArticleID) { first = false
totalVotes++ continue
} }
totalVotes += allVotes[vote].message.voteCount || 1
} }
getRef('like_count').textContent = getRelativeCount(totalVotes) getRef('like_count').textContent = getRelativeCount(totalVotes)
} else { } else {
animateLikeCount() for (const msg in allVotes) {
animateLikeCount(allVotes[msg].message.voteCount)
}
} }
firstLoad = false firstLoad = false
} }
}) })
resolve(true) resolve(true)
})) }))
floDapps.setCustomPrivKeyInput(() => new Promise((resolve, reject) => { floDapps.setCustomPrivKeyInput(() => new Promise((resolve, reject) => {