Fix: Restore missing buttons by refining UI state logic

This commit is contained in:
Avery Felts 2026-01-31 18:31:37 -07:00
parent af6ac933ee
commit 2e06aa833a

View File

@ -51,7 +51,6 @@ export function Dashboard({ user }: DashboardProps) {
const [achievements, setAchievements] = useState<Achievement[]>([]);
const [savingsConfig, setSavingsConfig] = useState<SavingsConfig | null>(null);
const [showSetup, setShowSetup] = useState(false);
const [showUsagePrompt, setShowUsagePrompt] = useState(false);
const [showCelebration, setShowCelebration] = useState(false);
const [isSubstancePickerOpen, setIsSubstancePickerOpen] = useState(false);
const [activeLoggingSubstance, setActiveLoggingSubstance] = useState<'nicotine' | 'weed' | null>(null);
@ -63,7 +62,8 @@ export function Dashboard({ user }: DashboardProps) {
const swipeContainerRef = useRef<HTMLDivElement>(null);
const { theme } = useTheme();
const isAnyModalOpen = modalOpenCount > 0 || showUsagePrompt || showSetup || showCelebration;
const isModalOpen = modalOpenCount > 0 || showSetup || showCelebration;
const isNavHidden = isModalOpen || isSubstancePickerOpen || !!activeLoggingSubstance;
const handleModalStateChange = useCallback((isOpen: boolean) => {
setModalOpenCount(prev => isOpen ? prev + 1 : Math.max(0, prev - 1));
@ -165,11 +165,11 @@ export function Dashboard({ user }: DashboardProps) {
const isStandalone = window.matchMedia('(display-mode: standalone)').matches ||
(window.navigator as Navigator & { standalone?: boolean }).standalone === true;
// Always show usage prompt when accessed as PWA shortcut
// Always show substance picker when accessed as PWA shortcut
if (isStandalone) {
setShowUsagePrompt(true);
setIsSubstancePickerOpen(true);
} else if (shouldShowUsagePrompt()) {
setShowUsagePrompt(true);
setIsSubstancePickerOpen(true);
markPromptShown();
}
}
@ -195,13 +195,14 @@ export function Dashboard({ user }: DashboardProps) {
await savePreferencesAsync(newPrefs);
setPreferences(newPrefs);
setShowSetup(false);
setShowUsagePrompt(true);
setIsSubstancePickerOpen(true);
setRefreshKey(prev => prev + 1);
};
const handleUsageSubmit = async (count: number, substance: 'nicotine' | 'weed') => {
if (!preferences) {
setShowUsagePrompt(false);
setIsSubstancePickerOpen(false);
setActiveLoggingSubstance(null);
return;
}
@ -226,7 +227,6 @@ export function Dashboard({ user }: DashboardProps) {
setPreferences(latestPrefs);
}
setShowUsagePrompt(false);
setActiveLoggingSubstance(null);
setIsSubstancePickerOpen(false);
// Reload data and force calendar refresh
@ -306,7 +306,7 @@ export function Dashboard({ user }: DashboardProps) {
{preferences && (
<>
{/* Floating Log Button - Simplified to toggle Picker */}
<div className={`fixed bottom-6 right-6 z-40 transition-all duration-300 ${isAnyModalOpen ? 'opacity-0 scale-90 pointer-events-none' : 'opacity-100 scale-100'} sm:block`}>
<div className={`fixed bottom-6 right-6 z-40 transition-all duration-300 ${isModalOpen ? 'opacity-0 scale-90 pointer-events-none' : 'opacity-100 scale-100'} sm:block`}>
<Button
size="lg"
onClick={() => setIsSubstancePickerOpen(!isSubstancePickerOpen)}
@ -333,7 +333,7 @@ export function Dashboard({ user }: DashboardProps) {
<div className="space-y-6 sm:space-y-12 relative overflow-hidden">
{/* Mobile Navigation Buttons - LARGE */}
<div className="sm:hidden">
{currentPage > 0 && !isAnyModalOpen && (
{currentPage > 0 && !isNavHidden && (
<button
onClick={() => scrollToPage(currentPage - 1)}
className="fixed left-3 top-[55%] -translate-y-1/2 z-40 p-5 rounded-full glass border border-white/20 shadow-2xl active:scale-90 transition-all duration-300 group"
@ -346,7 +346,7 @@ export function Dashboard({ user }: DashboardProps) {
<ChevronLeft className="h-8 w-8 text-primary group-hover:scale-110" />
</button>
)}
{currentPage < 3 && !isAnyModalOpen && (
{currentPage < 3 && !isNavHidden && (
<button
onClick={() => scrollToPage(currentPage + 1)}
className="fixed right-3 top-[55%] -translate-y-1/2 z-40 p-5 rounded-full glass border border-white/20 shadow-2xl active:scale-90 transition-all duration-300 group"