fixed dass er bei essen bzw trinken bleibt
This commit is contained in:
parent
a376b5cd8a
commit
189fff2c34
@ -6,7 +6,11 @@ import './HomePage.css';
|
|||||||
|
|
||||||
const HomePage: React.FC = () => {
|
const HomePage: React.FC = () => {
|
||||||
const [productsData, setProductsData] = useState<ProductsData>({ food: [], drinks: [] });
|
const [productsData, setProductsData] = useState<ProductsData>({ food: [], drinks: [] });
|
||||||
const [activeTab, setActiveTab] = useState<'food' | 'drinks'>('drinks');
|
const [activeTab, setActiveTab] = useState<'food' | 'drinks'>(() => {
|
||||||
|
// Initialize from session storage, default to 'drinks' if not available
|
||||||
|
const savedTab = sessionStorage.getItem('kelnerRechnerActiveTab');
|
||||||
|
return (savedTab === 'food' || savedTab === 'drinks') ? savedTab as 'food' | 'drinks' : 'drinks';
|
||||||
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
import('../data/products.json')
|
import('../data/products.json')
|
||||||
@ -16,6 +20,12 @@ const HomePage: React.FC = () => {
|
|||||||
.catch(error => console.error('Failed to load products:', error));
|
.catch(error => console.error('Failed to load products:', error));
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
// Handler for tab changes that also updates session storage
|
||||||
|
const handleTabChange = (tab: 'food' | 'drinks') => {
|
||||||
|
setActiveTab(tab);
|
||||||
|
sessionStorage.setItem('kelnerRechnerActiveTab', tab);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="home-page">
|
<div className="home-page">
|
||||||
<header className="app-header">
|
<header className="app-header">
|
||||||
@ -27,13 +37,13 @@ const HomePage: React.FC = () => {
|
|||||||
<div className="category-tabs">
|
<div className="category-tabs">
|
||||||
<button
|
<button
|
||||||
className={activeTab === 'drinks' ? 'active' : ''}
|
className={activeTab === 'drinks' ? 'active' : ''}
|
||||||
onClick={() => setActiveTab('drinks')}
|
onClick={() => handleTabChange('drinks')}
|
||||||
>
|
>
|
||||||
Getränke
|
Getränke
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
className={activeTab === 'food' ? 'active' : ''}
|
className={activeTab === 'food' ? 'active' : ''}
|
||||||
onClick={() => setActiveTab('food')}
|
onClick={() => handleTabChange('food')}
|
||||||
>
|
>
|
||||||
Essen
|
Essen
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user