Skip to content

Commit

Permalink
PR review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Barlow committed Dec 19, 2019
1 parent dd181e6 commit ee82bf1
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 27 deletions.
5 changes: 2 additions & 3 deletions app/appointment.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { readFileSync } from "fs";
import { dataFile, dataType } from "../common/constants";
import { toEpochSec } from "../common/utils";

let data = {};
let cb;
let data, cb;

export function initialize(callback) {
cb = callback;
Expand Down Expand Up @@ -59,7 +58,7 @@ function loadData() {
}

function existsData() {
if (Object.keys(data).length === 0 && data.constructor === Object) {
if (data === undefined) {
console.warn("Appointment: No data found.");
return false;
}
Expand Down
Binary file removed build/app.fba
Binary file not shown.
15 changes: 8 additions & 7 deletions common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,27 @@ export function timeUntil(date) {
);

if (days > 0) {
return `in ${days} day${pluralize(days)}`;
return `in ${days} ${pluralize(days, "day")}`;
}

if (hours > 0) {
return `in ${hours}hr${pluralize(hours)}${
hours < 3 && minutes > 0 ? ` ${minutes}min${pluralize(minutes)}` : ""
return `in ${hours}${pluralize(hours, "hr")}${
hours < 3 && minutes > 0 ? ` ${minutes}${pluralize(minutes, "min")}` : ""
}`;
}

if (minutes > 0) {
return `in ${minutes}min${pluralize(minutes)}`;
return `in ${minutes}${pluralize(minutes, "min")}`;
}

return "Now";
}

/**
* Returns an `s` if the number is plural
* Pluralizes the units if required
* @param {Number} number
* @param {String} unit
*/
function pluralize(number) {
return number === 1 ? "" : "s";
function pluralize(number, unit) {
return number === 1 ? unit : `${unit}s`;
}
23 changes: 6 additions & 17 deletions companion/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,20 @@ companion.addEventListener("wakeinterval", refreshData);
refreshData();

function refreshData() {
let dataCalendars = [],
dataEvents = [];
let dataEvents = [];

calendars
.searchSources()
.then(results => {
return calendars.searchCalendars();
})
.then(results => {
results.forEach(calendar => {
// console.log(
// `> calendar: ${calendar.title} (${calendar.sourceId}/${calendar.id})`
// );
dataCalendars.push(calendar);
});

// Filter events to 48hr window
const start = new Date();
const end = new Date();
start.setHours(0, 0, 0, 0);
end.setHours(128, 59, 59, 999);
const eventsQuery = {
startDate: start,
endDate: end
};
const startDate = new Date();
const endDate = new Date();
startDate.setHours(0, 0, 0, 0);
endDate.setHours(128, 59, 59, 999);
const eventsQuery = { startDate, endDate };

return calendars.searchEvents(eventsQuery);
})
Expand Down
Binary file modified screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ee82bf1

Please sign in to comment.