-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(web): add layer from resource (#1212)
Co-authored-by: airslice <[email protected]>
- Loading branch information
1 parent
cf1bd0e
commit 3016a71
Showing
13 changed files
with
493 additions
and
128 deletions.
There are no files selected for viewing
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
63 changes: 63 additions & 0 deletions
63
web/src/beta/features/Editor/Map/DataSourceLayerCreator/CZML/hooks.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,63 @@ | ||
import { useT } from "@reearth/services/i18n"; | ||
import { useState, useMemo, useCallback } from "react"; | ||
|
||
import { DataProps, DataSourceOptType, SourceType } from ".."; | ||
import { generateTitle } from "../util"; | ||
|
||
export default ({ sceneId, onClose, onSubmit }: DataProps) => { | ||
const t = useT(); | ||
|
||
const [sourceType, setSourceType] = useState<SourceType>("local"); | ||
|
||
const [value, setValue] = useState(""); | ||
const [layerName, setLayerName] = useState(""); | ||
const dataSourceTypeOptions: DataSourceOptType = useMemo( | ||
() => [ | ||
{ label: t("From Assets"), value: "local" }, | ||
{ label: t("From Web"), value: "url" }, | ||
{ label: t("From Value"), value: "value" } | ||
], | ||
[t] | ||
); | ||
|
||
const handleSubmit = () => { | ||
let encodeUrl = undefined; | ||
|
||
if (sourceType === "value" && value !== "") { | ||
encodeUrl = "data:text/plain;charset=UTF-8," + encodeURIComponent(value); | ||
} | ||
|
||
onSubmit({ | ||
layerType: "simple", | ||
sceneId, | ||
title: generateTitle(value, layerName), | ||
visible: true, | ||
config: { | ||
data: { | ||
url: sourceType === "value" ? encodeUrl : value || undefined, | ||
type: "czml", | ||
} | ||
} | ||
}); | ||
onClose(); | ||
}; | ||
|
||
const handleValueChange = useCallback((value?: string, name?: string) => { | ||
setValue(value || ""); | ||
setLayerName(name || ""); | ||
}, []); | ||
|
||
const handleDataSourceTypeChange = useCallback((newValue: string) => { | ||
setSourceType(newValue as SourceType); | ||
setValue(""); | ||
}, []); | ||
|
||
return { | ||
value, | ||
dataSourceTypeOptions, | ||
sourceType, | ||
handleValueChange, | ||
handleDataSourceTypeChange, | ||
handleSubmit | ||
}; | ||
}; |
124 changes: 124 additions & 0 deletions
124
web/src/beta/features/Editor/Map/DataSourceLayerCreator/CZML/index.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,124 @@ | ||
import { | ||
InputGroup, | ||
SubmitWrapper, | ||
Wrapper, | ||
InputsWrapper, | ||
ContentWrapper | ||
} from "@reearth/beta/features/Editor/Map/shared/SharedComponent"; | ||
import { | ||
RadioGroup, | ||
Button, | ||
TextInput, | ||
TextArea, | ||
Icon | ||
} from "@reearth/beta/lib/reearth-ui"; | ||
import { AssetField } from "@reearth/beta/ui/fields"; | ||
import { useT } from "@reearth/services/i18n"; | ||
import { styled, useTheme } from "@reearth/services/theme"; | ||
import { FC } from "react"; | ||
|
||
import { DataProps } from ".."; | ||
|
||
import useHooks from "./hooks"; | ||
|
||
const CZML: FC<DataProps> = ({ sceneId, onSubmit, onClose }) => { | ||
const t = useT(); | ||
|
||
const { | ||
value, | ||
sourceType, | ||
dataSourceTypeOptions, | ||
handleValueChange, | ||
handleDataSourceTypeChange, | ||
handleSubmit | ||
} = useHooks({ sceneId, onSubmit, onClose }); | ||
|
||
const theme = useTheme(); | ||
return ( | ||
<Wrapper> | ||
<ContentWrapper> | ||
<Warning> | ||
<IconWrapper | ||
icon="lightBulb" | ||
color={theme.warning.main} | ||
size="normal" | ||
/> | ||
<TextWrapper> | ||
{t( | ||
"Support for the CZML format is currently experimental and remains somewhat unstable, with certain features not yet fully supported. We advise using it with caution." | ||
)} | ||
</TextWrapper> | ||
</Warning> | ||
<InputGroup label={t("Source Type")}> | ||
<RadioGroup | ||
value={sourceType} | ||
options={dataSourceTypeOptions} | ||
onChange={handleDataSourceTypeChange} | ||
/> | ||
</InputGroup> | ||
|
||
{sourceType === "local" && ( | ||
<InputsWrapper> | ||
<AssetField | ||
inputMethod="asset" | ||
title={t("Asset")} | ||
value={value} | ||
assetsTypes={["czml"]} | ||
onChange={handleValueChange} | ||
/> | ||
</InputsWrapper> | ||
)} | ||
{sourceType === "url" && ( | ||
<InputGroup label={t("Resource URL")}> | ||
<InputsWrapper> | ||
<TextInput | ||
placeholder={t("Input Text")} | ||
value={value} | ||
onChange={handleValueChange} | ||
/> | ||
</InputsWrapper> | ||
</InputGroup> | ||
)} | ||
{sourceType === "value" && ( | ||
<InputGroup label={t("Value")}> | ||
<InputsWrapper> | ||
<TextArea | ||
placeholder={t("Input data here")} | ||
rows={8} | ||
value={value} | ||
onChange={handleValueChange} | ||
/> | ||
</InputsWrapper> | ||
</InputGroup> | ||
)} | ||
</ContentWrapper> | ||
<SubmitWrapper> | ||
<Button | ||
title={t("Add to Layer")} | ||
appearance="primary" | ||
onClick={handleSubmit} | ||
disabled={!value} | ||
/> | ||
</SubmitWrapper> | ||
</Wrapper> | ||
); | ||
}; | ||
|
||
const Warning = styled("div")(({ theme }) => ({ | ||
display: "flex", | ||
gap: theme.spacing.small, | ||
alignItems: "center" | ||
})); | ||
|
||
const IconWrapper = styled(Icon)(() => ({ | ||
flexGrow: 0, | ||
flexShrink: 0 | ||
})); | ||
|
||
const TextWrapper = styled("div")(({ theme }) => ({ | ||
color: theme.warning.main, | ||
fontSize: theme.fonts.sizes.body, | ||
fontWeight: theme.fonts.weight.regular | ||
})); | ||
|
||
export default CZML; |
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.