Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F22404850
body-page-editor.jsx
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
body-page-editor.jsx
View Options
import
React
,
{
useReducer
}
from
'react'
;
import
ElementEditor
from
'./element-editor'
;
import
Preview
from
'./preview'
;
import
SelectComponent
from
'./select-component'
;
import
components_map
from
'../../components/components.map'
;
function
reducer
(
state
,
action
)
{
switch
(
action
.
type
)
{
case
'addElement'
:
return
{
...
state
,
componentToCreate
:
null
,
elements
:
state
.
elements
.
concat
([
[
components_map
[
state
.
componentToCreate
],
{}],
]),
};
case
'setElementProps'
:
state
.
elements
[
action
.
elementIndex
][
1
]
=
action
.
newProps
;
return
{
...
state
,
elements
:
state
.
elements
,
};
case
'setComponentToCreate'
:
return
{
...
state
,
componentToCreate
:
action
.
componentToCreate
,
};
}
}
export
default
function
bodyPageEditor
()
{
const
[
state
,
dispatch
]
=
useReducer
(
reducer
,
{
componentToCreate
:
''
,
elements
:
[],
});
return
(
<
React
.
Fragment
>
<
h2
>
Body
Page
Editor
<
/h2>
<
div
style
=
{{
display
:
'flex'
,
flexFlow
:
'row'
}}
>
{
state
.
elements
.
map
(([
component
,
componentProps
],
index
)
=>
(
<
ElementEditor
key
=
{
index
}
component
=
{
component
}
componentProps
=
{
componentProps
}
onChange
=
{
newProps
=>
dispatch
({
type
:
'setElementProps'
,
elementIndex
:
index
,
newProps
,
})
}
/>
))}
<
Preview
elements
=
{
state
.
elements
}
/>
<
/div>
<
div
>
{
JSON
.
stringify
(
state
.
elements
)}
<
/div>
<
SelectComponent
value
=
{
state
.
componentToCreate
||
''
}
onChange
=
{
value
=>
dispatch
({
type
:
'setComponentToCreate'
,
componentToCreate
:
value
,
})
}
/>
<
button
disabled
=
{
!
state
.
componentToCreate
}
onClick
=
{()
=>
{
dispatch
({
type
:
'addElement'
});
}}
>
Add
element
<
/button>
<
/React.Fragment>
);
}
File Metadata
Details
Attached
Mime Type
application/javascript
Expires
Fri, Nov 27, 19:21 (9 h, 36 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1222648
Default Alt Text
body-page-editor.jsx (1 KB)
Attached To
Mode
rSEALPAGE Sealpage
Attached
Detach File
Event Timeline