-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Once source of truth for dates, move things into the date hook
- Loading branch information
Showing
3 changed files
with
25 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,31 @@ | ||
import { useEffect } from "react"; | ||
import { format, parseISO, isBefore } from "date-fns"; | ||
import { useAppState } from "../AppContext"; | ||
import { useAppState, useAppReducer } from "../AppContext"; | ||
const { remote } = require("electron"); | ||
|
||
export default function useDateCheck() { | ||
const { date } = useAppState(); | ||
const dispatch = useAppReducer(); | ||
const storedDate = parseISO(`${date.year}-${date.month}-${date.day}`); | ||
|
||
useEffect(() => { | ||
let nd = new Date(); | ||
|
||
const interval = setInterval(() => { | ||
let nd = new Date(); | ||
let currentDate = parseISO( | ||
`${format(nd, "y")}-${format(nd, "MM")}-${format(nd, "dd")}` | ||
); | ||
console.log(remote.getCurrentWindow()); | ||
|
||
if (isBefore(storedDate, currentDate)) { | ||
if (remote.getCurrentWindow().showResetNotification) { | ||
// Disabling this line so that it doesn't yell at us for not using | ||
// the notification variable | ||
// eslint-disable-next-line | ||
let resetNotification = new Notification("todometer reset time!", { | ||
new Notification("todometer reset time!", { | ||
body: "It's a new day! Your todos are being reset." | ||
}); | ||
} | ||
dispatch({ type: "RESET_ALL" }); | ||
window.location.reload(); | ||
} | ||
}, 1000); | ||
return () => clearInterval(interval); | ||
}, [storedDate]); | ||
}, [storedDate, dispatch]); | ||
} |