-
Notifications
You must be signed in to change notification settings - Fork 592
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
looker 3d improvements #4226
Merged
Merged
looker 3d improvements #4226
Changes from all commits
Commits
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
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
app/packages/looker-3d/src/action-bar/FullScreenToggler.tsx
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,39 @@ | ||
import { fullscreen, fullscreenExit } from "@fiftyone/looker/src/icons"; | ||
import * as fos from "@fiftyone/state"; | ||
import { IconButton } from "@mui/material"; | ||
import { useCallback, useEffect, useRef } from "react"; | ||
import { useRecoilState } from "recoil"; | ||
import { ActionItem } from "../containers"; | ||
|
||
const FullScreenIcon = ({ exit }: { exit: boolean }) => { | ||
const ref = useRef<HTMLDivElement>(); | ||
|
||
useEffect(() => { | ||
if (ref) { | ||
ref.current.innerHTML = ""; | ||
ref.current.appendChild(exit ? fullscreenExit : fullscreen); | ||
} | ||
}, [exit]); | ||
|
||
return <div style={{ display: "flex" }} ref={ref} />; | ||
}; | ||
|
||
export const FullScreenToggler = () => { | ||
const [isFullScreen, setIsFullScreen] = useRecoilState(fos.fullscreen); | ||
|
||
const toggleFullScreen = useCallback(() => { | ||
setIsFullScreen((prev) => !prev); | ||
}, []); | ||
|
||
return ( | ||
<ActionItem title="Toggle Fullscreen"> | ||
<IconButton onClick={toggleFullScreen} sx={{ fontSize: 24, padding: 0 }}> | ||
{isFullScreen ? ( | ||
<FullScreenIcon exit /> | ||
) : ( | ||
<FullScreenIcon exit={false} /> | ||
)} | ||
</IconButton> | ||
</ActionItem> | ||
); | ||
}; |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactor the
FullScreenIcon
component to use conditional rendering instead of direct DOM manipulation for better alignment with React best practices.This change eliminates the need for
useRef
anduseEffect
for DOM manipulation, leveraging React's declarative nature for UI updates.Committable suggestion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this doesn't work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sashankaryal, it seems there was an issue locating the
icons.ts
file or extracting the implementation details of thefullscreen
andfullscreenExit
icons using the provided script. This could be due to a variety of reasons, such as the file not existing where expected or the icons being imported from an external library that isn't directly accessible in this manner.Given this, I'd like to suggest a couple of alternative approaches to address the original concern with the
FullScreenIcon
component:Verify Icon Import Method: Ensure that the
fullscreen
andfullscreenExit
icons are imported correctly and can be rendered directly in JSX. If these icons are SVGs or React components, they should be able to be included directly within the JSX return statement without needing to manipulate the DOM.Alternative Rendering Strategy: If the icons are not directly renderable in JSX (for example, if they are SVG elements stored as strings or files), consider using a method to safely convert them into a format that can be rendered. This could involve using a library or utility function designed for this purpose.
Revisit Original Implementation: If direct DOM manipulation is indeed necessary due to the specific requirements or limitations of how these icons are implemented, it may be worth revisiting the original implementation. In such cases, ensuring that the manipulation is done as safely and efficiently as possible within the React component lifecycle is important.
Without direct access to the implementation details of the icons, these suggestions are based on common practices and potential scenarios. If you have more information about how these icons are implemented or if there's a specific error or issue encountered with the suggested refactor, please let me know, and I can provide further assistance.
Analysis chain
Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 53