Skip to content

Commit

Permalink
Austin 5/3 updated Tutorial, Refactored Electron
Browse files Browse the repository at this point in the history
>
>
Co-author-by: Zack Vandiver <[email protected]>
Co-author-by: Heather Pfeiffer <[email protected]>
Co-author-by: Austin Alvarez <InvectivusTaco>
Co-author-by: Jesse Wowczuk <[email protected]>
  • Loading branch information
InvectivusTaco committed May 3, 2024
2 parents 0ac829c + 902905e commit ab07a9e
Show file tree
Hide file tree
Showing 23 changed files with 6,830 additions and 1,189 deletions.
163 changes: 85 additions & 78 deletions app/src/components/bottom/BottomPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,78 +1,85 @@
import React, { useEffect, useRef, useState } from 'react';
import BottomTabs from './BottomTabs';
import { ExpandLess, ExpandMore } from '@mui/icons-material';

const BottomPanel = (props): JSX.Element => {
let y: number = 0;
let h: number = 0;
const node = useRef() as React.MutableRefObject<HTMLDivElement>;

const [isDragging, setIsDragging] = useState(false);

const mouseDownHandler = (e): void => {
y = e.clientY;

const styles = window.getComputedStyle(node.current);
h = parseInt(styles.height, 10);

document.addEventListener('mousemove', mouseMoveHandler);
document.addEventListener('mouseup', mouseUpHandler);
window.addEventListener('message', handleIframeMessage); //listens for messages from the iframe when the mouse is over it
};

//Interpret the messages from the iframe
const handleIframeMessage = (e) => {
if (e.data === 'iframeMouseUp') {
mouseUpHandler();
} else if (e.data.type === 'iframeMouseMove') {
mouseMoveHandler(e.data);
}
};

const mouseMoveHandler = function (e: MouseEvent): void {
if (!props.bottomShow) return; // prevent drag calculation to occur when bottom menu is not showing

const dy = y - e.clientY;

const newVal = h + dy;
const styles = window.getComputedStyle(node.current);
const min = parseInt(styles.minHeight, 10);
node.current.style.height = newVal > min ? `${h + dy}px` : `${min}px`;
};

const mouseUpHandler = function () {
// puts false in callback queue after OnDragStart sets to true (b/c react 17 doesn't have onDragEnd)
setTimeout(() => setIsDragging(false), 0);
document.removeEventListener('mousemove', mouseMoveHandler);
document.removeEventListener('mouseup', mouseUpHandler);
window.removeEventListener('message', handleIframeMessage);
};

useEffect(() => {
node.current.style.height = '50vh';
node.current.style.minHeight = '50vh';
}, []);

return (
<>
<div className="bottom-panel" id="resize" ref={node}>
<div
id="resize-drag"
onMouseDown={mouseDownHandler}
draggable
onDragStart={() => setIsDragging(true)}
onClick={() => !isDragging && props.setBottomShow(!props.bottomShow)}
tabIndex={0}
>
{props.bottomShow ? <ExpandMore /> : <ExpandLess />}
</div>
<BottomTabs
setBottomShow={props.setBottomShow}
isThemeLight={props.isThemeLight}
/>
</div>
</>
);
};

export default BottomPanel;
import React, { useEffect, useRef, useState } from 'react';
import BottomTabs from './BottomTabs';
import { ExpandLess, ExpandMore } from '@mui/icons-material';

