Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
showResults() {
getObjects({ bucket: config.cosmicjs.bucket }, (err, res) => {
this.is_saving = false
this.poll.vote_counted = true
if (res.objects) {
const votes = res.objects.type.votes
this.votes = votes
this.show_results = true
// Redo totals
let polls = res.objects.type.polls
polls = this.getVoteTotals(polls, votes)
const poll_index = _.findIndex(this.polls, { _id: this.poll._id })
polls[poll_index].vote_counted = true
this.polls = polls
}
})
}
getVoteTotals(polls, votes) {
componentDidMount() {
let data = this.state.data
setTimeout(() => {
this.refs.author.refs.input.focus()
}, 100)
const socket = io()
Cosmic.getObjects(config, (err, res) => {
const messages = res.objects.type.messages
if (messages) {
messages.reverse()
this.setState({
data: {
author: data.author,
messages
}
})
}
})
// Listen for messages coming in
socket.on('chat message', message => {
data = this.state.data
const messages = this.state.data.messages
if (data.author !== message.metafield.author.value) {
constructor() {
// Get all polls and votes
getObjects({ bucket: config.cosmicjs.bucket }, (err, res) => {
if (res.objects) {
let polls = res.objects.type.polls
const votes = res.objects.type.votes
polls = this.getVoteTotals(polls, votes)
// If already voted
polls.forEach((poll, i) => {
if (window.localStorage.getItem(polls[i]._id)) {
this.options_selected.push({ poll: polls[i]._id, value: window.localStorage.getItem(polls[i]._id) })
polls[i].vote_counted = true
}
})
this.polls = polls
this.votes = votes
const slug = window.location.pathname.replace('/', '')
if (slug) {
const poll = _.find(res.objects.type.polls, { slug })
export function getStore(callback){
let pages = {}
Cosmic.getObjects(config, function(err, response){
let objects = response.objects
/* Globals
======================== */
let globals = AppStore.data.globals
globals.text = response.object['text']
let metafields = globals.text.metafields
let menu_title = _.find(metafields, { key: 'menu-title' })
globals.text.menu_title = menu_title.value
let footer_text = _.find(metafields, { key: 'footer-text' })
globals.text.footer_text = footer_text.value
let site_title = _.find(metafields, { key: 'site-title' })
globals.text.site_title = site_title.value
init: function(payload) {
let _this = this;
let pages = {};
_this.data.ready = false;
_this.data.pages = [];
Cosmic.getObjects(config, function(err, response){
let objects = response.objects;
/* Globals
======================== */
let globals = _this.data.globals;
globals.text = response.object['text'];
let metafields = globals.text.metafields;
let menu_title = _.findWhere(metafields, { key: 'menu-title' });
globals.text.menu_title = menu_title.value;
let footer_text = _.findWhere(metafields, { key: 'footer-text' });
globals.text.footer_text = footer_text.value;
let site_title = _.findWhere(metafields, { key: 'site-title' });
globals.text.site_title = site_title.value;
init: function(items){
let _this = this;
Cosmic.getObjects(config, function(err, response){
let items = response.objects.type['list-items'];
items = _.sortBy(items, 'order');
_this.items = items;
_this.emitChange();
});
},