diff --git a/components/app-wrapper.js b/components/app-wrapper.js index 3674c2b..74d8798 100644 --- a/components/app-wrapper.js +++ b/components/app-wrapper.js @@ -10,6 +10,8 @@ import AppStatusBar from './common/app-status-bar' import AcceptLicense from './AcceptLicense' import PasswordPrompt from './password-prompt' +import { DateProvider } from '../hooks/useDate' + export default function AppWrapper() { const [isLoading, setIsLoading] = useState(true) const [isLicenseAccepted, setIsLicenseAccepted] = useState(false) @@ -47,7 +49,9 @@ export default function AppWrapper() { {isDbEncrypted ? ( setIsDbEncrypted(false)} /> ) : ( - checkIsDbEncrypted()} /> + + checkIsDbEncrypted()} /> + )} ) diff --git a/hooks/useDate.js b/hooks/useDate.js new file mode 100644 index 0000000..3a45b6a --- /dev/null +++ b/hooks/useDate.js @@ -0,0 +1,24 @@ +import React, { createContext, useContext, useState } from 'react' +import PropTypes from 'prop-types' +import { LocalDate } from '@js-joda/core' + +const DateContext = createContext() + +export const DateProvider = ({ children }) => { + const [date, setDate] = useState(LocalDate.now().toString()) + + return ( + + {children} + + ) +} + +DateProvider.propTypes = { + children: PropTypes.node, +} + +export const useDate = () => { + const { date, setDate } = useContext(DateContext) + return { date, setDate } +}