implemented live like updates

This commit is contained in:
sairaj mote 2021-12-13 03:00:28 +05:30
parent 81c7448e7b
commit eb29f04103

View File

@ -128,7 +128,7 @@
</sm-menu> </sm-menu>
</div> </div>
<div id="selected_content_options" class="flex hide-completely"> <div id="selected_content_options" class="flex hide-completely">
<button class="button" onclick="formatSelectedContent()"> <button class="button" onclick="renderPreview()">
<svg class="icon button__icon--left" xmlns="http://www.w3.org/2000/svg" <svg class="icon button__icon--left" xmlns="http://www.w3.org/2000/svg"
enable-background="new 0 0 24 24" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"> enable-background="new 0 0 24 24" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000">
<g> <g>
@ -1267,6 +1267,11 @@
if (!composedDocumentStructure[section].length) if (!composedDocumentStructure[section].length)
delete composedDocumentStructure[section] delete composedDocumentStructure[section]
} }
return composedDocumentStructure
}
function renderPreview() {
const composedDocumentStructure = formatSelectedContent()
let frag = document.createDocumentFragment() let frag = document.createDocumentFragment()
for (const section in composedDocumentStructure) { for (const section in composedDocumentStructure) {
@ -1302,6 +1307,7 @@
window.location.hash = `#/preview?articleID=${currentArticle.id}` window.location.hash = `#/preview?articleID=${currentArticle.id}`
} }
function downloadHTML(string, options = {}) { function downloadHTML(string, options = {}) {
const { title } = options const { title } = options
const element = createElement('a', { const element = createElement('a', {
@ -1321,15 +1327,7 @@
function exportSelection() { function exportSelection() {
const bodyTemplate = getRef('body_template').content.cloneNode(true) const bodyTemplate = getRef('body_template').content.cloneNode(true)
const composedDocumentStructure = {} const composedDocumentStructure = formatSelectedContent()
floGlobals.appObjects[currentArticle.id].sections.forEach(section => composedDocumentStructure[section.id] = [])
selectedContent.forEach(({ content, sectionID }, uid) => {
composedDocumentStructure[sectionID].push({ content, uid })
})
for (const section in composedDocumentStructure) {
if (!composedDocumentStructure[section].length)
delete composedDocumentStructure[section]
}
let frag = document.createDocumentFragment() let frag = document.createDocumentFragment()
for (const section in composedDocumentStructure) { for (const section in composedDocumentStructure) {
@ -12461,8 +12459,7 @@
], animOptions).onfinish = e => e.target.cancel() ], animOptions).onfinish = e => e.target.cancel()
} }
}) })
function upvote(elem) { function animateLikeCount() {
if (isLoggedIn) {
const animOptions = { const animOptions = {
fill: 'forwards', fill: 'forwards',
duration: 150, duration: 150,
@ -12482,6 +12479,10 @@
getRef('like_count').textContent = totalVotes getRef('like_count').textContent = totalVotes
tempCount.remove() tempCount.remove()
} }
}
function upvote(elem) {
if (isLoggedIn) {
// animateLikeCount()
floCloudAPI.sendGeneralData({ floCloudAPI.sendGeneralData({
articleID: currentArticleID, articleID: currentArticleID,
}, `article_${currentArticleID}_votes`) }, `article_${currentArticleID}_votes`)
@ -12591,6 +12592,56 @@
} }
} }
</script> </script>
<script id="onLoadStartUp">
let isSubAdmin = false
let isLoggedIn = false
let totalVotes = 0
function onLoadStartUp() {
//floDapps.addStartUpFunction('Sample', Promised Function)
//floDapps.setAppObjectStores({sampleObs1:{}, sampleObs2:{options{autoIncrement:true, keyPath:'SampleKey'}, Indexes:{sampleIndex:{}}}})
floDapps.setMidStartup(() => new Promise(async (resolve, reject) => {
await floCloudAPI.requestObjectData('RMT')
await floCloudAPI.requestGeneralData(`article_${currentArticleID}_votes`, {
callback: (d, e) => {
animateLikeCount()
}
})
const allVotes = floGlobals.generalData[`article_${currentArticleID}_votes|${floGlobals.adminID}|${floGlobals.application}`]
for (const vote in allVotes) {
const { message: { articleID } } = allVotes[vote]
if (allVotes[vote].message.articleID === currentArticleID) {
totalVotes++
}
}
getRef('like_count').textContent = totalVotes
resolve(true)
}))
floDapps.setCustomPrivKeyInput(() => new Promise((resolve, reject) => {
getRef('sign_in_button').onclick = () => {
resolve(getRef('private_key_field').value.trim())
getRef('private_key_field').value = ''
hidePopup()
}
getRef('sign_up_button').onclick = () => {
resolve(getRef('generated_private_key').value.trim())
getRef('generated_private_key').value = ''
hidePopup()
}
}))
floDapps.launchStartUp().then(async result => {
isLoggedIn = true
isSubAdmin = floGlobals.subAdmins.includes(myFloID)
console.log(result)
// alert(`Welcome FLO_ID: ${ myFloID }`)
//App functions....
}).catch(error => console.error(error))
}
</script>
<script> <script>
const smButton = document.createElement('template') const smButton = document.createElement('template')
smButton.innerHTML = ` smButton.innerHTML = `
@ -13923,51 +13974,6 @@
}) })
</script> </script>
<script id="onLoadStartUp">
let isSubAdmin = false
let isLoggedIn = false
let totalVotes = 0
function onLoadStartUp() {
//floDapps.addStartUpFunction('Sample', Promised Function)
//floDapps.setAppObjectStores({sampleObs1:{}, sampleObs2:{options{autoIncrement:true, keyPath:'SampleKey'}, Indexes:{sampleIndex:{}}}})
floDapps.setMidStartup(() => new Promise(async (resolve, reject) => {
await floCloudAPI.requestObjectData('RMT')
await floCloudAPI.requestGeneralData(`article_${currentArticleID}_votes`)
const allVotes = floGlobals.generalData[`article_${currentArticleID}_votes|${floGlobals.adminID}|${floGlobals.application}`]
for (const vote in allVotes) {
const { message: { articleID } } = allVotes[vote]
if (allVotes[vote].message.articleID === currentArticleID) {
totalVotes++
}
}
getRef('like_count').textContent = totalVotes
resolve(true)
}))
floDapps.setCustomPrivKeyInput(() => new Promise((resolve, reject) => {
getRef('sign_in_button').onclick = () => {
resolve(getRef('private_key_field').value.trim())
getRef('private_key_field').value = ''
hidePopup()
}
getRef('sign_up_button').onclick = () => {
resolve(getRef('generated_private_key').value.trim())
getRef('generated_private_key').value = ''
hidePopup()
}
}))
floDapps.launchStartUp().then(async result => {
isLoggedIn = true
isSubAdmin = floGlobals.subAdmins.includes(myFloID)
console.log(result)
// alert(`Welcome FLO_ID: ${ myFloID }`)
//App functions....
}).catch(error => console.error(error))
}
</script>
</template> </template>
</body> </body>