Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

core: group reminders by active/inactive

Abdullah Atta631142f852d7
diff --git a/packages/core/collections/reminders.js b/packages/core/collections/reminders.js
index 061868860..b5e02a5df 100644
--- a/packages/core/collections/reminders.js
+++ b/packages/core/collections/reminders.js
@@ -208,3 +208,15 @@ export function getUpcomingReminder(reminders) {
});
return sorted[0];
}
+
+/**
+ * @param {Reminder} reminder
+ */
+
+export function isReminderActive(reminder) {
+ const time = getUpcomingReminderTime(reminder);
+ return (
+ !reminder.disabled &&
+ (time > Date.now() || reminder.snoozeUntil > Date.now())
+ );
+}
diff --git a/packages/core/utils/grouping.js b/packages/core/utils/grouping.js
index ae93df9d1..c15ad170c 100644
--- a/packages/core/utils/grouping.js
+++ b/packages/core/utils/grouping.js
@@ -17,6 +17,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+import { isReminderActive } from "../collections/reminders";
import "../types";
import { getWeekGroupFromTimestamp, MONTHS_FULL } from "./date";
@@ -131,16 +132,26 @@ export function groupArray(
addToGroup(groups, groupTitle, item);
});
- let items = [];
- for (let [groupTitle, groupItems] of groups.entries()) {
- if (!groupItems.length) continue;
+ return flattenGroups(groups);
+}
- let group = { title: groupTitle, type: "header" };
- items.push(group);
- groupItems.forEach((item) => items.push(item));
- }
+/**
+ * @param {any[]} array
+ * @param {GroupOptions} options
+ * @returns Grouped array
+ */
+export function groupReminders(array) {
+ const groups = new Map([
+ ["Active", []],
+ ["Inactive", []]
+ ]);
- return items;
+ array.forEach((item) => {
+ const groupTitle = isReminderActive(item) ? "Active" : "Inactive";
+ addToGroup(groups, groupTitle, item);
+ });
+
+ return flattenGroups(groups);
}
function addToGroup(groups, groupTitle, item) {
@@ -154,3 +165,16 @@ function getFirstCharacter(str) {
if (!str) return "-";
return REGEX.exec(str)[0].toUpperCase();
}
+
+function flattenGroups(groups) {
+ let items = [];
+ for (let [groupTitle, groupItems] of groups.entries()) {
+ if (!groupItems.length) continue;
+
+ let group = { title: groupTitle, type: "header" };
+ items.push(group);
+ groupItems.forEach((item) => items.push(item));
+ }
+
+ return items;
+}