-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing some styling problems and add support for mobile
- Loading branch information
Showing
19 changed files
with
160 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,58 @@ | ||
import React from "react"; | ||
import { ChatProps } from "../../types"; | ||
import { ChatWrapper, ChatContent, ChatContainer } from "./styles/chat.styles"; | ||
import { | ||
ChatWrapper, | ||
ChatContent, | ||
ChatContainer, | ||
ChatLayer, | ||
} from "./styles/chat.styles"; | ||
import { useChat } from "./hooks/useChat"; | ||
import { ChatProvider } from "../../provider"; | ||
import { ChatProvider, useChatProvider } from "../../provider"; | ||
import useClassNames from "../../hooks/useClassNames"; | ||
import { useMediaQuery } from "../../hooks/useMediaQuery"; | ||
import { useSidebarHandler } from "../sidebar/hooks/useSidebarHandler"; | ||
|
||
export const Chat: React.FC<ChatProps> = ({ | ||
children, | ||
className, | ||
classNames, | ||
}) => { | ||
const { sidebar, messageInput, messages } = useChat(children); | ||
const classes = useClassNames({ className, classNames }); | ||
|
||
return ( | ||
<ChatProvider> | ||
<ChatWrapper className={classes?.base}> | ||
<ChatContent className={classes?.content}> | ||
{sidebar} | ||
<ChatContainer className={classes?.container}> | ||
{messages} | ||
{messageInput} | ||
</ChatContainer> | ||
</ChatContent> | ||
</ChatWrapper> | ||
<ChatHelper className={className} classNames={classNames}> | ||
{children} | ||
</ChatHelper> | ||
</ChatProvider> | ||
); | ||
}; | ||
|
||
export default Chat; | ||
|
||
const ChatHelper: React.FC<ChatProps> = ({ | ||
children, | ||
className, | ||
classNames, | ||
}) => { | ||
const { sidebar, messageInput, messages } = useChat(children); | ||
const classes = useClassNames({ className, classNames }); | ||
const isMobile = useMediaQuery("(max-width: 768px)"); | ||
const { handleClose } = useSidebarHandler(); | ||
const { | ||
state: { isSidebarOpen }, | ||
} = useChatProvider(); | ||
|
||
return ( | ||
<ChatWrapper className={classes?.base}> | ||
<ChatContent className={classes?.content}> | ||
{sidebar} | ||
{isMobile && isSidebarOpen && ( | ||
<ChatLayer onClick={handleClose} /> | ||
)} | ||
<ChatContainer className={classes?.container}> | ||
{messages} | ||
{messageInput} | ||
</ChatContainer> | ||
</ChatContent> | ||
</ChatWrapper> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { useChatProvider } from "../../../provider"; | ||
|
||
export const useSidebarHandler = () => { | ||
const { dispatch } = useChatProvider(); | ||
|
||
const handleToggle = () => { | ||
dispatch({ type: "TOGGLE_SIDEBAR" }); | ||
}; | ||
|
||
const handleOpen = () => { | ||
dispatch({ type: "OPEN_SIDEBAR" }); | ||
}; | ||
|
||
const handleClose = () => { | ||
dispatch({ type: "CLOSE_SIDEBAR" }); | ||
}; | ||
|
||
return { handleToggle, handleOpen, handleClose }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React from "react"; | ||
|
||
export function useMediaQuery(query: string) { | ||
const subscribe = React.useCallback( | ||
(callback: () => void) => { | ||
const matchMedia = window.matchMedia(query); | ||
|
||
matchMedia.addEventListener("change", callback); | ||
return () => { | ||
matchMedia.removeEventListener("change", callback); | ||
}; | ||
}, | ||
[query] | ||
); | ||
|
||
const getSnapshot = () => { | ||
return window.matchMedia(query).matches; | ||
}; | ||
|
||
return React.useSyncExternalStore(subscribe, getSnapshot); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.