Skip to content

Commit

Permalink
fix: APPS popover closing issue
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalkondle-dev committed Jun 22, 2024
1 parent fb56f81 commit beba8a1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
1 change: 1 addition & 0 deletions app/api/todos/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
getTodaysTodos,
getRecentTodos,
} from '@/lib/functions';
import '@/models/TodoList';

export async function GET(req: NextRequest) {
try {
Expand Down
9 changes: 7 additions & 2 deletions components/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,23 @@ import { APPS } from '@/lib/constants';
interface Props {
app: (typeof APPS)[number];
isCurrent: boolean;
setOpened: any;
}

const App = ({ app, isCurrent }: Props) => {
const App = ({ app, isCurrent, setOpened }: Props) => {
const router = useRouter();
const { hovered, ref } = useHover();

return (
<Paper
p="xs"
ref={ref}
bg={hovered || isCurrent ? `${app.color}.3` : 'transparent'}
key={app.path}
onClick={() => router.push(app?.path || '')}
onClick={() => {
setOpened(false);
router.push(app?.path || '');
}}
style={{ cursor: 'pointer' }}
c={hovered || isCurrent ? 'white' : 'dark'}
>
Expand Down
24 changes: 21 additions & 3 deletions components/Layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { APPS } from '@/lib/constants';
export default function Layout({ children }: { children: React.ReactNode }) {
const [mobileOpened, { toggle: toggleMobile, close }] = useDisclosure();
const [desktopOpened, { toggle: toggleDesktop }] = useDisclosure(true);
const [opened, setOpened] = useState(false);
const session = useSession();
const loading = session?.status === 'loading';
const isLoggedIn = session?.status === 'authenticated';
Expand Down Expand Up @@ -107,16 +108,33 @@ export default function Layout({ children }: { children: React.ReactNode }) {
<Group gap={0}>
{isLoggedIn && (
<>
<Popover position="bottom" withArrow shadow="md">
<Popover
opened={opened}
onChange={setOpened}
position="bottom"
withArrow
shadow="md"
>
<Popover.Target>
<ActionIcon variant="subtle" color="gray" radius="xl" size="lg">
<ActionIcon
variant="subtle"
color="gray"
radius="xl"
size="lg"
onClick={() => setOpened((o) => !o)}
>
<IconGridDots stroke={3} style={{ width: rem(20), height: rem(20) }} />
</ActionIcon>
</Popover.Target>
<Popover.Dropdown p="xs">
<SimpleGrid spacing="xs" cols={3}>
{APPS.map((app) => (
<App isCurrent={APP?.path === app?.path} key={app?.path} app={app} />
<App
setOpened={setOpened}
isCurrent={APP?.path === app?.path}
key={app?.path}
app={app}
/>
))}
</SimpleGrid>
</Popover.Dropdown>
Expand Down

0 comments on commit beba8a1

Please sign in to comment.