Skip to content

Commit 84c305c

Browse files
SideDrawer: do not resize canvas on drag
1 parent f18cbf6 commit 84c305c

File tree

3 files changed

+40
-20
lines changed

3 files changed

+40
-20
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bldrs",
3-
"version": "1.0.1893",
3+
"version": "1.0.1894",
44
"main": "src/index.jsx",
55
"license": "AGPL-3.0",
66
"homepage": "https://github.com/bldrs-ai/Share",

src/Components/Apps/Apps.spec.ts

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {expect, test} from '@playwright/test'
2-
import {assertDefined} from 'src/utils/assert'
32
import {
43
homepageSetup,
54
returningUserVisitsHomepageWaitForModel,
@@ -8,6 +7,22 @@ import {TITLE_NOTES} from '../Notes/component'
87
import {TITLE_APPS} from './component'
98

109

10+
/**
11+
* Assert `value` is not null.
12+
*
13+
* @template T
14+
* @param value
15+
* @param msg
16+
* @return value
17+
*/
18+
function assertNotNull<T>(value: T | null, msg: string): T {
19+
if (!value) {
20+
throw new Error(msg)
21+
}
22+
return value
23+
}
24+
25+
1126
const {beforeEach, describe} = test
1227
/**
1328
* Migrated from cypress/e2e/apps/apps.cy.js
@@ -63,7 +78,15 @@ describe('AppsSideDrawer', () => {
6378
const appsDrawer = page.getByTestId('AppsDrawer')
6479

6580
const handle = notesDrawer.getByTestId('resize-handle-x')
66-
const handleBox = assertDefined(await handle.boundingBox())
81+
const handleBox = assertNotNull(
82+
await handle.boundingBox(),
83+
'Expected Notes resize handle to have a bounding box',
84+
)
85+
const viewerContainer = page.locator('#viewer-container')
86+
const viewerBoxBefore = assertNotNull(
87+
await viewerContainer.boundingBox(),
88+
'Expected viewer container to have a bounding box',
89+
)
6790

6891
// Drag left to widen Notes (this used to push Apps out of view).
6992
await page.mouse.move(
@@ -78,10 +101,21 @@ describe('AppsSideDrawer', () => {
78101
// Apps should remain visible and inside the viewport.
79102
await expect(page.getByTestId(`PanelTitle-${TITLE_APPS}`)).toBeVisible()
80103

81-
const appsBox = assertDefined(await appsDrawer.boundingBox())
104+
const appsBox = assertNotNull(
105+
await appsDrawer.boundingBox(),
106+
'Expected Apps drawer to have a bounding box',
107+
)
82108
const vw = await page.evaluate(() => window.innerWidth)
83109
expect(appsBox.x).toBeGreaterThanOrEqual(0)
84110
expect(appsBox.x + (appsBox.width)).toBeLessThanOrEqual(vw + 1)
111+
112+
// Viewer should not resize when drawers open/resize (drawers overlay the canvas).
113+
const viewerBoxAfter = assertNotNull(
114+
await viewerContainer.boundingBox(),
115+
'Expected viewer container to have a bounding box after resize',
116+
)
117+
expect(Math.abs(viewerBoxAfter.width - viewerBoxBefore.width)).toBeLessThanOrEqual(1)
118+
expect(Math.abs(viewerBoxAfter.width - vw)).toBeLessThanOrEqual(2)
85119
})
86120
})
87121
})

src/Containers/CadView.jsx

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ export default function CadView({
5050
const hasGitHubIdentity = useStore((state) => state.hasGithubIdentity)
5151
const customViewSettings = useStore((state) => state.customViewSettings)
5252
const elementTypesMap = useStore((state) => state.elementTypesMap)
53-
const isAppsVisible = useStore((state) => state.isAppsVisible)
54-
const isNotesVisible = useStore((state) => state.isNotesVisible)
55-
const rightDrawerWidth = useStore((state) => state.rightDrawerWidth)
56-
const appsDrawerWidth = useStore((state) => state.appsDrawerWidth)
5753
const preselectedElementIds = useStore((state) => state.preselectedElementIds)
5854
const searchIndex = useStore((state) => state.searchIndex)
5955
const selectedElements = useStore((state) => state.selectedElements)
@@ -70,7 +66,6 @@ export default function CadView({
7066
const setSelectedElement = useStore((state) => state.setSelectedElement)
7167
const setSelectedElements = useStore((state) => state.setSelectedElements)
7268
const setViewer = useStore((state) => state.setViewer)
73-
const sidebarWidth = (isNotesVisible ? rightDrawerWidth : 0) + (isAppsVisible ? appsDrawerWidth : 0)
7469
const viewer = useStore((state) => state.viewer)
7570

7671
// AppSlice
@@ -705,17 +700,8 @@ export default function CadView({
705700
/* eslint-enable */
706701

707702

708-
// Shrink the scene viewer when drawer is open. This recenters the
709-
// view in the new shrunk canvas, which preserves what the user is
710-
// looking at.
711-
// TODO(pablo): add render testing
712-
useEffect(() => {
713-
const isDrawerOpen = isNotesVisible || isAppsVisible
714-
if (viewer && !isMobile) {
715-
viewer.container.style.width = isDrawerOpen ? `calc(100vw - ${sidebarWidth}px)` : '100vw'
716-
viewer.context.resize()
717-
}
718-
}, [isNotesVisible, isAppsVisible, isMobile, viewer, sidebarWidth])
703+
// NOTE: Do not resize the 3D canvas when drawers open/resize.
704+
// Drawers should overlay the viewer without changing its dimensions.
719705

720706
useEffect(() => {
721707
const setViewportHeight = () => {

0 commit comments

Comments
 (0)