Skip to content

Commit 4bb2edd

Browse files
authored
Merge pull request #39 from oslabs-beta/RachCleanup2
Helper & Redux folder cleanup
2 parents 6013202 + 62f5fee commit 4bb2edd

File tree

11 files changed

+25
-41
lines changed

11 files changed

+25
-41
lines changed

app/src/helperFunctions/auth.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
const fetch = require('node-fetch');
22
const isDev = process.env.NODE_ENV === 'development';
33
const { DEV_PORT, API_BASE_URL } = require('../../../config');
4+
45
let serverURL = API_BASE_URL;
6+
7+
//checks if we're in dev mode or not to reset the serverURL to localhost:8080
58
if (isDev) {
69
serverURL = `http://localhost:${DEV_PORT}`;
710
}
11+
812
export const sessionIsCreated = (
913
username: string,
1014
password: string,
@@ -37,6 +41,7 @@ export const sessionIsCreated = (
3741
.catch((err) => 'Error');
3842
return result;
3943
};
44+
4045
export const newUserIsCreated = (
4146
username: string,
4247
email: string,

app/src/helperFunctions/cssRefresh.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Removes old link to css and creates a new stylesheet link on demo render
2+
// this is not currently being used for the website version
23
const cssRefresher = () => {
34
const oldStylesheet = document.getElementById('Render Stylesheet')
45
console.log(oldStylesheet);

app/src/helperFunctions/generateCode.ts

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -468,33 +468,8 @@ const generateUnformattedCode = (
468468
);`
469469
generatedCode += `\n}`;
470470
return generatedCode;
471-
// return `${`import React, { useState, useEffect, useContext} from 'react';`}
472-
// ${currComponent.name === 'App' ? contextImports : ''}
473-
// ${
474-
// importReactRouter
475-
// ? `import { BrowserRouter as Router, Route, Switch, Link } from 'react-router-dom';`
476-
// : ``
477-
// }
478-
// ${createContextImport()}
479-
// ${importsMapped}
480-
// ${`const ${currComponent.name} = (props) => {`}
481-
// ${createUseContextHook()}
482-
// ${`${writeStateProps(currComponent.useStateCodes)}`}
483-
// // ------------------------------------------- added code below -------------------------------------------
484-
// ${createEventHandler()}
485-
// // ------------------------------------------- added code above -------------------------------------------
486-
487-
// return(
488-
// <>
489-
// ${createRender()}
490-
// </>
491-
// );
492-
// ${`}\n`}
493-
// export default ${currComponent.name}
494-
// `;
495471
}
496-
//
497-
// next.js component code
472+
498473
else if (projectType === 'Next.js') {
499474
return `
500475
import React, { useState } from 'react';
@@ -549,8 +524,6 @@ const generateUnformattedCode = (
549524
};
550525
// formats code with prettier linter
551526
const formatCode = (code: string) => {
552-
// in test environment, window.api is not defined,
553-
// so we reference original prettier format function instead
554527
if (process.env.NODE_ENV === 'test') {
555528
const { format } = require('prettier');
556529
return format(code, {
@@ -560,8 +533,6 @@ const formatCode = (code: string) => {
560533
jsxBracketSameLine: true,
561534
parser: 'babel'
562535
});
563-
// } else if (process.env.NODE_ENV === 'production') {
564-
// return window.api.formatCode(code);
565536
} else {
566537
return code;
567538
}

app/src/helperFunctions/projectGetSaveDel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { letterSpacing } from '@mui/system';
2-
31
const isDev = process.env.NODE_ENV === 'development';
42
const { DEV_PORT, API_BASE_URL } = require('../../../config.js');
53
let serverURL = API_BASE_URL;
64

5+
//check if we're in dev mode
76
if (isDev) {
87
serverURL = `http://localhost:${DEV_PORT}`;
98
}
9+
1010
export const getProjects = (): Promise<any> => {
1111
let userId = window.localStorage.getItem('ssid');
1212
const body = JSON.stringify({ userId });

app/src/helperFunctions/renderChildren.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import React, { useContext } from 'react';
1+
import React from 'react';
22
import { ChildElement } from '../interfaces/Interfaces';
33
import DirectChildComponent from '../components/main/DirectChildComponent';
44
import DirectChildHTML from '../components/main/DirectChildHTML';
55
import DirectChildHTMLNestable from '../components/main/DirectChildHTMLNestable';
66
import SeparatorChild from '../components/main/SeparatorChild';
77
import RouteLink from '../components/main/RouteLink';
8-
import StateContext from '../context/context';
98
import { useSelector } from 'react-redux';
9+
import { RootState } from '../redux/store';
1010

1111
// helper method to render all direct children of a component
1212
// direct children are clickable and draggable
1313
// direct children may also have their own indirect children (grandchildren, great-grandchildren, etc) which are not draggable and clickable
1414
// there are four types of direct children that can be rendered on the screen
1515
const renderChildren = (children: ChildElement[]) => {
16-
const state = useSelector(store => store.appState)
16+
const state = useSelector((store: RootState) => store.appState)
1717

1818
return children.map((child: ChildElement, i: number) => {
1919
const { type, style, childId, children, attributes, name } = child;

app/src/helperFunctions/zipFiles.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
import { saveAs } from 'file-saver';
22
const JSZip = require("jszip");
33

4+
//function to create a zip file for export in web app
45
const zipFiles = (state) => {
6+
//initializes zip
57
var zip = new JSZip();
68
let reacTypeApp = zip.folder('ReacTypeApp');
9+
//creates component folder inside of zip folder
710
let componentFolder = reacTypeApp.folder('componentfolder');
11+
//writes a file with default index.html code
812
reacTypeApp.file('index.html', '<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <link rel="stylesheet" href="styles.css"> <title>ReacType App</title> </head> <body> <div id="root"></div> </body> </html>');
13+
//writes each component as its own file in the component folder
914
for (let i in state.components){
1015
componentFolder.file(`${state.components[i].name}.jsx`, state.components[i].code);
1116
}
17+
//writes our css file if we have a css file stored in local storage
1218
if(localStorage.getItem('css')){
1319
reacTypeApp.file('style.css', localStorage.getItem('css'));
1420
}
21+
//zips the file and saves to local machine
1522
zip.generateAsync({type:"blob"})
1623
.then(function(content) {
1724
// see FileSaver.js

app/src/redux/HTMLTypes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import {
99
HTMLType
1010
} from '../interfaces/Interfaces';
1111

12+
//properties for all HTML components
13+
1214
const HTMLTypes: HTMLType[] = [
1315
{
1416
id: 11,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ const initialState = {
55
input: ``
66
};
77

8+
//realtime updates for the code preview
9+
810
const codePreviewSlice = createSlice({
911
name: 'codePreview',
1012
initialState,

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
2-
// import type { RootState } from '../redux/store';
32

43
// -------------------------//
54
// interfaces for all methods // calling actions payloads type referencss assigning type // typesccript

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ const initialState = {
77
isThemeLight: null,
88
}
99

10+
//allows us to set style for themes
11+
1012
const styleSlice = createSlice({
1113
name: 'style',
1214
initialState,

app/src/redux/store.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,7 @@ const store = configureStore({
2323

2424
return getDefaultMiddleware({
2525
serializableCheck: {
26-
// Ignore the `configToggle` action type
27-
// ignoredActions: ['configToggle'],
28-
// Ignore these field paths in all actions
29-
// ignoredActionPaths: ['meta.arg', 'payload.timestamp'],
3026
// Ignore these paths in the state
31-
// ignoredPaths: ignoredPaths,
3227
ignoredPaths
3328
}
3429
});

0 commit comments

Comments
 (0)