Skip to content

Commit 7b0b96f

Browse files
Merge pull request #25 from MadinventorZero/projectsave
Projectsave
2 parents 0b62141 + dce5e65 commit 7b0b96f

File tree

11 files changed

+70
-40
lines changed

11 files changed

+70
-40
lines changed

app/src/components/App.tsx

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ export const App = (): JSX.Element => {
1919
} else {
2020
state.isLoggedIn = false;
2121
}
22-
22+
23+
2324
// following useEffect runs on first mount
2425
useEffect(() => {
2526
// if user is a guest, see if a project exists in localforage and retrieve it
@@ -51,26 +52,46 @@ export const App = (): JSX.Element => {
5152
} else {
5253
console.log(
5354
'No user project found in localforage, setting initial state blank'
54-
);
55-
}
56-
});
57-
}
58-
}, []);
59-
55+
);
56+
}
57+
});
58+
}
59+
}, []);
60+
61+
// Caret Start Updated save cycle
6062
useEffect(() => {
61-
let userId;
62-
if (Cookies.get('ssid')) {
63-
userId = Cookies.get('ssid');
64-
} else {
65-
userId = window.localStorage.getItem('ssid');
63+
console.log('Legacy state', state);
64+
// provide config properties to legacy projects so new edits can be auto saved
65+
if (state.config === undefined) {
66+
state.config = {saveFlag:true, saveTimer:false};
67+
};
68+
console.log('Updated state for legacy projects', state);
69+
// New project save configuration to optimize server load and minimize Ajax requests
70+
if (state.config.saveFlag) {
71+
state.config.saveFlag = false;
72+
state.config.saveTimer = true;
73+
let userId;
74+
if (Cookies.get('ssid')) {
75+
userId = Cookies.get('ssid');
76+
} else {
77+
userId = window.localStorage.getItem('ssid');
78+
}
79+
if (state.isLoggedIn === false) {
80+
localforage.setItem('guestProject', state);
81+
} else if (state.name !== '') {
82+
saveProject(state.name, state);
83+
localforage.setItem(userId, state);
84+
}
6685
}
67-
if (state.isLoggedIn === false) {
68-
localforage.setItem('guestProject', state);
69-
} else if (state.name !== '') {
70-
saveProject(state.name, state);
71-
localforage.setItem(userId, state);
86+
if (state.config.saveTimer) {
87+
state.config.saveTimer = false;
88+
setTimeout(() => {
89+
state.config.saveFlag = true;
90+
}, 15000);
7291
}
73-
}, [state]);
92+
}, [state])
93+
// Caret End
94+
7495

