Skip to content

Commit 1cd16fd

Browse files
committed
Initial commit
1 parent 177d505 commit 1cd16fd

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

app/src/components/bottom/StylesEditor.tsx

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import 'ace-builds/src-min-noconflict/ext-searchbox';
1111
import Fab from '@mui/material/Fab';
1212
import SaveIcon from '@mui/icons-material/Save';
1313
import cssRefresher from '../../helperFunctions/cssRefresh';
14+
import { updateStylesheet } from '../../redux/reducers/slice/appStateSlice';
15+
import { useDispatch } from 'react-redux';
1416

1517
//This was being used for the demo
1618
// const serverURL = 'https://reactype-caret.herokuapp.com';
@@ -23,11 +25,12 @@ const StylesEditor: React.FC<{
2325
const [css, setCss] = useState();
2426
//now using variable and storing CSS in localStorage to retain CSS upon dismount of the component
2527
let currentCss = localStorage.getItem('css');
26-
28+
const dispatch = useDispatch();
29+
2730
//This was being used for the demo
2831

2932
// useEffect(() => {
30-
// loadFile();
33+
// loadFile();
3134
// }, []);
3235

3336
// const loadFile = () => {
@@ -60,21 +63,22 @@ const StylesEditor: React.FC<{
6063
//refactored this function to store the css on local storage rather than invoke saveFile()
6164
const saveCss = (e) => {
6265
e.preventDefault();
63-
localStorage.setItem('css', currentCss)
64-
}
66+
dispatch(updateStylesheet(currentCss));
67+
localStorage.setItem('css', currentCss);
68+
};
6569

6670
const handleChange = (text) => {
6771
currentCss = text;
68-
}
72+
};
6973

7074
return (
7175
<div
72-
className='text-editor'
76+
className="text-editor"
7377
ref={wrapper}
7478
style={{
7579
height: '100%',
7680
maxWidth: '100%',
77-
justifyContent: 'center',
81+
justifyContent: 'center'
7882
}}
7983
>
8084
<AceEditor
@@ -93,7 +97,12 @@ const StylesEditor: React.FC<{
9397
enableLiveAutocompletion: true
9498
}}
9599
/>
96-
<Fab className='bttn' onClick={saveCss} color="secondary" aria-label="add">
100+
<Fab
101+
className="bttn"
102+
onClick={saveCss}
103+
color="secondary"
104+
aria-label="add"
105+
>
97106
<SaveIcon />
98107
</Fab>
99108
</div>

app/src/interfaces/Interfaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface State {
1515
nextChildId: number;
1616
HTMLTypes: HTMLType[];
1717
tailwind: boolean;
18+
stylesheet: string
1819
}
1920

2021
export interface ChildElement {

app/src/redux/reducers/slice/appStateSlice.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ export const initialState: State = {
3838
nextChildId: 1,
3939
nextTopSeparatorId: 1000,
4040
HTMLTypes: HTMLTypes, // left as is for now
41-
tailwind: false
41+
tailwind: false,
42+
stylesheet: ''
4243
};
4344

4445
let separator = initialState.HTMLTypes[1];
@@ -858,8 +859,8 @@ const appStateSlice = createSlice({
858859
state.canvasFocus = canvasFocus;
859860
},
860861
//deleted 'convertToJSX' function, which threw errors upon opening
861-
openProject: ( state, action) => {
862-
return action.payload
862+
openProject: (state, action) => {
863+
return action.payload;
863864
},
864865
addElement: (state, action) => {
865866
const HTMLTypes = [...state.HTMLTypes];
@@ -1262,6 +1263,10 @@ const appStateSlice = createSlice({
12621263
},
12631264
allCooperativeState: (state, action) => {
12641265
return Object.assign({}, state, action.payload);
1266+
},
1267+
updateStylesheet: (state, action) => {
1268+
console.log('stylesheet', state.stylesheet, 'action', action);
1269+
state.stylesheet = action.payload;
12651270
}
12661271
}
12671272
});
@@ -1301,7 +1306,8 @@ export const {
13011306
toggleLoggedIn,
13021307
//configToggle,
13031308
snapShotAction,
1304-
allCooperativeState
1309+
allCooperativeState,
1310+
updateStylesheet
13051311
} = appStateSlice.actions;
13061312

13071313
// Exports so we can combine in rootReducer

0 commit comments

Comments
 (0)