Skip to content

Commit

Permalink
fix potential erasure bug and clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
atude committed Jul 8, 2023
1 parent 5f31075 commit 971fb9f
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 78 deletions.
2 changes: 1 addition & 1 deletion public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
119 changes: 51 additions & 68 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
/*global chrome*/

/*
TODO
- Alarm functionality - schedule due dates for tasks
- More themes
MAINTENANCE
- Refactor -> abstract functions, components, etx
- Clean up styles, use scss or variables, remove unused styles
- 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';
Expand Down Expand Up @@ -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
}, []);

Expand Down Expand Up @@ -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(() => {
Expand Down
15 changes: 6 additions & 9 deletions src/utils/time.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}),
];

0 comments on commit 971fb9f

Please sign in to comment.