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

Introduce screenshot API, feature flag and use it in NoteCard. #750

Merged
merged 4 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions cypress/e2e/screenshot/screen-from-note.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
describe('Note screenshot', () => {
context('enable/disable feature using url parameter', () => {
beforeEach(() => {
cy.setCookie('isFirstTime', 'false')
cy.visit('/')
})

it('should not show screenshot button when url param not present', () => {
cy.findByRole('button', {name: /Take Screenshot/}).should('not.exist')
})

it('should show screenshot when url param present', () => {
cy.routerNavigate('/share/v/p/index.ifc?feature=screenshot')
cy.get('[title="Notes"]').click()
cy.get('button[title="Take Screenshot"]').should('exist')
})
})
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bldrs",
"version": "1.0.0-r670",
"version": "1.0.0-r675",
"main": "src/index.jsx",
"license": "MIT",
"homepage": "https://github.com/bldrs-ai/Share",
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Buttons.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function TooltipIconButton({
title={title}
describeChild
placement={placement}
data-testid={dataTestId}
data-testid={dataTestId || title}
PopperProps={{style: {zIndex: 0}}}
>
<ToggleButton selected={selected} onClick={onClick} value={''} size={size}>
Expand Down
25 changes: 22 additions & 3 deletions src/Components/Notes/NoteCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ import {
removeCameraUrlParams,
} from '../CameraControl'
import {useIsMobile} from '../Hooks'
import {usePlaceMark} from '../../hooks/usePlaceMark'
import {useExistInFeature} from '../../hooks/useExistInFeature'
import {NOTE_PREFIX} from './Notes'
import PhotoCameraIcon from '@mui/icons-material/PhotoCamera'
import CameraIcon from '../../assets/icons/Camera.svg'
import ShareIcon from '../../assets/icons/Share.svg'
import DeleteIcon from '../../assets/icons/Delete.svg'
import SynchIcon from '../../assets/icons/Synch.svg'
import PlaceMarkIcon from '../../assets/icons/PlaceMark.svg'
import {usePlaceMark} from '../../hooks/usePlaceMark'
import {useExistInFeature} from '../../hooks/useExistInFeature'


/**
Expand Down Expand Up @@ -293,8 +294,10 @@ const CardFooter = ({
deleteNote,
removeComment,
isComment,
synched}) => {
synched,
}) => {
const [shareIssue, setShareIssue] = useState(false)
const viewer = useStore((state) => state.viewer)
const repository = useStore((state) => state.repository)
const toggleSynchSidebar = useStore((state) => state.toggleSynchSidebar)
const accessToken = useStore((state) => state.accessToken)
Expand All @@ -305,6 +308,8 @@ const CardFooter = ({
const {user} = useAuth0()
const {togglePlaceMarkActive} = usePlaceMark()
const existPlaceMarkInFeature = useExistInFeature('placemark')
const isScreenshotEnabled = useExistInFeature('screenshot')
const [screenshotUri, setScreenshotUri] = useState(null)


return (
Expand Down Expand Up @@ -407,6 +412,20 @@ const CardFooter = ({
icon={<SynchIcon style={{width: '15px', height: '15px'}}/>}
/>
}
{isScreenshotEnabled && screenshotUri &&
<img src={screenshotUri} width="40" height="40" alt="screenshot"/>
}
{isScreenshotEnabled &&
<TooltipIconButton
title='Take Screenshot'
size='small'
placement='bottom'
onClick={() => {
setScreenshotUri(viewer.takeScreenshot())
}}
icon={<PhotoCameraIcon style={{width: '15px', height: '15px'}}/>}
/>
}
{numberOfComments > 0 &&
<Box
sx={{
Expand Down
17 changes: 17 additions & 0 deletions src/Infrastructure/IfcViewerAPIExtended.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,21 @@ export class IfcViewerAPIExtended extends IfcViewerAPI {
const ifcManager = this.IFC
return ifcManager.loader.ifcManager.getExpressId(mesh.geometry, picked.faceIndex)
}


/**
* Uses the internal renderer to take screenshot of current scene.
*
* The image may be fetched to bytes with:
*
* const res = await fetch(dataURI)
* const img = await res.blob()
*
* @return {string}
*/
takeScreenshot() {
const renderer = this.context.renderer
const dataURI = renderer.newScreenshot()
return dataURI
}
}