From dbb542dd885d1c725e1aa0fe9627fb37ca6946be Mon Sep 17 00:00:00 2001
From: dsoloha <38593903+dsoloha@users.noreply.github.com>
Date: Mon, 13 Jan 2020 00:06:21 -0500
Subject: [PATCH] Finishing touches, converted reminders widget into JS

---
 src/002-config/fc-js-init.js                |  1 +
 src/Mods/Reminder/reminder.js               |  7 ++++++
 src/pregmod/managePersonalAffairs.tw        | 26 +++++++--------------
 src/uncategorized/BackwardsCompatibility.tw | 12 ++++------
 4 files changed, 21 insertions(+), 25 deletions(-)
 create mode 100644 src/Mods/Reminder/reminder.js

diff --git a/src/002-config/fc-js-init.js b/src/002-config/fc-js-init.js
index ff16bb6b663..3c923124687 100644
--- a/src/002-config/fc-js-init.js
+++ b/src/002-config/fc-js-init.js
@@ -43,6 +43,7 @@ App.RA = {};
 App.SF = {};
 App.Corporate = {};
 App.SecExp = {};
+App.Reminders = {};
 
 
 Object.defineProperty(App, "activeSlave", {
diff --git a/src/Mods/Reminder/reminder.js b/src/Mods/Reminder/reminder.js
new file mode 100644
index 00000000000..5954e3413d1
--- /dev/null
+++ b/src/Mods/Reminder/reminder.js
@@ -0,0 +1,7 @@
+App.Reminders.add = function(entry, week) {
+    if (entry.length > 0 && week.length > 0 && !isNaN(week)) {
+        V.reminders.entries.push(entry);
+        V.reminders.weeks.push(week);
+        V.reminders.text.push(`${entry} in ${numberWithPlural(week, 'week')}`);
+    }
+};
diff --git a/src/pregmod/managePersonalAffairs.tw b/src/pregmod/managePersonalAffairs.tw
index de50d0a9a63..c11c5bfffc2 100644
--- a/src/pregmod/managePersonalAffairs.tw
+++ b/src/pregmod/managePersonalAffairs.tw
@@ -218,11 +218,11 @@ Sclera:
 
 <br><br>
 
-<<if $reminders.length == 0>>
+<<if $reminders.text.length == 0>>
 	You do not have any reminders set.
 <<else>>
-	You have $reminders.length reminders set:
-	<<print $reminders>>
+	You have <<=numberWithPlural($reminders.text.length, "reminder")>> set:
+	<<print $reminders.text>>
 <</if>>
 <br>
 Remind me
@@ -230,23 +230,13 @@ Remind me
 in
 <<textbox "$reminderWeek" "">>
 weeks.
-<<link "Add" "Manage Personal Affairs">>
-	<<if $reminderEntry.length > 0 && $reminderWeek.length > 0>>
-		<<set $reminderWeek = parseInt($reminderWeek)>>
-		<<set $reminderEntries.push($reminderEntry), $reminderWeeks.push($reminderWeek)>>
-		<<run $reminders.push(`${$reminderEntry} in ${$reminderWeek} ${$reminderWeek == 1 ? 'week' : 'weeks'}`)>>
-	<</if>>
-<</link>>
+[[Add|Manage Personal Affairs][App.Reminders.add($reminderEntry, $reminderWeek)]]
 <br>
-<<if $reminders.length > 0 || $cheatMode || $debugMode>>
-	<<link "Clear your reminders" "Manage Personal Affairs">>
-		<<set $reminders = [], $reminderEntries = [], $reminderWeeks = []>>
-	<</link>>/* |
-	TODO:
-	<<link "Clear a reminder" "Manage Personal Affairs">>
+<<if $reminders.text.length > 0 || $cheatMode || $debugMode>>
+	[[Clear your reminders|Manage Personal Affairs][$reminders = {entries: [], weeks: [], text: []}]]
+	/* TODO: <<link "Clear a reminder" "Manage Personal Affairs">>
 		<<include "Clear Reminder">>
-	<</link>>
-	*/
+	<</link>> */
 <</if>>
 
 <br><br>
diff --git a/src/uncategorized/BackwardsCompatibility.tw b/src/uncategorized/BackwardsCompatibility.tw
index fb72f9a0d33..e8b91023853 100644
--- a/src/uncategorized/BackwardsCompatibility.tw
+++ b/src/uncategorized/BackwardsCompatibility.tw
@@ -154,13 +154,11 @@
 <</if>>
 
 <<if ndef $reminders>>
-	<<set $reminders = []>>
-<</if>>
-<<if ndef $reminderEntries>>
-	<<set $reminderEntries = []>>
-<</if>>
-<<if ndef $reminderWeeks>>
-	<<set $reminderWeeks = []>>
+	<<set $reminders = {
+		entries: [],
+		weeks: [],
+		text: []
+	}>>
 <</if>>
 
 <<if $releaseID < 1057>>
-- 
GitLab