diff --git a/home.js b/home.js index 79f8fe6..fad0363 100644 --- a/home.js +++ b/home.js @@ -74,6 +74,12 @@ document.addEventListener('DOMContentLoaded', async () => { // Initialize storage - this loads groups, everything else await loadStorage(); + // Pull data from each tab about which group they belong to + await initializeGroupData(); + + // Data loaded, start building UI + await populateUI(); + // New group click handler document.querySelector('.newgroup').addEventListener('click', async () => { await newGroup(); @@ -81,16 +87,17 @@ document.addEventListener('DOMContentLoaded', async () => { }); const loadStorage = async () => { - + // get data from local storage const data = await api.storage.local.get(EXT_DATA_CONFIG_KEY); console.log('storage', data); // Not first run! if (data.config) { + console.log('not first run'); config = data.config; } + // First run! else { - // First run! console.log('first run'); config = {}; @@ -99,7 +106,7 @@ const loadStorage = async () => { config.groups = {}; // Create default group - var id = await newGroup(DEFAULT_GROUP_TITLE); + const id = await newGroup(DEFAULT_GROUP_TITLE); // Storage default group id as last active group config.lastGroupId = id; @@ -107,12 +114,6 @@ const loadStorage = async () => { // await updateStorage(); } - - // Pull data from each tab about which group they belong to - initializeGroupData().then(function() { - // Data loaded, start building UI - populateUI(); - }); } // Save changes to config to persistent storage @@ -125,15 +126,15 @@ const updateStorage = async () => { } // On DOM -function populateUI() { +const populateUI = async () => { // Populate groups with their tabs - initializeGroupData().then(function() { - showTabs(); - }); + await initializeGroupData() + + showGroups(); // Listen for things that'll change our state initTabEventListeners(); -} +}; function initTabEventListeners() { // add new tabs in this window to current group @@ -257,6 +258,7 @@ function showGroups() { for (let id in config.groups) { var group = config.groups[id]; var card = addCard(); + console.log('GROUP', group.title); card.querySelector('h1').innerText = group.title; card.dataset.id = group.id; card.addEventListener('click', e => {