const BottomPanel = (props): JSX.Element => {
let y: number = 0;
let h: number = 0;
const node = useRef() as React.MutableRefObject<HTMLDivElement>;

const [isDragging, setIsDragging] = useState(false);

const mouseDownHandler = (e): void => {
y = e.clientY;

const styles = window.getComputedStyle(node.current);
h = parseInt(styles.height, 10);

document.addEventListener('mousemove', mouseMoveHandler);
document.addEventListener('mouseup', mouseUpHandler);
window.addEventListener('message', handleIframeMessage); //listens for messages from the iframe when the mouse is over it
};

//Interpret the messages from the iframe
const handleIframeMessage = (e) => {
if (e.data === 'iframeMouseUp') {
mouseUpHandler();
} else if (e.data.type === 'iframeMouseMove') {
mouseMoveHandler(e.data);
}
};

const mouseMoveHandler = function (e: MouseEvent): void {
if (!props.bottomShow) return; // prevent drag calculation to occur when bottom menu is not showing

const dy = y - e.clientY;
const newHeight = h + dy;

const styles = window.getComputedStyle(node.current);
const minHeight = parseInt(styles.minHeight, 10);
const maxHeight = window.innerHeight * 0.8; // Set a maximum height, e.g., 90% of window height

node.current.style.height = `${Math.max(minHeight, Math.min(maxHeight, newHeight))}px`;
};

const mouseUpHandler = function () {
// puts false in callback queue after OnDragStart sets to true (b/c react 17 doesn't have onDragEnd)
setTimeout(() => setIsDragging(false), 0);
document.removeEventListener('mousemove', mouseMoveHandler);
document.removeEventListener('mouseup', mouseUpHandler);
window.removeEventListener('message', handleIframeMessage);
};

useEffect(() => {
if (props.bottomShow) {
node.current.style.height = '50vh'; // Initial height when bottom panel is open
node.current.style.minHeight = '20vh'; // Minimum height when bottom panel is open
} else {
node.current.style.height = '0.1'; // Initial height when bottom panel is closed
node.current.style.minHeight = '0.1'; // Minimum height when bottom panel is closed
}
}, [props.bottomShow]);

return (
<>
<div className="bottom-panel" id="resize" ref={node} >
<div
id="resize-drag"
onMouseDown={mouseDownHandler}
draggable
onDragStart={() => setIsDragging(true)}
onClick={() => !isDragging && props.setBottomShow(!props.bottomShow)}
tabIndex={0}
>
{props.bottomShow ? <ExpandMore /> : <ExpandLess />}
</div>
<BottomTabs
setBottomShow={props.setBottomShow}
isThemeLight={props.isThemeLight}
/>
</div>
</>
);
};

export default BottomPanel;
51 changes: 23 additions & 28 deletions app/src/components/bottom/BottomTabs.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
import React, { useState } from 'react';
import makeStyles from '@mui/styles/makeStyles';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';
import StylesEditor from './StylesEditor';
import CustomizationPanel from '../../containers/CustomizationPanel';
import { useDispatch, useSelector } from 'react-redux';
import { changeProjectType } from '../../redux/reducers/slice/appStateSlice';
import { RootState } from '../../redux/store';
import { MeetingProvider } from '@videosdk.live/react-sdk';
const videoSDKToken = `${import.meta.env.VITE_VIDEOSDK_TOKEN}`;
import Chatroom from './ChatRoom';
import CreationPanel from './CreationPanel';
import CustomizationPanel from '../../containers/CustomizationPanel';
import StylesEditor from './StylesEditor';
import Tree from '../../tree/TreeChart';
import ContextManager from '../ContextAPIManager/ContextManager';
import StateManager from '../StateManagement/StateManagement';
import Chatroom from './ChatRoom';
import MUIProps from './MUIProps';
import makeStyles from '@mui/styles/makeStyles';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';
import Box from '@mui/material/Box';
import Tree from '../../tree/TreeChart';
import FormControl from '@mui/material/FormControl';
import MenuItem from '@mui/material/MenuItem';
import Select from '@mui/material/Select';
import arrow from '../main/Arrow';
import { useDispatch, useSelector } from 'react-redux';
import { changeProjectType } from '../../redux/reducers/slice/appStateSlice';
import { RootState } from '../../redux/store';
import { MeetingProvider } from '@videosdk.live/react-sdk';
const videoSDKToken = `${import.meta.env.VITE_VIDEOSDK_TOKEN}`;


const BottomTabs = (props): JSX.Element => {
const { setBottomShow, isThemeLight } = props;
Expand Down Expand Up @@ -73,54 +75,52 @@ const BottomTabs = (props): JSX.Element => {
indicator: classes.tabsIndicator
}}
variant="scrollable"
scrollButtons="auto"
scrollButtons="auto"
>
<Tab
disableRipple
<Tab
classes={{ root: classes.tabRoot, selected: classes.tabSelected }}
label="Live Chat"
onClick={showBottomPanel}
sx={{ borderTop: '2px solid #191919' }}
/>
<Tab
disableRipple
classes={{ root: classes.tabRoot, selected: classes.tabSelected }}
label="Creation Panel"
onClick={showBottomPanel}
sx={{ borderTop: '2px solid #191919' }}
/>
<Tab
disableRipple
classes={{ root: classes.tabRoot, selected: classes.tabSelected }}
label="Customization"
onClick={showBottomPanel}
sx={{ borderTop: '2px solid #191919' }}
/>
<Tab
disableRipple
classes={{ root: classes.tabRoot, selected: classes.tabSelected }}
label="CSS Editor"
onClick={showBottomPanel}
sx={{ borderTop: '2px solid #191919' }}
/>
<Tab
disableRipple
classes={{ root: classes.tabRoot, selected: classes.tabSelected }}
label="Component Tree"
onClick={showBottomPanel}
/>
<Tab
disableRipple
classes={{ root: classes.tabRoot, selected: classes.tabSelected }}
label="Context Manager"
onClick={showBottomPanel}
/>
<Tab
disableRipple
classes={{ root: classes.tabRoot, selected: classes.tabSelected }}
label="State Manager"
onClick={showBottomPanel}
/>
<Tab
classes={{ root: classes.tabRoot, selected: classes.tabSelected }}
label="MUI Props"
onClick={showBottomPanel}
/>
</Tabs>

