+
@@ -908,7 +908,7 @@
case 'dashboard':
targetPage = 'dashboard'
await Promise.all([
- floCloudAPI.requestObjectData('publishedVc'),
+ floCloudAPI.requestObjectData('admin'),
floCloudAPI.requestGeneralData('publishing_requests', {
callback: (d, e) => renderDashboard(d)
})
@@ -1050,17 +1050,17 @@
},
requestCard(details) {
const { message: { articleID, category, title }, time, vectorClock } = details
- if (!floGlobals.appObjects.publishedVc.hasOwnProperty(vectorClock)) {
+ if (!floGlobals.appObjects.adminData.publishedVc.hasOwnProperty(vectorClock)) {
const clone = getRef('request_template').content.cloneNode(true).firstElementChild
clone.dataset.vc = vectorClock
clone.querySelector('.request-card__title').textContent = title
clone.querySelector('.request-card__time').textContent = getFormattedTime(time)
- clone.querySelector('.publish-button').textContent = floGlobals.appObjects['articles'].hasOwnProperty(articleID) ? 'Update' : 'Publish'
+ clone.querySelector('.publish-button').textContent = floGlobals.appObjects.rmTimes.articles.hasOwnProperty(articleID) ? 'Update' : 'Publish'
return clone
}
},
articleRow(articleID) {
- const { category, title, published, votes } = floGlobals.appObjects.articles[articleID]
+ const { category, title, published, votes } = floGlobals.appObjects.rmTimes.articles[articleID]
const clone = getRef('article_row_template').content.cloneNode(true).firstElementChild
clone.querySelector('.article-card__title').textContent = title
clone.querySelector('.article-row__published').textContent = relativeTime.from(published)
@@ -1069,7 +1069,7 @@
return clone
},
writerCard(writerID) {
- const { name, bio } = floGlobals.appObjects.articleWriters[writerID]
+ const { name, bio } = floGlobals.appObjects.rmTimes.articleWriters[writerID]
const clone = getRef('article_writer_template').content.cloneNode(true).firstElementChild
clone.dataset.writerId = writerID
clone.querySelector('.writer-profile').textContent = name[0]
@@ -1082,9 +1082,8 @@
const getArticles = async () => {
await Promise.all([
- floCloudAPI.requestObjectData('articles'),
+ floCloudAPI.requestObjectData('rmTimes'),
floCloudAPI.requestObjectData('articlesContent'),
- floCloudAPI.requestObjectData('articleWriters'),
])
delete floGlobals.appObjects.articlesContent
showPage(window.location.hash, { firstLoad: true })
@@ -1104,15 +1103,36 @@
function renderHomepage() {
const frag = document.createDocumentFragment()
// Render article topics
- const categories = ['Art', 'Culture', 'Politics', 'Science', 'Tech']
- categories.forEach(category => frag.append(createElement('a', {
- textContent: category,
- attributes: { href: `#/explore?type=category&query=${category.toLowerCase()}` },
- className: 'category interact'
+ const categories = [
+ {
+ title: 'Art',
+ icon: `
`
+ },
+ {
+ title: 'Culture',
+ icon: `
`
+ },
+ {
+ title: 'Politics',
+ icon: `
`
+ },
+ {
+ title: 'Science',
+ icon: `
`
+ },
+ {
+ title: 'Tech',
+ icon: `
`
+ }
+ ]
+ categories.forEach(({ title, icon }) => frag.append(createElement('a', {
+ attributes: { href: `#/explore?type=category&query=${title.toLowerCase()}` },
+ className: 'category interact',
+ innerHTML: `${icon}
${title}`,
})))
getRef('news_categories_list').innerHTML = ''
getRef('news_categories_list').append(frag)
- const arrOfArticles = getArrayOfObj(floGlobals.appObjects.articles)
+ const arrOfArticles = getArrayOfObj(floGlobals.appObjects.rmTimes.articles)
// Render trending article card
let sortedByVotes = arrOfArticles.sort((a, b) => b.votes - a.votes)
sortedByVotes.slice(0, 3).forEach(articleDetail => frag.append(render.trendingArticleCard(articleDetail)))
@@ -1128,7 +1148,7 @@
const openedArticles = {}
async function renderArticle(articleID, firstLoad = true) {
const allArticles = await compactIDB.readData('appObjects', 'articlesContent')
- const { title, published, readTime, contributors } = floGlobals.appObjects.articles[articleID]
+ const { title, published, readTime, contributors } = floGlobals.appObjects.rmTimes.articles[articleID]
getRef('article_title').textContent = title
getRef('published_time').textContent = getFormattedTime(published, 'date-only')
getRef('reading_time').textContent = `${readTime} Min read`
@@ -1136,24 +1156,24 @@
const frag = document.createDocumentFragment()
contributors.forEach(id => {
frag.append(createElement('a', {
- textContent: floGlobals.appObjects.articleWriters.hasOwnProperty(id) ? floGlobals.appObjects.articleWriters[id].name : id,
+ textContent: floGlobals.appObjects.rmTimes.articleWriters.hasOwnProperty(id) ? floGlobals.appObjects.rmTimes.articleWriters[id].name : id,
className: 'contributor',
attributes: { 'href': `#/writer?id=${id}` }
}))
})
getRef('article_contributors').innerHTML = ''
getRef('article_contributors').append(frag)
- getRef('like_count').textContent = floGlobals.appObjects.articles[articleID].votes
+ getRef('like_count').textContent = floGlobals.appObjects.rmTimes.articles[articleID].votes
// implement live voting
if (!openedArticles.hasOwnProperty(articleID)) {
floCloudAPI.requestGeneralData(`article_${articleID}_votes`, {
- lowerVectorClock: floGlobals.appObjects.articles[articleID].lastCountedVC + 1,
+ lowerVectorClock: floGlobals.appObjects.rmTimes.articles[articleID].lastCountedVC + 1,
callback: (allVotes, e) => {
if (firstLoad) {
for (const vote in allVotes) {
- floGlobals.appObjects.articles[articleID].votes += allVotes[vote].message.voteCount || 1
+ floGlobals.appObjects.rmTimes.articles[articleID].votes += allVotes[vote].message.voteCount || 1
}
- getRef('like_count').textContent = floGlobals.appObjects.articles[articleID].votes
+ getRef('like_count').textContent = floGlobals.appObjects.rmTimes.articles[articleID].votes
} else {
for (const msg in allVotes) {
animateLikeCount(allVotes[msg].message.voteCount, articleID)
@@ -1164,14 +1184,14 @@
})
openedArticles[articleID] = true
} else {
- getRef('like_count').textContent = floGlobals.appObjects.articles[articleID].votes
+ getRef('like_count').textContent = floGlobals.appObjects.rmTimes.articles[articleID].votes
}
}
function renderExplorePage(params) {
const { type, query } = params
const frag = document.createDocumentFragment()
- const sortedByTime = getArrayOfObj(floGlobals.appObjects.articles).sort((a, b) => b.published - a.published)
+ const sortedByTime = getArrayOfObj(floGlobals.appObjects.rmTimes.articles).sort((a, b) => b.published - a.published)
if (type === 'recent') {
sortedByTime.forEach(articleDetail => frag.append(render.articleCard(articleDetail)))
} else {
@@ -1185,8 +1205,8 @@
getRef('query_results_list').append(frag)
}
function renderWriterPage(params) {
- if (floGlobals.appObjects.articleWriters.hasOwnProperty(params.id)) {
- const { name, bio } = floGlobals.appObjects.articleWriters[params.id]
+ if (floGlobals.appObjects.rmTimes.articleWriters.hasOwnProperty(params.id)) {
+ const { name, bio } = floGlobals.appObjects.rmTimes.articleWriters[params.id]
getRef('writer_initials').textContent = name[0]
getRef('writer_name').textContent = name
getRef('writer_bio').textContent = bio
@@ -1197,7 +1217,7 @@
}
getRef('writer_id').value = params.id
const frag = document.createDocumentFragment()
- const sortedByTime = getArrayOfObj(floGlobals.appObjects.articles).sort((a, b) => b.published - a.published)
+ const sortedByTime = getArrayOfObj(floGlobals.appObjects.rmTimes.articles).sort((a, b) => b.published - a.published)
const options = { keys: ['contributors'], threshold: 0 }
const fuse = new Fuse(sortedByTime, options)
const searchResult = fuse.search(params.id).map(v => v.item)
@@ -1271,7 +1291,7 @@
keys: ['title', 'tags', 'category'],
threshold: 0.3
}
- const fuse = new Fuse(getArrayOfObj(floGlobals.appObjects.articles).sort((a, b) => b.published - a.published), options)
+ const fuse = new Fuse(getArrayOfObj(floGlobals.appObjects.rmTimes.articles).sort((a, b) => b.published - a.published), options)
const searchResult = fuse.search(searchKey).map(v => v.item)
getRef('search_suggestions').innerHTML = ''
if (searchResult.length) {
@@ -1420,18 +1440,18 @@
duration: 150,
ease: 'easing',
}
- floGlobals.appObjects.articles[articleID].votes += voteCount
+ floGlobals.appObjects.rmTimes.articles[articleID].votes += voteCount
getRef('like_count').animate(slideOutUp, animOptions)
.onfinish = (e) => {
e.target.cancel()
}
const tempCount = document.createElement('div')
tempCount.classList.add('temp-count')
- tempCount.textContent = floGlobals.appObjects.articles[articleID].votes
+ tempCount.textContent = floGlobals.appObjects.rmTimes.articles[articleID].votes
getRef('like_count').after(tempCount)
tempCount.animate(slideInUp, animOptions)
.onfinish = () => {
- getRef('like_count').textContent = floGlobals.appObjects.articles[articleID].votes
+ getRef('like_count').textContent = floGlobals.appObjects.rmTimes.articles[articleID].votes
tempCount.remove()
}
}
@@ -1539,18 +1559,18 @@
if (card)
frag.prepend(card)
}
- floCloudAPI.updateObjectData('publishedVc')
+ floCloudAPI.updateObjectData('adminData')
getRef('publishing_requests').innerHTML = ''
getRef('publishing_requests').append(frag)
- for (const articleKey in floGlobals.appObjects.articles) {
+ for (const articleKey in floGlobals.appObjects.rmTimes.articles) {
const card = render.articleRow(articleKey)
frag.prepend(card)
}
getRef('article_analytics').innerHTML = ''
getRef('article_analytics').append(frag)
- for (const articleKey in floGlobals.appObjects.articleWriters) {
+ for (const articleKey in floGlobals.appObjects.rmTimes.articleWriters) {
const card = render.writerCard(articleKey)
frag.prepend(card)
}
@@ -1560,33 +1580,32 @@
function publishArticle(vc) {
const { message: { articleID, content, contributors, title, readTime }, vectorClock } = floGlobals.generalData[`publishing_requests|${floGlobals.adminID}|${floGlobals.application}`][vc];
- const isPublished = floGlobals.appObjects['articles'].hasOwnProperty(articleID)
+ const isPublished = floGlobals.appObjects.rmTimes.articles.hasOwnProperty(articleID)
getConfirmation(`${isPublished ? 'Update' : 'Publish'} article?`).then(res => {
if (res) {
const { title, category, summary, published, tags, contributors } = getArticleMetaData()
- floGlobals.appObjects['publishedVc'][vectorClock] = true
+ floGlobals.appObjects.adminData.publishedVc[vectorClock] = true
floGlobals.appObjects.articlesContent[articleID] = content
if (isPublished) {
- floGlobals.appObjects['articles'][articleID]['updated'] = Date.now();
+ floGlobals.appObjects.rmTimes.articles[articleID]['updated'] = Date.now();
} else {
- floGlobals.appObjects.articles[articleID] = {
+ floGlobals.appObjects.rmTimes.articles[articleID] = {
published: Date.now(),
votes: 0,
lastCountedVC: ''
}
- floGlobals.appObjects.articleVotes[articleID] = { votes: {} }
+ floGlobals.appObjects.adminData.articleVotes[articleID] = { votes: {} }
}
- floGlobals.appObjects['articles'][articleID].category = category
- floGlobals.appObjects['articles'][articleID].contributors = contributors
- floGlobals.appObjects['articles'][articleID].title = title
- floGlobals.appObjects['articles'][articleID].tags = tags
- floGlobals.appObjects['articles'][articleID].readTime = readTime
- floGlobals.appObjects['articles'][articleID].summary = summary
+ floGlobals.appObjects.rmTimes.articles[articleID].category = category
+ floGlobals.appObjects.rmTimes.articles[articleID].contributors = contributors
+ floGlobals.appObjects.rmTimes.articles[articleID].title = title
+ floGlobals.appObjects.rmTimes.articles[articleID].tags = tags
+ floGlobals.appObjects.rmTimes.articles[articleID].readTime = readTime
+ floGlobals.appObjects.rmTimes.articles[articleID].summary = summary
Promise.all([
- floCloudAPI.updateObjectData('articles'),
- floCloudAPI.updateObjectData('publishedVc'),
+ floCloudAPI.updateObjectData('rmTimes'),
+ floCloudAPI.updateObjectData('adminData'),
floCloudAPI.updateObjectData('articlesContent'),
- floCloudAPI.updateObjectData('articleVotes'),
]).then(() => {
notify(`${isPublished ? 'Updated' : 'Published'} article`, 'success')
document.querySelector(`.request-card[data-vc="${vc}"]`).remove()
@@ -1601,9 +1620,9 @@
const button = e.target.closest('.publish-button');
const vc = button.closest('.request-card').dataset.vc;
const { message: { articleID, title, contributors } } = floGlobals.generalData[`publishing_requests|${floGlobals.adminID}|${floGlobals.application}`][vc]
- const isPublished = floGlobals.appObjects['articles'].hasOwnProperty(articleID)
+ const isPublished = floGlobals.appObjects.rmTimes.articles.hasOwnProperty(articleID)
if (isPublished)
- setArticleMetaData(floGlobals.appObjects.articles[articleID])
+ setArticleMetaData(floGlobals.appObjects.rmTimes.articles[articleID])
else
setArticleMetaData({ title, contributors })
floGlobals.subAdminData = {
@@ -1651,7 +1670,7 @@
if (e.target.closest('.edit-article')) {
const button = e.target.closest('.edit-article');
const articleID = button.dataset.articleId;
- setArticleMetaData(floGlobals.appObjects.articles[articleID])
+ setArticleMetaData(floGlobals.appObjects.rmTimes.articles[articleID])
floGlobals.subAdminData = {
actionType: 'analytics',
articleID,
@@ -1666,14 +1685,14 @@
getConfirmation('Update article meta data?').then(res => {
if (res) {
const { title, category, summary, published, tags, contributors } = getArticleMetaData()
- floGlobals.appObjects['articles'][articleID].category = category
- floGlobals.appObjects['articles'][articleID].title = title
- floGlobals.appObjects['articles'][articleID].tags = tags
- floGlobals.appObjects['articles'][articleID].summary = summary
- floGlobals.appObjects['articles'][articleID].contributors = contributors
+ floGlobals.appObjects.rmTimes.articles[articleID].category = category
+ floGlobals.appObjects.rmTimes.articles[articleID].title = title
+ floGlobals.appObjects.rmTimes.articles[articleID].tags = tags
+ floGlobals.appObjects.rmTimes.articles[articleID].summary = summary
+ floGlobals.appObjects.rmTimes.articles[articleID].contributors = contributors
Promise.all([
- floCloudAPI.updateObjectData('articles'),
- floCloudAPI.updateObjectData('publishedVc'),
+ floCloudAPI.updateObjectData('rmTimes'),
+ floCloudAPI.updateObjectData('adminData'),
]).then(() => {
notify(`Updated article meta data`, 'success')
hidePopup()
@@ -1691,14 +1710,14 @@
}
async function calculateVotes() {
- await floCloudAPI.requestObjectData('articleVotes')
+ await floCloudAPI.requestObjectData('adminData')
const articlesVotesProm = []
const articleIDs = []
- for (const articleKey in floGlobals.appObjects.articles) {
- if (floGlobals.appObjects.articleVotes.hasOwnProperty(articleKey) && floGlobals.appObjects.articles[articleKey].lastCountedVC !== '') {
+ for (const articleKey in floGlobals.appObjects.rmTimes.articles) {
+ if (floGlobals.appObjects.adminData.articleVotes.hasOwnProperty(articleKey) && floGlobals.appObjects.rmTimes.articles[articleKey].lastCountedVC !== '') {
articlesVotesProm.push(
floCloudAPI.requestGeneralData(`article_${articleKey}_votes`, {
- lowerVectorClock: floGlobals.appObjects.articles[articleKey].lastCountedVC + 1
+ lowerVectorClock: floGlobals.appObjects.rmTimes.articles[articleKey].lastCountedVC + 1
})
)
} else {
@@ -1710,31 +1729,31 @@
}
Promise.all(articlesVotesProm).then(res => {
res.forEach((articleVotes, index) => {
- if (!floGlobals.appObjects.articleVotes.hasOwnProperty(articleIDs[index])) {
- floGlobals.appObjects.articleVotes[articleIDs[index]].votes = {}
+ if (!floGlobals.appObjects.adminData.articleVotes.hasOwnProperty(articleIDs[index])) {
+ floGlobals.appObjects.adminData.articleVotes[articleIDs[index]].votes = {}
}
- if (floGlobals.appObjects.articles[articleIDs[index]].lastCountedVC === '') {
+ if (floGlobals.appObjects.rmTimes.articles[articleIDs[index]].lastCountedVC === '') {
articleVotes = floGlobals.generalData[`article_${articleIDs[index]}_votes|${floGlobals.adminID}|${floGlobals.application}`]
}
for (const voteKey in articleVotes) {
const { senderID, message: { voteCount }, type, vectorClock, time } = articleVotes[voteKey]
- const { votes } = floGlobals.appObjects.articleVotes[articleIDs[index]];
+ const { votes } = floGlobals.appObjects.adminData.articleVotes[articleIDs[index]];
if (votes[senderID]) {
- floGlobals.appObjects.articleVotes[articleIDs[index]].votes[senderID] += voteCount || 1
+ floGlobals.appObjects.adminData.articleVotes[articleIDs[index]].votes[senderID] += voteCount || 1
} else {
- floGlobals.appObjects.articleVotes[articleIDs[index]].votes[senderID] = voteCount || 1
+ floGlobals.appObjects.adminData.articleVotes[articleIDs[index]].votes[senderID] = voteCount || 1
}
- floGlobals.appObjects.articles[articleIDs[index]].lastCountedVC = vectorClock
+ floGlobals.appObjects.rmTimes.articles[articleIDs[index]].lastCountedVC = vectorClock
}
let totalArticleVotes = 0
- for (const voter in floGlobals.appObjects.articleVotes[articleIDs[index]].votes) {
- totalArticleVotes += floGlobals.appObjects.articleVotes[articleIDs[index]].votes[voter]
+ for (const voter in floGlobals.appObjects.adminData.articleVotes[articleIDs[index]].votes) {
+ totalArticleVotes += floGlobals.appObjects.adminData.articleVotes[articleIDs[index]].votes[voter]
}
- floGlobals.appObjects.articles[articleIDs[index]].votes = totalArticleVotes
+ floGlobals.appObjects.rmTimes.articles[articleIDs[index]].votes = totalArticleVotes
})
Promise.all([
- floCloudAPI.updateObjectData('articles'),
- floCloudAPI.updateObjectData('articleVotes')
+ floCloudAPI.updateObjectData('rmTimes'),
+ floCloudAPI.updateObjectData('adminData')
])
.then(() => {
console.log('calculated votes')
@@ -1750,7 +1769,7 @@
function setWriterDetails(writerID) {
console.log(writerID)
- const { name, bio } = floGlobals.appObjects.articleWriters[writerID]
+ const { name, bio } = floGlobals.appObjects.rmTimes.articleWriters[writerID]
getRef('get_writer_id').value = writerID
getRef('get_writer_name').value = name
getRef('get_writer_bio').value = bio
@@ -1786,9 +1805,9 @@
const writerID = button.closest('.writer-card').dataset.writerId;
getConfirmation('Delete this writer?').then(res => {
if (res) {
- delete floGlobals.appObjects.articleWriters[writerID]
+ delete floGlobals.appObjects.rmTimes.articleWriters[writerID]
button.closest('.writer-card').remove()
- floCloudAPI.updateObjectData('articleWriters').then(() => {
+ floCloudAPI.updateObjectData('rmTimes').then(() => {
notify('Writer deleted', 'success')
}).catch(error => console.error(error))
}
@@ -1798,17 +1817,17 @@
function saveWriter() {
const { floID, name, bio } = getWriterDetails()
- if (floGlobals.appObjects.articleWriters.hasOwnProperty(floID)) {
- const { name: oldName, bio: oldBio } = floGlobals.appObjects.articleWriters[floID]
+ if (floGlobals.appObjects.rmTimes.articleWriters.hasOwnProperty(floID)) {
+ const { name: oldName, bio: oldBio } = floGlobals.appObjects.rmTimes.articleWriters[floID]
if (name !== oldName || bio !== oldBio) {
- floGlobals.appObjects.articleWriters[floID].name = name
- floGlobals.appObjects.articleWriters[floID].bio = bio
+ floGlobals.appObjects.rmTimes.articleWriters[floID].name = name
+ floGlobals.appObjects.rmTimes.articleWriters[floID].bio = bio
const writerCard = getRef('writers_list').querySelector(`.writer-card[data-writer-id="${floID}"]`)
if (writerCard) {
writerCard.querySelector('.writer-name').textContent = name
writerCard.querySelector('.writer-bio').textContent = bio
}
- floCloudAPI.updateObjectData('articleWriters').then(() => {
+ floCloudAPI.updateObjectData('rmTimes').then(() => {
notify('Writer details updated', 'success')
hidePopup()
}).catch(error => console.error(error))
@@ -1816,8 +1835,8 @@
notify('Details are not changed', 'error')
}
} else {
- floGlobals.appObjects.articleWriters[floID] = { name, bio }
- floCloudAPI.updateObjectData('articleWriters').then(() => {
+ floGlobals.appObjects.rmTimes.articleWriters[floID] = { name, bio }
+ floCloudAPI.updateObjectData('rmTimes').then(() => {
getRef('writers_list').append(render.writerCard(floID))
notify('Added writer details', 'success')
hidePopup()