Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pack Sidebar in its own module #463

Merged
merged 3 commits into from
Mar 6, 2024
Merged

Pack Sidebar in its own module #463

merged 3 commits into from
Mar 6, 2024

Conversation

Amnish04
Copy link
Collaborator

@Amnish04 Amnish04 commented Feb 16, 2024

#437 introduced a lot of duplication for sidebar related styles and logic as we now had different sidebar views for mobile and desktop.

I have tried to minimize that duplication, by creating separate components for mobile and desktop sidebar and exposing through a common Sidebar api, taking inspiration from the way PromptForm is done.

This way, the places that use the sidebar now look the same as before since all the changes have been abstracted in its own module.

Here's a summary of changes:

  1. Renamed the existing Sidebar component to SidebarContent.
  2. Added a SidebarMobile component that uses SidebarContent and extends it by adding the search field and ChatCraft brand at the top.
  3. Similarly, SidebarDesktop component wraps SidebarContent to apply the new open/close transition effect. This way, we don't have to repeat the keyframe definitions at evey place where sidebar is used.
  4. These Sidebar components are exposed by the common Sidebar in index.tsx based on the screen width using isMobile hook.

This fixes #457.

Copy link

cloudflare-pages bot commented Feb 16, 2024

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 840b987
Status: ✅  Deploy successful!
Preview URL: https://2ac9a670.console-overthinker-dev.pages.dev
Branch Preview URL: https://amnish04-sidebar-refactor.console-overthinker-dev.pages.dev

View logs

@Amnish04 Amnish04 self-assigned this Feb 16, 2024
@kliu57 kliu57 self-requested a review February 22, 2024 14:04
type SidebarMobileProps = SidebarContentProps & {
searchText?: string;
handleToggleSidebarVisible: () => void;
isSidebarVisible: boolean;
Copy link
Collaborator

@WangGithub0 WangGithub0 Feb 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SidebarMobile and SidebarDesktop both have isSidebarVisible, could we put it in SidebarContent?

Copy link
Collaborator Author

@Amnish04 Amnish04 Feb 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WangGithub0 We probably can't have it in SidebarContent as its not even using those props.

I was actually thinking of managing sidebar triggers inside the Sidebar component which is a common ancestor of both SidebarDesktop and SidebarMobile.
image

But that came with a problem. Currently, many of the UI elements in the ChatBase component are using isSidebarVisible managed by the useDisclosure hook at the top level of component hierarchy.
image

In other words, those elements are not reading directly from the Settings context. And when I tried to encapsulate isSidebarVisible management in Sidebar.tsx both of those properties got out of sync and started causing unexpected behaviours with opening and closing of sidebar.

Ideally, I think we should be managing the sidebarVisible state with useSettings hook considering that its state is meant to be single source of truth.

But since I have not used the useDisclosure hook before and am not sure if its serving a higher purpose than my understanding, I decided not to touch it and pass that state as props to components. Again, I am also confused which path I should pick here, but the current way manages to make it work without making changes to lot of places

Copy link
Collaborator

@kliu57 kliu57 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did some regression testing on your branch and things are working well

@Amnish04 Amnish04 changed the title Minimize duplication for sidebar code Pack Sidebar in its own module Mar 6, 2024
@Amnish04 Amnish04 merged commit 0c46cf0 into main Mar 6, 2024
4 checks passed
@kliu57 kliu57 added this to the Release 1.4 milestone Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor the sidebar to eliminate duplication
3 participants