Skip to content

Instantly share code, notes, and snippets.

@stefanoverna
Created June 19, 2018 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefanoverna/c39b5e443585496f47641fa11f974a88 to your computer and use it in GitHub Desktop.
Save stefanoverna/c39b5e443585496f47641fa11f974a88 to your computer and use it in GitHub Desktop.
Simply.js Pebble
var talks = [];
var currentIndex = 0;
function formatDate(template, date) {
var specs = 'YYYY:MM:DD:HH:mm:ss'.split(':');
date = new Date(date || Date.now() - new Date().getTimezoneOffset() * 6e4);
return date.toISOString().split(/[-:.TZ]/).reduce(function(template, item, i) {
return template.split(specs[i]).join(item);
}, template);
}
function load() {
currentIndex = 0;
simply.setText({
title: 'WMF 2018',
subtitle: 'Caricamento...',
body: '',
}, true);
ajax(
{
url: 'https://graphql.datocms.com/',
method: 'post',
headers: {
'Authorization': 'Bearer 26e925423e4c73b654ca25e4f8503c'
},
type: 'json',
data: {
query: 'query foo($now: DateTime!) { talks: allTalks(orderBy: time_ASC, first: 20, filter: { time: { gt: $now }}) { title room { name } time duration speakers { name } } }',
variables: {
now: new Date().toISOString(),
}
},
},
function(x) {
talks = x.data.talks;
renderTalk();
},
function(y) {
simply.body(y);
}
)
}
function renderTalk() {
var talk = talks[currentIndex];
simply.subtitle(talk.title.trim());
simply.body(
[
talk.speakers.map(function(s) { return s.name }).join(", "),
"Ore " + formatDate('HH:mm', Date.parse(talk.time)) + " (" + talk.duration + "min)",
"Stanza " + talk.room.name,
].filter(function(x) { return x }).join("\n")
);
}
simply.on('longClick', function(e) {
load();
});
simply.on('singleClick', function(e) {
if (e.button == 'select') {
currentIndex += 1;
if (currentIndex == talks.length) {
currentIndex = 0;
}
renderTalk();
}
});
simply.scrollable(true);
simply.style('small');
load();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment