-
Notifications
You must be signed in to change notification settings - Fork 3.5k
feat(home): resizable chat/resource panel divider #3648
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ba928f6
feat(home): resizable chat/resource panel divider
waleedlatif1 24ed482
fix(home): address PR review comments
waleedlatif1 81fb09b
refactor(home): eradicate useEffect anti-patterns per you-might-not-n…
waleedlatif1 8e6c617
fix(home): revert default width to 60%, reduce max resize to 63%
waleedlatif1 e56b4d4
improvement(react): replace useEffect anti-patterns with better React…
waleedlatif1 af49953
improvement(react): replace useEffect anti-patterns with better React…
waleedlatif1 d6adde6
improvement(home): use pointer events for resize handle (touch + mous…
waleedlatif1 2f13d0a
fix(autosave): store idle-reset timer ref to prevent status corruptio…
waleedlatif1 4f41c01
fix(home): move onEditValueConsumed call out of render phase into use…
waleedlatif1 1c6b155
fix(home): add pointercancel handler; fix(settings): sync name on pro…
waleedlatif1 35eed3c
fix(home): restore cleanupRef assignment dropped during AbortControll…
waleedlatif1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
feat(home): resizable chat/resource panel divider
- Loading branch information
commit ba928f642b0a11789d3a45ca5b9cd2d7fc241d29
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
65 changes: 65 additions & 0 deletions
65
apps/sim/app/workspace/[workspaceId]/home/hooks/use-mothership-resize.ts
This file contains hidden or 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,65 @@ | ||
| import { useCallback, useEffect, useRef } from 'react' | ||
| import { MOTHERSHIP_WIDTH } from '@/stores/constants' | ||
|
|
||
| /** | ||
| * Hook for managing resize of the MothershipView resource panel. | ||
| * | ||
| * Uses imperative DOM manipulation (zero React re-renders during drag). | ||
| * Attach `mothershipRef` to the MothershipView root div and call | ||
| * `handleResizeMouseDown` from the drag handle's onMouseDown. | ||
| * Call `clearWidth` when the panel collapses so the CSS class retakes control. | ||
| */ | ||
| export function useMothershipResize() { | ||
| const mothershipRef = useRef<HTMLDivElement | null>(null) | ||
| // Stored so the useEffect cleanup can tear down listeners if the component unmounts mid-drag | ||
| const cleanupRef = useRef<(() => void) | null>(null) | ||
|
|
||
| const handleResizeMouseDown = useCallback((e: React.MouseEvent) => { | ||
| e.preventDefault() | ||
|
|
||
| const el = mothershipRef.current | ||
| if (!el) return | ||
|
|
||
| // Pin to current rendered width so drag starts from the visual position | ||
| el.style.width = `${el.getBoundingClientRect().width}px` | ||
|
|
||
| // Disable CSS transition to prevent animation lag during drag | ||
| const prevTransition = el.style.transition | ||
| el.style.transition = 'none' | ||
| document.body.style.cursor = 'ew-resize' | ||
| document.body.style.userSelect = 'none' | ||
|
|
||
| const handleMouseMove = (moveEvent: MouseEvent) => { | ||
| const newWidth = window.innerWidth - moveEvent.clientX | ||
| const maxWidth = window.innerWidth * MOTHERSHIP_WIDTH.MAX_PERCENTAGE | ||
| el.style.width = `${Math.min(Math.max(newWidth, MOTHERSHIP_WIDTH.MIN), maxWidth)}px` | ||
|
waleedlatif1 marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| const handleMouseUp = () => { | ||
| el.style.transition = prevTransition | ||
| document.body.style.cursor = '' | ||
| document.body.style.userSelect = '' | ||
| document.removeEventListener('mousemove', handleMouseMove) | ||
| document.removeEventListener('mouseup', handleMouseUp) | ||
| cleanupRef.current = null | ||
| } | ||
|
waleedlatif1 marked this conversation as resolved.
|
||
|
|
||
| cleanupRef.current = handleMouseUp | ||
| document.addEventListener('mousemove', handleMouseMove) | ||
| document.addEventListener('mouseup', handleMouseUp) | ||
| }, []) | ||
|
waleedlatif1 marked this conversation as resolved.
Outdated
waleedlatif1 marked this conversation as resolved.
Outdated
|
||
|
|
||
| // Tear down any active drag if the component unmounts mid-drag | ||
| useEffect(() => { | ||
| return () => { | ||
| cleanupRef.current?.() | ||
| } | ||
| }, []) | ||
|
|
||
| /** Remove inline width so the collapse CSS class retakes control */ | ||
| const clearWidth = useCallback(() => { | ||
| mothershipRef.current?.style.removeProperty('width') | ||
| }, []) | ||
|
|
||
| return { mothershipRef, handleResizeMouseDown, clearWidth } | ||
| } | ||
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.