implemented modal providor modal store
This commit is contained in:
parent
266cb715b0
commit
784e24e8f3
@ -2,8 +2,10 @@ import './globals.css'
|
|||||||
import type { Metadata } from 'next'
|
import type { Metadata } from 'next'
|
||||||
import { Open_Sans } from 'next/font/google'
|
import { Open_Sans } from 'next/font/google'
|
||||||
import { ClerkProvider } from '@clerk/nextjs'
|
import { ClerkProvider } from '@clerk/nextjs'
|
||||||
import { ThemeProvider } from '@/components/providors/theme-providor'
|
|
||||||
import { cn } from '@/lib/utils'
|
import { cn } from '@/lib/utils'
|
||||||
|
import { ThemeProvider } from '@/components/providors/theme-providor'
|
||||||
|
import { ModalProvidor } from '@/components/providors/modal-providor'
|
||||||
|
|
||||||
const font = Open_Sans({ subsets: ['latin'] })
|
const font = Open_Sans({ subsets: ['latin'] })
|
||||||
|
|
||||||
@ -30,6 +32,7 @@ export default function RootLayout({
|
|||||||
enableSystem={false}
|
enableSystem={false}
|
||||||
storageKey="discord-theme"
|
storageKey="discord-theme"
|
||||||
>
|
>
|
||||||
|
<ModalProvidor/>
|
||||||
{children}
|
{children}
|
||||||
</ThemeProvider>
|
</ThemeProvider>
|
||||||
</body>
|
</body>
|
||||||
|
@ -3,8 +3,12 @@
|
|||||||
import { Plus } from "lucide-react"
|
import { Plus } from "lucide-react"
|
||||||
|
|
||||||
import { ActionTooltip } from "@/components/action-tooltip"
|
import { ActionTooltip } from "@/components/action-tooltip"
|
||||||
|
import { useModal } from "@/hooks/use-modal-store"
|
||||||
|
|
||||||
export const NavigationAction = () => {
|
export const NavigationAction = () => {
|
||||||
|
|
||||||
|
const { onOpen } = useModal();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<ActionTooltip
|
<ActionTooltip
|
||||||
@ -13,6 +17,7 @@ export const NavigationAction = () => {
|
|||||||
label="Add a server"
|
label="Add a server"
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
|
onClick={() => onOpen("createServer")}
|
||||||
className="group flex items-center"
|
className="group flex items-center"
|
||||||
>
|
>
|
||||||
<div className="flex mx-3 h-[48px] w-[48px] rounded-[24px] group-hover:rounded-[16px] transition-all overflow-hidding items-center justify-center bg-background dark:bg-neutral-700 group-hover:bg-emerald-500">
|
<div className="flex mx-3 h-[48px] w-[48px] rounded-[24px] group-hover:rounded-[16px] transition-all overflow-hidding items-center justify-center bg-background dark:bg-neutral-700 group-hover:bg-emerald-500">
|
||||||
|
23
components/providors/modal-providor.tsx
Normal file
23
components/providors/modal-providor.tsx
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
|
import { CreateServerModal } from "@/components/modals/create-server-modal";
|
||||||
|
|
||||||
|
export const ModalProvidor = () => {
|
||||||
|
const [isMounted, setIsMounted] = useState(false);
|
||||||
|
|
||||||
|
useEffect (() => {
|
||||||
|
setIsMounted(true);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
if (!isMounted) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<CreateServerModal />
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
17
hooks/use-modal-store.ts
Normal file
17
hooks/use-modal-store.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { create } from "zustand";
|
||||||
|
|
||||||
|
export type ModalType = "createServer";
|
||||||
|
|
||||||
|
interface ModalStore {
|
||||||
|
type: ModalType | null;
|
||||||
|
isOpen: boolean;
|
||||||
|
onOpen: (type: ModalType) => void;
|
||||||
|
onClose: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useModal = create<ModalStore>((set) => ({
|
||||||
|
type: null,
|
||||||
|
isOpen: false,
|
||||||
|
onOpen: (type) => set({ isOpen: true, type }),
|
||||||
|
onClose: () => set({ type: null, isOpen: false }),
|
||||||
|
}));
|
Loading…
x
Reference in New Issue
Block a user