Skip to content

Commit

Permalink
feat(web): layer style node system (#1143)
Browse files Browse the repository at this point in the history
Co-authored-by: airslice <[email protected]>
  • Loading branch information
mkumbobeaty and airslice authored Oct 1, 2024
1 parent 67cad92 commit 16722ac
Show file tree
Hide file tree
Showing 37 changed files with 1,753 additions and 280 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { CodeInput } from "@reearth/beta/lib/reearth-ui";
import { LayerStyle } from "@reearth/services/api/layerStyleApi/utils";
import { styled } from "@reearth/services/theme";
import { SetStateAction } from "jotai";
import { Dispatch, FC, useCallback, useEffect, useState } from "react";

import NoStyleMessage from "../NoStyleMessage";

type CodeProps = {
layerStyle: LayerStyle | undefined;
setLayerStyle: Dispatch<SetStateAction<LayerStyle | undefined>>;
};

const StyleCode: FC<CodeProps> = ({ layerStyle, setLayerStyle }) => {
const [styleCode, setStyleCode] = useState<string | undefined>("");

useEffect(() => {
setStyleCode(JSON.stringify(layerStyle?.value, null, 2));
}, [layerStyle]);

const handleStyleCodeChange = useCallback(
(newStyleCode?: string) => {
try {
const parsedStyle = JSON.parse(newStyleCode || "");
setLayerStyle((prev) => {
if (!prev?.id) return prev;
return {
...prev,
value: parsedStyle
};
});
} catch (_error) {
// Do nothing
}

setStyleCode(newStyleCode);
},
[setLayerStyle]
);

return layerStyle?.id ? (
<CodeWrapper>
<CodeInput
value={styleCode}
onChange={handleStyleCodeChange}
language="json"
showLines={false}
/>
</CodeWrapper>
) : (
<NoStyleMessage />
);
};

export default StyleCode;

const CodeWrapper = styled("div")(({ theme }) => ({
padding: theme.spacing.small,
height: "100%"
}));
Loading

0 comments on commit 16722ac

Please sign in to comment.