Add date context and provide it to the app
This commit is contained in:
@@ -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 ? (
|
||||
<PasswordPrompt enableShowApp={() => setIsDbEncrypted(false)} />
|
||||
) : (
|
||||
<App restartApp={() => checkIsDbEncrypted()} />
|
||||
<DateProvider>
|
||||
<App restartApp={() => checkIsDbEncrypted()} />
|
||||
</DateProvider>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
|
||||
@@ -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 (
|
||||
<DateContext.Provider value={{ date, setDate }}>
|
||||
{children}
|
||||
</DateContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
DateProvider.propTypes = {
|
||||
children: PropTypes.node,
|
||||
}
|
||||
|
||||
export const useDate = () => {
|
||||
const { date, setDate } = useContext(DateContext)
|
||||
return { date, setDate }
|
||||
}
|
||||
Reference in New Issue
Block a user