|
@@ -1,37 +1,18 @@
|
|
-import React, { ReactElement, useEffect, useState } from 'react';
|
|
|
|
|
|
+import React, { ReactElement } from 'react';
|
|
import {
|
|
import {
|
|
BrowserRouter as Router,
|
|
BrowserRouter as Router,
|
|
Route,
|
|
Route,
|
|
Switch
|
|
Switch
|
|
} from 'react-router-dom';
|
|
} from 'react-router-dom';
|
|
import { CaloriesList } from '../components/caloriesList/CaloriesList';
|
|
import { CaloriesList } from '../components/caloriesList/CaloriesList';
|
|
-import { AppContext } from './AppContext';
|
|
|
|
|
|
+import { AppContextProvider } from './AppContextProvider';
|
|
import { PageFooter } from './pageFooter/PageFooter';
|
|
import { PageFooter } from './pageFooter/PageFooter';
|
|
import { PageHeader } from './pageHeader/PageHeader';
|
|
import { PageHeader } from './pageHeader/PageHeader';
|
|
-
|
|
|
|
import './app.css';
|
|
import './app.css';
|
|
|
|
|
|
-const AppContextProvider = AppContext.Provider;
|
|
|
|
-const storedCalories = JSON.parse(localStorage.getItem('calorieItems') || '[]');
|
|
|
|
-
|
|
|
|
function App (): ReactElement {
|
|
function App (): ReactElement {
|
|
- const [calorieItems, setCalorieItems] = useState<CalorieItems>(storedCalories);
|
|
|
|
- const [selectedDate, setSelectedDate] = useState<number>(Date.now());
|
|
|
|
- const [selectedItem, setSelectedItem] = useState<CalorieValue>();
|
|
|
|
-
|
|
|
|
- useEffect(() => {
|
|
|
|
- localStorage.setItem('calorieItems', JSON.stringify(calorieItems));
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
return (
|
|
return (
|
|
- <AppContextProvider value={{
|
|
|
|
- calorieItems,
|
|
|
|
- selectedDate,
|
|
|
|
- selectedItem,
|
|
|
|
- setCalorieItems,
|
|
|
|
- setSelectedDate,
|
|
|
|
- setSelectedItem
|
|
|
|
- }}>
|
|
|
|
|
|
+ <AppContextProvider >
|
|
<PageHeader />
|
|
<PageHeader />
|
|
|
|
|
|
<main id="pageContent">
|
|
<main id="pageContent">
|