Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
npbreland committed Jan 16, 2024
1 parent d8d9f10 commit e9c0a63
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
9 changes: 5 additions & 4 deletions apps/habitbuilder/interface.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ <h2>Data</h2>
<div id="data"></div>
<button class="btn btn-default" id="btnSave">Save</button>
<button class="btn btn-default" id="btnDelete">Delete</button>
<h2>Settings</h2>
<h2 style="margin-top: 20px">Settings</h2>
<div id="settings"></div>
<button class="btn btn-primary" id="btnSaveSettings">Save settings</button>

Expand Down Expand Up @@ -76,17 +76,18 @@ <h2>Settings</h2>
});
}


// You can call a utility function to save the data
document.getElementById("btnSave").addEventListener("click", function() {
Util.saveCSV("habitbuilder", csvData);
Util.readStorageFile('habitbuilder.data.csv',data=>{
csvData = data.trim();
Util.saveCSV("habitbuilder", csvData);
});
});
// Or you can also delete the file
document.getElementById("btnDelete").addEventListener("click", function() {
Util.showModal("Deleting...");
Util.eraseStorageFile("habitbuilder.data.csv", function() {
Util.hideModal();
getData();
});
});
// Called when app starts
Expand Down
10 changes: 9 additions & 1 deletion apps/habitbuilder/settings-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ function buildSettingsForm(questions = [], reminderTime = "") {
settingsHtml += questionComponent(question, i);
}

settingsHtml += `<p>Reminder time <input type="time" id="remindertime" class="form-input" value="${reminderTime}"></p>`;
const time = getTimeFromMs(reminderTime);

settingsHtml += `<p>Reminder time <input type="time" id="remindertime" class="form-input" value="${time}"></p>`;
return settingsHtml;
}

Expand Down Expand Up @@ -39,3 +41,9 @@ function getMsFromMidnight(timeStr) {
const [hours, minutes] = timeStr.split(":");
return hours * 60 * 60 * 1000 + minutes * 60 * 1000;
}

function getTimeFromMs(ms) {
const hours = Math.floor(ms / (60 * 60 * 1000));
const minutes = Math.floor((ms % (60 * 60 * 1000)) / (60 * 1000));
return `${hours}:${minutes}`;
}

0 comments on commit e9c0a63

Please sign in to comment.