From b2820bbb47299efd4ce161e2f1a526feeb9cd1bd Mon Sep 17 00:00:00 2001 From: Ryan Lanny Jenkins Date: Wed, 4 Jun 2025 20:44:28 -0500 Subject: [PATCH] Allow pressing 1-4 to select a tab. --- src/App.tsx | 22 +++++++++++++++++----- src/components/CustomTabs.tsx | 11 +++++------ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 76b690d..76bcf90 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -31,12 +31,24 @@ function App() { useGameTick() useSaveSystem() const [isGodModalOpen, setIsGodModalOpen] = useState(false) + const [activeTab, setActiveTab] = useState('fields') useEffect(() => { const handleKeyPress = (event: KeyboardEvent) => { if (event.key.toLowerCase() === 'g') { setIsGodModalOpen(prev => !prev) } + // Handle number keys 1-4 for tab selection + const tabMap: { [key: string]: string } = { + '1': 'fields', + '2': 'warehouse', + '3': 'market', + '4': 'temple' + } + const tabValue = tabMap[event.key] + if (tabValue) { + setActiveTab(tabValue) + } } window.addEventListener('keydown', handleKeyPress) @@ -47,12 +59,12 @@ function App() {
- + - Fields - Warehouse - Market - Temple + Fields (1) + Warehouse (2) + Market (3) + Temple (4) diff --git a/src/components/CustomTabs.tsx b/src/components/CustomTabs.tsx index 69c1150..d3c311b 100644 --- a/src/components/CustomTabs.tsx +++ b/src/components/CustomTabs.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react' +import React from 'react' export interface TabProps { value: string @@ -6,7 +6,8 @@ export interface TabProps { } export interface TabsProps { - defaultValue: string + value: string + onValueChange: (value: string) => void children: React.ReactNode } @@ -76,11 +77,9 @@ const TabsContext = React.createContext<{ setValue: () => {}, }) -export const Tabs: React.FC = ({ defaultValue, children }) => { - const [value, setValue] = useState(defaultValue) - +export const Tabs: React.FC = ({ value, onValueChange, children }) => { return ( - +
{children}
)