code refactoring

This commit is contained in:
sairaj mote 2022-01-23 16:10:38 +05:30
parent e8c1b979c9
commit 250b0b8d41

View File

@ -616,7 +616,8 @@
</svg> </svg>
<div class="content__author flex align-center"></div> <div class="content__author flex align-center"></div>
</Button> </Button>
<sm-checkbox class="content__checkbox" aria-label="Select content"></sm-checkbox> <sm-checkbox class="content__checkbox" aria-label="Select content"
title="Select this snippet to download as HTML"></sm-checkbox>
</div> </div>
<div class="content__area"></div> <div class="content__area"></div>
<div class="flex align-center space-between"> <div class="flex align-center space-between">
@ -1341,7 +1342,7 @@
if (noOfContributors === 2) if (noOfContributors === 2)
break break
} }
if (noOfContributors < 2) { if (noOfContributors < 2 && !contributors.hasOwnProperty(myFloID)) {
contentCard.querySelector('.content__author').textContent = `2 Contributors` contentCard.querySelector('.content__author').textContent = `2 Contributors`
} }
floGlobals.currentArticle.uniqueEntries[entry.origin].iterations.push(genDataVC) floGlobals.currentArticle.uniqueEntries[entry.origin].iterations.push(genDataVC)
@ -1439,7 +1440,7 @@
easing: 'ease', easing: 'ease',
} }
const selectedContentSize = selectedContent.size const selectedContentSize = selectedContent.size
getRef('selected_entries_no').textContent = `${selectedContentSize} selected` getRef('selected_entries_no').textContent = `${selectedContentSize} selected for download`
if (selectedContentSize === 1 && !isContentSelected) { if (selectedContentSize === 1 && !isContentSelected) {
getRef('article_name_wrapper').classList.remove('hide-completely') getRef('article_name_wrapper').classList.remove('hide-completely')
getRef('selected_content_options').classList.add('hide-completely') getRef('selected_content_options').classList.add('hide-completely')
@ -13063,24 +13064,24 @@
], animOptions).onfinish = e => e.target.cancel() ], animOptions).onfinish = e => e.target.cancel()
} }
}) })
function animateLikeCount(voteCount = 1) { function animateLikeCount(voteCount = 1, articleID) {
const animOptions = { const animOptions = {
fill: 'forwards', fill: 'forwards',
duration: 150, duration: 150,
ease: 'easing', ease: 'easing',
} }
totalVotes += voteCount floGlobals.appObjects.articles[articleID].votes += voteCount
getRef('like_count').animate(slideOutUp, animOptions) getRef('like_count').animate(slideOutUp, animOptions)
.onfinish = (e) => { .onfinish = (e) => {
e.target.cancel() e.target.cancel()
} }
const tempCount = document.createElement('div') const tempCount = document.createElement('div')
tempCount.classList.add('temp-count') tempCount.classList.add('temp-count')
tempCount.textContent = getRelativeCount(totalVotes) tempCount.textContent = floGlobals.appObjects.articles[articleID].votes
getRef('like_count').after(tempCount) getRef('like_count').after(tempCount)
tempCount.animate(slideInUp, animOptions) tempCount.animate(slideInUp, animOptions)
.onfinish = () => { .onfinish = () => {
getRef('like_count').textContent = getRelativeCount(totalVotes) getRef('like_count').textContent = floGlobals.appObjects.articles[articleID].votes
tempCount.remove() tempCount.remove()
} }
} }
@ -13183,14 +13184,6 @@
animateTo(getRef('sign_up'), slideInLeft, animOptions) animateTo(getRef('sign_up'), slideInLeft, animOptions)
} }
} }
function getRelativeCount(count) {
if (count < 1000)
return count
else if (count < 1000000)
return parseFloat((count / 1000).toFixed(1)) + 'K'
else if (count < 1000000000)
return parseFloat((count / 1000000).toFixed(1)) + 'M'
}
function goToSignIn() { function goToSignIn() {
const animOptions = { const animOptions = {
fill: 'forwards', fill: 'forwards',
@ -13218,30 +13211,23 @@
<script id="onLoadStartUp"> <script id="onLoadStartUp">
floGlobals.isSubAdmin = false floGlobals.isSubAdmin = false
let isLoggedIn = false let isLoggedIn = false
let totalVotes = 0
function onLoadStartUp() { function onLoadStartUp() {
//floDapps.addStartUpFunction('Sample', Promised Function) //floDapps.addStartUpFunction('Sample', Promised Function)
//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('articles') await floCloudAPI.requestObjectData('articles')
totalVotes = floGlobals.appObjects.articles[currentArticleID].votes
await floCloudAPI.requestGeneralData(`article_${currentArticleID}_votes`, { await floCloudAPI.requestGeneralData(`article_${currentArticleID}_votes`, {
lowerVectorClock: floGlobals.appObjects.articles[currentArticleID].lastCountedVC, lowerVectorClock: floGlobals.appObjects.articles[currentArticleID].lastCountedVC + 1,
callback: (allVotes, e) => { callback: (allVotes, e) => {
if (firstLoad) { if (firstLoad) {
let first = true
for (const vote in allVotes) { for (const vote in allVotes) {
if (first) { floGlobals.appObjects.articles[currentArticleID].votes += allVotes[vote].message.voteCount || 1
first = false
continue
}
totalVotes += allVotes[vote].message.voteCount || 1
} }
getRef('like_count').textContent = getRelativeCount(totalVotes) getRef('like_count').textContent = floGlobals.appObjects.articles[currentArticleID].votes
} else { } else {
for (const msg in allVotes) { for (const msg in allVotes) {
animateLikeCount(allVotes[msg].message.voteCount) animateLikeCount(allVotes[msg].message.voteCount, currentArticleID)
} }
} }
firstLoad = false firstLoad = false