7596
return (
7697
<div className="app">

app/src/components/bottom/BottomTabs.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const BottomTabs = () => {
4040
setTheme(e.target.value);
4141
};
4242

43-
console.log("Editor Theme: ", theme);
43+
// console.log("Editor Theme: ", theme);
4444

4545
return (
4646
<div className={classes.root} style={style}>

app/src/components/bottom/CodePreview.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ const CodePreview: React.FC<{
3434
useEffect(() => {
3535
setDivHeight(height);
3636
}, [height])
37-
3837
return (
3938
<div
4039
ref={wrapper}

app/src/components/form/Selector.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import MenuItem from '@material-ui/core/MenuItem';
66

77
const FormSelector = (props): JSX.Element => {
88
const items = [];
9+
let key = 1;
910
props.items.forEach(el => {
10-
items.push(<MenuItem value={el.value}>{el.text}</MenuItem>);
11+
items.push(<MenuItem value={el.value} key={`menu${key}`}>{el.text}</MenuItem>);
12+
key++
1113
})
1214
return (
1315
<div className={props.classes.configRow}>

app/src/components/main/Annotation.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ function Annotation({
4242
*/
4343
const handleAnnoChange = (event) => {
4444
const { value } = event.target;
45-
4645
if (value === '' || value === undefined) {
4746
ref.current.style.background = '#3ec1ac';
4847
} else {
@@ -73,7 +72,7 @@ function Annotation({
7372
}
7473
}
7574
return '';
76-
}
75+
};
7776

7877
/**
7978
* This useEffect allows the annotations to remain persistent when changing between root level components on the right panel

app/src/components/right/ComponentPanel.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,13 @@ const ComponentPanel = ({isThemeLight}): JSX.Element => {
148148
color={'primary'}
149149
variant="outlined"
150150
className={isThemeLight ? `${classes.inputField} ${classes.lightThemeFontColor}` : `${classes.inputField} ${classes.darkThemeFontColor}`}
151-
InputProps={{ className: classes.input }}
151+
// Caret inputprops and helpertext must be lowercase
152+
inputprops={{ className: classes.input }}
152153
value={compName}
153-
error={errorStatus}
154-
helperText={errorStatus ? errorMsg : ''}
154+
// Doesn't accept boolean value needs to be a string
155+
error={errorStatus.toString()}
156+
// Updated
157+
helpertext={errorStatus ? errorMsg : ''}
155158
onChange={handleNameInput}
156159
/>
157160
</div>

app/src/context/initialState.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import HTMLTypes from './HTMLTypes';
55
const initialState: State = {
66
name: '',
77
isLoggedIn: false,
8+
// CARET
9+
config: { saveFlag: true, saveTimer: false },
10+
// END CARET
811
components: [
912
{
1013
id: 1,

app/src/helperFunctions/renderChildren.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ const renderChildren = (children: ChildElement[]) => {
1818
if (name === '') child.name = state.components[typeId - 1].name;
1919
// A DirectChildComponent is an instance of a top level component
2020
// This component will render IndirectChild components (div/components rendered inside a child component)
21-
// Caret Start Removed style from prop drills so that styling isn't applied to canvas items
21+
// Caret Start Removed style from prop drills so that styling isn't applied to canvas items.
22+
// Also added keys & removed an unnecessary div around DirChildNestables that were causing errors.
2223
if (type === 'Component') {
2324
return (
2425
<DirectChildComponent
2526
childId={childId}
2627
type={type}
2728
typeId={typeId}
28-
key={'DirChildComp' + childId.toString() + name}
29+
key={'DirChildComp' + childId.toString() + name + (Math.random()*1000).toString()}
2930
name={name}
3031
annotations={annotations}
3132
/>
@@ -39,7 +40,7 @@ const renderChildren = (children: ChildElement[]) => {
3940
childId={childId}
4041
type={type}
4142
typeId={typeId}
42-
key={'DirChildHTML' + childId.toString() + name}
43+
key={'DirChildHTML' + childId.toString() + name + (Math.random()*1000).toString()}
4344
name={name}
4445
annotations={annotations}
4546
/>
@@ -48,17 +49,16 @@ const renderChildren = (children: ChildElement[]) => {
4849
// Caret Added Orderedlists, Unorderedlists, and Menus, changed lists to nestable because they are nestable.
4950
// child is a nestable type of HTML element (divs and forms)
5051
else if (type === 'HTML Element' && (typeId === 11 || typeId === 2 || typeId === 3 || typeId === 14 || typeId === 15 || typeId === 16)) {
51-
return ( <div>
52+
return (
5253
<DirectChildHTMLNestable
5354
childId={childId}
5455
type={type}
5556
typeId={typeId}
5657
children={children}
57-
key={'DirChildHTMLNest' + childId.toString() + name}
58+
key={'DirChildHTMLNest' + childId.toString() + name + (Math.random()*1000).toString()}
5859
name={name}
5960
annotations={annotations}
6061
/>
61-
</div>
6262
);
6363
}
6464
else if (type === 'HTML Element' && typeId === 1000 ) {
@@ -68,7 +68,7 @@ const renderChildren = (children: ChildElement[]) => {
6868
type={type}
6969
typeId={typeId}
7070
children={children}
71-
key={'DirChildHTMLNest' + childId.toString() + name}
71+
key={'SeparatorChild' + childId.toString() + name + (Math.random()*1000).toString()}
7272
name={name}
7373
/>
7474
);
@@ -82,7 +82,7 @@ const renderChildren = (children: ChildElement[]) => {
8282
type={type}
8383
typeId={typeId}
8484
children={children}
85-
key={'RouteLink' + childId.toString() + name}
85+
key={'RouteLink' + childId.toString() + name + (Math.random()*1000).toString()}
8686
name={name}
8787
/>
8888
);

app/src/interfaces/Interfaces.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ export interface State {
66
components: Component[];
77
rootComponents: number[];
88
projectType: string;
9+
// Caret
10+
config?: {};
911
separator: ChildElement;
1012
canvasFocus: { componentId: number; childId: number | null };
1113
nextComponentId: number;

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,6 @@
127127
"cors": "^2.8.5",
128128
"d3": "^6.2.0",
129129
"dotenv": "^8.2.0",
130-
"electron": "^9.4.2",
131-
"electron-debug": "^3.1.0",
132-
"electron-devtools-installer": "^2.2.4",
133-
"electron-splashscreen": "^1.0.0",
134-
"electron-window-manager": "^1.0.6",
135130
"enzyme": "^3.4.1",
136131
"enzyme-adapter-react-16": "^1.2.0",
137132
"eslint-plugin-react-hooks": "^4.2.0",
@@ -186,6 +181,11 @@
186181
"csp-html-webpack-plugin": "^4.0.0",
187182
"css-loader": "^2.1.1",
188183
"dotenv-webpack": "^5.0.1",
184+
"electron": "^9.4.2",
185+
"electron-debug": "^3.1.0",
186+
"electron-devtools-installer": "^2.2.4",
187+
"electron-splashscreen": "^1.0.0",
188+
"electron-window-manager": "^1.0.6",
189189
"electron-builder": "^22.7.0",
190190
"enzyme-to-json": "^3.5.0",
191191
"eslint": "^4.19.1",

server/server.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ const isDev = process.env.NODE_ENV === 'development';
1616
const isProd = process.env.NODE_ENV === 'production';
1717
const isTest = process.env.NODE_ENV === 'test';
1818

19-
app.use(express.json());
19+
app.use(express.json({limit: '100mb'}));
20+
app.use(express.urlencoded({limit: '100mb', extended: true }))
2021
app.use(cookieParser());
2122

2223

0 commit comments

Comments
 (0)