From 2f187b10072bb8e70e98685096192238646af365 Mon Sep 17 00:00:00 2001 From: Sofiya Tepikin Date: Sat, 24 Sep 2022 12:42:00 +0200 Subject: [PATCH] Add date context and provide it to the app --- components/app-wrapper.js | 6 +++++- hooks/useDate.js | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 hooks/useDate.js 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 } +}