diff --git a/public/manifest.json b/public/manifest.json index 6788103b..19201ec7 100755 --- a/public/manifest.json +++ b/public/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 3, "name": "Kanbie", "description": "Kanban board from any tab.", - "version": "2.0.8", + "version": "2.1.0", "action": { "default_popup": "index.html" }, diff --git a/src/App.js b/src/App.js index eab685d9..cb391243 100755 --- a/src/App.js +++ b/src/App.js @@ -1,12 +1,6 @@ /*global chrome*/ /* - - TODO - - - Alarm functionality - schedule due dates for tasks - - More themes - MAINTENANCE - Refactor -> abstract functions, components, etx @@ -14,7 +8,6 @@ - Fix up mutations -> make sure functions are not mutating/using ref instead of copy - Use reducers to clean up logic - Convert to TS - */ import React, { useState, useEffect } from 'react'; @@ -69,53 +62,41 @@ function App() { // Load data useEffect(() => { - let getColumns; - let getLabels; - let getSettings; - let getAlarms; - - try { - chrome.storage.sync.get("columns", (data) => { - if (!chrome.runtime.error) { - getColumns = data.columns; - } - if (getColumns && getColumns !== "undefined") { - setColumns(getColumns); - } - }); - - chrome.storage.sync.get("labels", (data) => { - if (!chrome.runtime.error) { - getLabels = data.labels; - } - if (getLabels && getLabels !== "undefined") { - setLabels(getLabels); - } - }); - - chrome.storage.sync.get("settings", (data) => { - if (!chrome.runtime.error) { - getSettings = data.settings; - } - if (getSettings && getSettings !== "undefined") { - setSettings(getSettings); - } - }); + const initLoad = async () => { + try { + const getColumns = await chrome.storage.sync.get("columns"); + const getLabels = await chrome.storage.sync.get("labels"); + const getSettings = await chrome.storage.sync.get("settings"); + const getAlarms = await chrome.storage.sync.get("alarms"); + + if (chrome.runtime.error) { + throw Error("runtime error"); + } - chrome.storage.sync.get("alarms", (data) => { - if (!chrome.runtime.error) { - getAlarms = data.alarms; - } - if (getAlarms && getAlarms !== "undefined") { - setAlarms(getAlarms); - } - }); + if (getColumns.columns && getColumns.columns !== "undefined") { + setColumns(getColumns.columns); + } + + if (getLabels.labels && getLabels.labels !== "undefined") { + setLabels(getLabels.labels); + } + + if (getSettings.settings && getSettings.settings !== "undefined") { + setSettings(getSettings.settings); + } + + if (getAlarms.alarms && getAlarms.alarms !== "undefined") { + setAlarms(getAlarms.alarms); + } + + setLoaded(true); + } catch (error) { + console.warn("Error syncing with chrome API. Are you using this as a webapp?"); + setLoaded(true); + } + } - setLoaded(true); - } catch (error) { - console.warn("Error syncing with chrome API. Are you using this as a webapp?"); - setLoaded(true); - } + initLoad(); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); @@ -144,22 +125,24 @@ function App() { }, [settings]); useEffect(() => { - // console.log(columns); - // Pull items - try { - chrome.storage.sync.set({ - "columns": columns, - "labels": labels, - "settings": settings, - "alarms": alarms, - }, () => { - if (chrome.runtime.error) { - console.warn("Runtime error. Failed to save data"); - } - }); - } catch (error) { - console.warn("Error syncing storage with chrome extensions."); - } + // Pull items. Only pull if initial load succeeded to prevent bad overrides. + if (loaded) { + try { + chrome.storage.sync.set({ + "columns": columns, + "labels": labels, + "settings": settings, + "alarms": alarms, + }, () => { + if (chrome.runtime.error) { + console.warn("Runtime error. Failed to save data"); + } + }); + } catch (error) { + console.warn("Error syncing storage with chrome extensions."); + } + } + // eslint-disable-next-line react-hooks/exhaustive-deps }, [columns, labels, settings, alarms]); useEffect(() => { diff --git a/src/utils/time.js b/src/utils/time.js index 8f9a4489..d05775b9 100644 --- a/src/utils/time.js +++ b/src/utils/time.js @@ -38,16 +38,13 @@ export const allDays = [ { id: `__DATE: ${moment().add(1, 'days').format("DD/MM/YYYY")}`, display: "Tomorrow" }, ...[...Array(12).keys()].map((i) => { const dayDate = moment().add(2 + i, 'days'); - if (i < 5) { - return { - id: `__DATE: ${dayDate.format("DD/MM/YYYY")}`, - display: `${dayDate.format("dddd")} ${dayDate.format("DD/MM")}`, - } - } + const formattedDate = dayDate.format("DD/MM/YYYY"); + const amPm = dayDate.format("DD/MM"); + const formattedDisplay = `${i < 5 ? '' : 'Next '}${dayDate.format("dddd")} ${amPm}`; return { - id: `__DATE: ${dayDate.format("DD/MM/YYYY")}`, - display: `Next ${dayDate.format("dddd")} ${dayDate.format("DD/MM")}`, - } + id: `__DATE: ${formattedDate}`, + display: formattedDisplay, + }; }), ];