From 6fea27e0cac2d17928aaedb7245f280c091d06f6 Mon Sep 17 00:00:00 2001
From: Vishesh Handa <me@vhanda.in>
Date: Thu, 14 Feb 2019 01:11:35 +0100
Subject: [PATCH] Show +1 notification badge after user has made a journal
 entry

---
 lib/appstate.dart            | 2 ++
 lib/screens/home_screen.dart | 4 +++-
 lib/state_container.dart     | 2 ++
 3 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/appstate.dart b/lib/appstate.dart
index 0a753413..2b4f7460 100644
--- a/lib/appstate.dart
+++ b/lib/appstate.dart
@@ -9,6 +9,8 @@ class AppState {
   String remoteGitRepoPath = "";
   bool remoteGitRepoConfigured = false;
 
+  bool hasJournalEntries = false;
+
   // FIXME: Make final
   String gitBaseDirectory = "";
 
diff --git a/lib/screens/home_screen.dart b/lib/screens/home_screen.dart
index 6c370e85..b88ee274 100644
--- a/lib/screens/home_screen.dart
+++ b/lib/screens/home_screen.dart
@@ -33,9 +33,11 @@ class HomeScreen extends StatelessWidget {
       },
     );
 
+    bool shouldShowBadge =
+        !appState.remoteGitRepoConfigured && appState.hasJournalEntries;
     var appBarMenuButton = BadgeIconButton(
       icon: const Icon(Icons.menu),
-      itemCount: appState.remoteGitRepoConfigured ? 0 : 1,
+      itemCount: shouldShowBadge ? 1 : 0,
       onPressed: () {
         _scaffoldKey.currentState.openDrawer();
       },
diff --git a/lib/state_container.dart b/lib/state_container.dart
index 0e1d2aa9..a05a416d 100644
--- a/lib/state_container.dart
+++ b/lib/state_container.dart
@@ -97,6 +97,7 @@ class StateContainerState extends State<StateContainer> {
       setState(() {
         appState.isLoadingFromDisk = false;
         appState.notes = loadedNotes;
+        appState.hasJournalEntries = loadedNotes.isNotEmpty;
       });
     }).catchError((err, stack) {
       setState(() {
@@ -121,6 +122,7 @@ class StateContainerState extends State<StateContainer> {
       setState(() {
         appState.isLoadingFromDisk = false;
         appState.notes = loadedNotes;
+        appState.hasJournalEntries = loadedNotes.isNotEmpty;
       });
     } catch (err, stack) {
       setState(() {