Skip to content

Commit 37582f6

Browse files
authored
Merge pull request #10 from tsully/reusable
New canvas rendering logic and useReducer for state management
2 parents 609e037 + 8987e4b commit 37582f6

19 files changed

+937
-195
lines changed

src/HTMLTypes.ts

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import { HTMLType } from './interfaces/InterfacesNew';
2+
3+
import ImageIcon from '@material-ui/icons/Image';
4+
import ParagraphIcon from '@material-ui/icons/LocalParking';
5+
import FormIcon from '@material-ui/icons/Description';
6+
import HeaderIcon from '@material-ui/icons/TextFormat';
7+
import ButtonIcon from '@material-ui/icons/EditAttributes';
8+
import LinkIcon from '@material-ui/icons/Link';
9+
import ListIcon from '@material-ui/icons/List';
10+
11+
const HTMLTypes: HTMLType[] = [
12+
{
13+
id: 1,
14+
tag: 'img',
15+
name: 'Image',
16+
style: {},
17+
placeHolderShort: '',
18+
placeHolderLong: '',
19+
icon: ImageIcon
20+
},
21+
{
22+
id: 2,
23+
tag: 'form',
24+
name: 'Form',
25+
style: {},
26+
placeHolderShort: '',
27+
placeHolderLong: '',
28+
icon: FormIcon
29+
},
30+
{
31+
id: 3,
32+
tag: 'li',
33+
name: 'List',
34+
style: { color: 'purple' },
35+
placeHolderShort: 'This is a list',
36+
placeHolderLong: '',
37+
icon: ListIcon
38+
},
39+
{
40+
id: 4,
41+
tag: 'button',
42+
name: 'Button',
43+
style: {},
44+
placeHolderShort: '',
45+
placeHolderLong: '',
46+
icon: ButtonIcon
47+
},
48+
{
49+
id: 6,
50+
tag: 'a',
51+
name: 'Link',
52+
style: {},
53+
placeHolderShort: '',
54+
placeHolderLong: '',
55+
icon: LinkIcon
56+
},
57+
{
58+
id: 8,
59+
tag: 'p',
60+
name: 'Paragraph',
61+
style: {},
62+
placeHolderShort: '',
63+
placeHolderLong: '',
64+
icon: ParagraphIcon
65+
},
66+
{
67+
id: 9,
68+
tag: 'h1',
69+
name: 'Header 1',
70+
style: {},
71+
placeHolderShort: '',
72+
placeHolderLong: '',
73+
icon: HeaderIcon
74+
},
75+
{
76+
id: 10,
77+
tag: 'h2',
78+
name: 'Header 2',
79+
style: {},
80+
placeHolderShort: '',
81+
placeHolderLong: '',
82+
icon: HeaderIcon
83+
},
84+
{
85+
id: 11,
86+
tag: 'div',
87+
name: 'Div',
88+
style: {},
89+
placeHolderShort: '',
90+
placeHolderLong: '',
91+
icon: HeaderIcon
92+
}
93+
];
94+
95+
export default HTMLTypes;

src/components/AppNew.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
import React, { useState } from 'react';
1+
import React, { useState, useReducer } from 'react';
22
import '../public/styles/style.css';
33
import '../public/styles/styleNew.css';
44
import { DndProvider } from 'react-dnd';
55
import { HTML5Backend } from 'react-dnd-html5-backend';
66
import AppContainer from '../containers/AppContainer';
77
import { initialState, stateContext } from '../context/context';
8-
// import { Context } from '../interfaces/InterfacesNew';
8+
import reducer from '../reducers/componentReducerNew';
9+
// import { Context, State } from '../interfaces/InterfacesNew';
910

1011
// Intermediary component to wrap main App component with higher order provider components
1112
export const App = (): JSX.Element => {
12-
const [context, setContext] = useState(initialState);
13+
// const [context, setContext] = useState(initialState);
14+
const [state, dispatch] = useReducer(reducer, initialState);
1315
return (
1416
<div className="app">
1517
<DndProvider backend={HTML5Backend}>
@@ -18,7 +20,7 @@ export const App = (): JSX.Element => {
1820
>
1921
ReacType
2022
</header>
21-
<stateContext.Provider value={[context, setContext]}>
23+
<stateContext.Provider value={[state, dispatch]}>
2224
<AppContainer />
2325
</stateContext.Provider>
2426
</DndProvider>

src/components/left/ComponentPanelItemNew.tsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@ import Grid from '@material-ui/core/Grid';
44
import { useDrag } from 'react-dnd';
55
import { ItemTypes } from '../../constants/ItemTypes';
66

7-
const ComponentPanelItem: React.FC<{name: String, id: Number, root: Boolean, focusClick: any}> = ({name, id, root, focusClick}) => {
7+
const ComponentPanelItem: React.FC<{
8+
name: String;
9+
id: Number;
10+
root: Boolean;
11+
focusClick: any;
12+
}> = ({ name, id, root, focusClick }) => {
813
// useDrag hook allows components in left panel to be drag source
914
const [{ isDragging }, drag] = useDrag({
1015
item: {
1116
type: ItemTypes.INSTANCE,
1217
newInstance: true,
13-
category: 'Component',
14-
name,
15-
id
18+
instanceType: 'Component',
19+
instanceId: id
1620
},
1721
canDrag: !root,
1822
collect: (monitor: any) => ({
@@ -31,15 +35,17 @@ const ComponentPanelItem: React.FC<{name: String, id: Number, root: Boolean, foc
3135
// minWidth: '340px',
3236
height: '80px',
3337
marginBottom: '15px',
34-
border: root ? '2px dotted rgba(255,255,255, 0.45)' : '2px solid rgba(255,255,255, 1)',
35-
borderRadius: root ? '' : '8px',
38+
border: root
39+
? '2px dotted rgba(255,255,255, 0.45)'
40+
: '2px solid rgba(255,255,255, 1)',
41+
borderRadius: root ? '' : '8px'
3642
}}
3743
>
38-
39-
<div className="compPanelItem" onClick={focusClick}>
40-
<h3>{id} {name}</h3>
44+
<div className="compPanelItem" onClick={focusClick}>
45+
<h3>
46+
{id} {name}
47+
</h3>
4148
</div>
42-
4349
</Grid>
4450
);
4551
};

0 commit comments

Comments
 (0)