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

Added feature to indicate the user if the content JSON is exploitable… #366

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 2 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
13 changes: 13 additions & 0 deletions src/containers/Editor/BottomBar.tsx
Expand Up @@ -11,6 +11,7 @@ import {
AiOutlineLock,
AiOutlineUnlock,
} from "react-icons/ai";
import { AiOutlineSafetyCertificate } from "react-icons/ai";
import { MdOutlineCheckCircleOutline } from "react-icons/md";
import { TbTransform } from "react-icons/tb";
import {
Expand Down Expand Up @@ -114,11 +115,16 @@ export const BottomBar = () => {
const getFormat = useFile(state => state.getFormat);
const [isPrivate, setIsPrivate] = React.useState(false);
const [isUpdating, setIsUpdating] = React.useState(false);
const contents = useFile(state => state.contents);
Copy link
Owner

Choose a reason for hiding this comment

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

Each time the contents in updated it will cause a rerender which is a performance concern for us. Instead we could make our calculations with in useFile(state => ...) to prevent rerender and only when the value is changed, referred as exploitable.


React.useEffect(() => {
setIsPrivate(data?.private ?? true);
}, [data]);

const isNotExploitableJson = (contentString: string): boolean => {
return contentString[0] !== "[" && contentString[contentString.length - 1] !== "]";
};

const handleSaveJson = React.useCallback(async () => {
if (!user) return setVisible("login")(true);

Expand Down Expand Up @@ -273,6 +279,13 @@ export const BottomBar = () => {
Transform
</StyledBottomBarItem>
)}

{isNotExploitableJson(contents) && (
<StyledBottomBarItem>
<AiOutlineSafetyCertificate />
JSON is not exploitable
</StyledBottomBarItem>
)}
Copy link
Owner

Choose a reason for hiding this comment

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

It's better to show the warning when it's exploitable instead of not exploitable.

Copy link
Owner

Choose a reason for hiding this comment

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

Also we could use "Exploitable" instead of "JSON is exploitable" so it will consume less space.

</StyledLeft>

<StyledRight>
Expand Down