<div className={classes.projectTypeWrapper}>
Expand Down Expand Up @@ -161,13 +161,8 @@ const BottomTabs = (props): JSX.Element => {
{tab === 3 && <StylesEditor theme={theme} setTheme={setTheme} />}
{tab === 4 && <Tree data={components} />}
{tab === 5 && <ContextManager theme={theme} setTheme={setTheme} />}
{tab === 6 && (
<StateManager
theme={theme}
setTheme={setTheme}
isThemeLight={isThemeLight}
/>
)}
{tab === 6 && (<StateManager theme={theme} setTheme={setTheme} isThemeLight={isThemeLight} />)}
{tab === 7 && <MUIProps theme={theme} setTheme={setTheme} />}
</div>
</div>
</MeetingProvider>
Expand Down
47 changes: 47 additions & 0 deletions app/src/components/bottom/MUIProps.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React, { useState } from 'react';
import { Button, TextField } from "@mui/material";
import { Send } from "@mui/icons-material";
import MUITypes from "../../redux/MUITypes";
import { MUIType } from '../../interfaces/Interfaces';
import { emitEvent } from '../../helperFunctions/socket';

const MUIProps = (props): JSX.Element => {
const [selectedComponent, setSelectedComponent] = useState<MUIType | null>(null);

const handleComponentSelect = (component: MUIType) => {
setSelectedComponent(component);
};

const handleSend = () => {
if (selectedComponent) {
emitEvent("add-component", selectedComponent, {placeholder: "Placeholder"});
}
};

return (
<div>
<div style={{ display: "flex", flexDirection: "column" }}>
{MUITypes.map((component) => (
<Button
key={component.id}
onClick={() => handleComponentSelect(component)}
sx={{ marginBottom: "0.5rem" }}
>
{component.name}
</Button>
))}
</div>
<Button
onClick={handleSend}
variant="contained"
endIcon={<Send />}
sx={{ marginTop: "1rem" }}
>
Save
</Button>
</div>
);
};

export default MUIProps;

4 changes: 1 addition & 3 deletions app/src/components/left/ComponentDrag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import makeStyles from '@mui/styles/makeStyles';
import { useSelector } from 'react-redux';
import ComponentPanelItem from '../right/ComponentPanelItem';


const useStyles = makeStyles({
panelWrapper: {
display: 'flex',
Expand All @@ -21,7 +20,7 @@ const useStyles = makeStyles({
color: '#fff'
},
darkThemeFontColor: {
color: '#fff'
color: '#00008B,'
}
});

Expand Down Expand Up @@ -70,4 +69,3 @@ const ComponentDrag = ({ isVisible, isThemeLight }): JSX.Element | null => {
};

export default ComponentDrag;

27 changes: 0 additions & 27 deletions app/src/components/left/DragDropPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,33 +101,6 @@ const DragDropPanel = (props): JSX.Element => {
</AccordionDetails>
</Accordion>

{/* MUI Components */}
<Accordion className={classes.accordion}>
<AccordionSummary
expandIcon={<ExpandMoreIcon />}
aria-controls="panel2a-content"
id="panel2a-header"
className={classes.accordionSummary}
>
<h3>MUI Components</h3>
</AccordionSummary>
<AccordionDetails>
<Grid container justifyContent="center">
{muiTypesToRender.map((option) => {
return (
<MUIItem
name={option.name}
key={`mui-${option.name}`}
id={option.id}
icon={option.icon}
handleDelete={handleDelete}
/>
);
})}
</Grid>
</AccordionDetails>
</Accordion>

{/* React Router */}
<Accordion className={classes.accordion}>
<AccordionSummary
Expand Down
Loading

0 comments on commit ab07a9e

Please sign in to comment.