Fix: Resolve import error in App.tsx

Fixes an import error in `App.tsx` related to the `authStore`.  The error message "Failed to resolve import "./stores/authStore" from "src/App.tsx". Does the file exist?" indicates that the specified module could not be found.  This commit addresses the issue by ensuring the correct import path or by creating the missing file.
This commit is contained in:
gpt-engineer-app[bot] 2025-05-20 20:00:20 +00:00
parent ea18d3488d
commit ff772429f7
6 changed files with 81 additions and 20 deletions

40
package-lock.json generated
View File

@ -57,7 +57,8 @@
"tailwind-merge": "^2.5.2", "tailwind-merge": "^2.5.2",
"tailwindcss-animate": "^1.0.7", "tailwindcss-animate": "^1.0.7",
"vaul": "^0.9.3", "vaul": "^0.9.3",
"zod": "^3.23.8" "zod": "^3.23.8",
"zustand": "^4.4.7"
}, },
"devDependencies": { "devDependencies": {
"@eslint/js": "^9.9.0", "@eslint/js": "^9.9.0",
@ -7052,6 +7053,15 @@
} }
} }
}, },
"node_modules/use-sync-external-store": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/use-sync-external-store/-/use-sync-external-store-1.2.0.tgz",
"integrity": "sha512-eEgnFxGQ1Ife9bzYs6VLi8/4X6CObHMw9Qr9tPY43iKwsPw8xE8+EFsf/2cFZ5S3esXgpWgtSCtLNS41F+sKPA==",
"license": "MIT",
"peerDependencies": {
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
}
},
"node_modules/util-deprecate": { "node_modules/util-deprecate": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
@ -7346,6 +7356,34 @@
"funding": { "funding": {
"url": "https://github.com/sponsors/colinhacks" "url": "https://github.com/sponsors/colinhacks"
} }
},
"node_modules/zustand": {
"version": "4.4.7",
"resolved": "https://registry.npmjs.org/zustand/-/zustand-4.4.7.tgz",
"integrity": "sha512-QFJWJMdlETcI69paJwhSMJz7PPWjVP8Sjhclxmxmxv/RYI7ZOvR5BHX+ktH0we9gTWQMxcne8q1OY8xxz604gw==",
"license": "MIT",
"dependencies": {
"use-sync-external-store": "1.2.0"
},
"engines": {
"node": ">=12.7.0"
},
"peerDependencies": {
"@types/react": ">=16.8",
"immer": ">=9.0",
"react": ">=16.8"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"immer": {
"optional": true
},
"react": {
"optional": true
}
}
} }
} }
} }

View File

@ -60,7 +60,8 @@
"tailwind-merge": "^2.5.2", "tailwind-merge": "^2.5.2",
"tailwindcss-animate": "^1.0.7", "tailwindcss-animate": "^1.0.7",
"vaul": "^0.9.3", "vaul": "^0.9.3",
"zod": "^3.23.8" "zod": "^3.23.8",
"zustand": "^4.4.7"
}, },
"devDependencies": { "devDependencies": {
"@eslint/js": "^9.9.0", "@eslint/js": "^9.9.0",

View File

@ -14,6 +14,7 @@ interface LayoutProps {
const Layout: React.FC<LayoutProps> = ({ children }) => { const Layout: React.FC<LayoutProps> = ({ children }) => {
const { toast } = useToast(); const { toast } = useToast();
const [isMobile, setIsMobile] = useState(false); const [isMobile, setIsMobile] = useState(false);
const [sidebarOpen, setSidebarOpen] = useState(false);
useEffect(() => { useEffect(() => {
const checkIfMobile = () => { const checkIfMobile = () => {
@ -27,11 +28,15 @@ const Layout: React.FC<LayoutProps> = ({ children }) => {
window.removeEventListener('resize', checkIfMobile); window.removeEventListener('resize', checkIfMobile);
}; };
}, []); }, []);
const handleCloseSidebar = () => {
setSidebarOpen(false);
};
return ( return (
<div className="flex h-screen overflow-hidden"> <div className="flex h-screen overflow-hidden">
{isMobile ? ( {isMobile ? (
<Sheet> <Sheet open={sidebarOpen} onOpenChange={setSidebarOpen}>
<SheetTrigger asChild> <SheetTrigger asChild>
<Button variant="ghost" size="icon" className="md:hidden fixed top-2 left-2 z-20"> <Button variant="ghost" size="icon" className="md:hidden fixed top-2 left-2 z-20">
<Menu className="h-5 w-5" /> <Menu className="h-5 w-5" />
@ -39,11 +44,11 @@ const Layout: React.FC<LayoutProps> = ({ children }) => {
</Button> </Button>
</SheetTrigger> </SheetTrigger>
<SheetContent side="left" className="p-0 w-[250px]"> <SheetContent side="left" className="p-0 w-[250px]">
<Sidebar className="w-full border-none" /> <Sidebar isOpen={true} onClose={handleCloseSidebar} />
</SheetContent> </SheetContent>
</Sheet> </Sheet>
) : ( ) : (
<Sidebar /> <Sidebar isOpen={true} onClose={() => {}} />
)} )}
<div className="flex flex-col flex-1 overflow-hidden"> <div className="flex flex-col flex-1 overflow-hidden">
<Header /> <Header />

View File

@ -1,5 +1,6 @@
import { Link, NavLink, useLocation } from 'react-router-dom'; import { Link, NavLink, useLocation } from 'react-router-dom';
import { useMobile } from '@/hooks/use-mobile'; import { useIsMobile } from '@/hooks/use-mobile';
import { import {
Home, Home,
ListFilter, ListFilter,
@ -28,7 +29,7 @@ const getNavLinkClass = (isActive: boolean) => {
}; };
export default function Sidebar({ isOpen, onClose }: SidebarProps) { export default function Sidebar({ isOpen, onClose }: SidebarProps) {
const isMobile = useMobile(); const isMobile = useIsMobile();
const location = useLocation(); const location = useLocation();
return ( return (

View File

@ -1,19 +1,23 @@
import * as React from "react"
const MOBILE_BREAKPOINT = 768 import { useState, useEffect } from 'react';
export function useIsMobile() { export function useIsMobile() {
const [isMobile, setIsMobile] = React.useState<boolean | undefined>(undefined) const [isMobile, setIsMobile] = useState(false);
React.useEffect(() => { useEffect(() => {
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`) const checkIfMobile = () => {
const onChange = () => { setIsMobile(window.innerWidth < 768);
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT) };
}
mql.addEventListener("change", onChange) // Verificar inicialmente
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT) checkIfMobile();
return () => mql.removeEventListener("change", onChange)
}, []) // Adicionar listener para redimensionamento
window.addEventListener('resize', checkIfMobile);
// Limpar listener quando componente for desmontado
return () => window.removeEventListener('resize', checkIfMobile);
}, []);
return !!isMobile return isMobile;
} }

12
src/stores/authStore.ts Normal file
View File

@ -0,0 +1,12 @@
import { create } from 'zustand';
interface AuthState {
isLoggedIn: boolean;
setLoggedIn: (status: boolean) => void;
}
export const authStore = create<AuthState>((set) => ({
isLoggedIn: localStorage.getItem('autenticado') === 'true',
setLoggedIn: (status) => set({ isLoggedIn: status }),
}));