Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

View-Only Sketches and Major Main/Editor Refactoring #219

Merged
merged 60 commits into from
Apr 3, 2020
Merged
Show file tree
Hide file tree
Changes from 58 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
978c26b
adds getSketch function
mattxwang Oct 30, 2019
66a765d
adds GET specifically (oops!)
mattxwang Oct 30, 2019
b6bba6e
added /p/:programid route and fixed fetch logic
alyssamw Nov 3, 2019
8111d3d
put sketch in use so we remember to use it later
alyssamw Nov 8, 2019
8480fde
make editor constants global, move Output files out of Editor, moved …
jamieliu386 Nov 14, 2019
d5078c0
added rough ui for toggle switch
emmyc Nov 14, 2019
98e5df3
added buttons back to Output and Sketches
jamieliu386 Nov 14, 2019
c6488ad
fixed path to constants in Editor
jamieliu386 Nov 14, 2019
2ac38c8
checking if removing buttons breaks things
jamieliu386 Nov 14, 2019
fb9f01d
Made checkbox toggle controlled by adding check state
emmyc Nov 15, 2019
4099158
figured out buttons
jamieliu386 Nov 15, 2019
1a6898a
moved Editor related things into TextEditor component, moved Editor/O…
jamieliu386 Nov 15, 2019
9ddc20d
refactoring editor component
jamieliu386 Nov 15, 2019
8b6fa37
fixed sketches being rendered weirdly
jamieliu386 Nov 15, 2019
1342f28
renamed Editor things to TextEditor
jamieliu386 Nov 17, 2019
964fa64
integrated theme state with reducers
emmyc Nov 21, 2019
0f4c39f
Made text editor color changes for light mode
emmyc Nov 24, 2019
ed815d1
Merge branch 'master' into view-only
jamieliu386 Nov 24, 2019
5eb261e
pass screenWidth, screenHeight, and handleDownload() props to TextEdi…
jamieliu386 Nov 24, 2019
1fb7a4a
Merge branch 'master' into add-fetch-program
mattxwang Nov 25, 2019
b2672ca
fix sketches being rendered incorrectly with profile panel open
jamieliu386 Nov 26, 2019
14e434a
Merge branch 'master' into add-fetch-program
mattxwang Nov 26, 2019
31f428e
Added theme colors to scss file based on cm theme
emmyc Nov 30, 2019
aaedcbb
fixes strange blue cursor on light theme
mattxwang Dec 1, 2019
5c8659c
removes not useful css class set
mattxwang Dec 1, 2019
c63c130
Merge branch 'master' into light-mode
mattxwang Dec 1, 2019
f2f780c
important for the merge!
mattxwang Dec 1, 2019
b84ccae
hoists theme-* higher in editor
mattxwang Dec 1, 2019
04077fe
makes editor-expand-panel button also look noice
mattxwang Dec 1, 2019
badccf6
removed transition from language button in header
emmyc Dec 1, 2019
b045e8c
removed transition from language select button
emmyc Dec 1, 2019
917c8f4
makes getTheme a switch case
mattxwang Dec 3, 2019
bd5e8f1
adds demo vanilla js cookie functionality
mattxwang Dec 3, 2019
6479661
fixes strict equality
mattxwang Dec 3, 2019
59210b1
setup commit
emmyc Dec 11, 2019
54a14b3
Merge branch 'master' into add-fetch-program
emmyc Dec 18, 2019
1849580
created viewonly component and container
emmyc Dec 25, 2019
efbcfa1
temporary fix, makes sketches button show up on view-only
mattxwang Dec 25, 2019
6c15a6c
slight adjustment to componentDidMount
mattxwang Dec 25, 2019
aec8833
made profile panel render differently if user is not logged in
jamieliu386 Feb 20, 2020
19edaeb
fixed download button, display sketch name
jamieliu386 Feb 20, 2020
592908a
make output render properly, fix code coloring
jamieliu386 Feb 20, 2020
a1f4dce
fix output bug
jamieliu386 Feb 20, 2020
7275c0b
creates EditorAndOutput component
mattxwang Feb 21, 2020
f73f457
oops sorry undeletes SketchesPageContainer
mattxwang Feb 21, 2020
012ddf9
Merge branch 'master' into view-only
mattxwang Feb 21, 2020
c408b0d
fixes themes!
mattxwang Feb 21, 2020
02d0f9d
adds panel buttons wrapper
mattxwang Feb 21, 2020
721ba92
fixes thumbnail on viewonly
mattxwang Feb 21, 2020
a7b3ca6
fixes CSS name collision
mattxwang Feb 21, 2020
6632cda
updates failing tests to use a uid
mattxwang Feb 21, 2020
126e9ed
Merge branch 'master' into view-only
mattxwang Mar 2, 2020
4605c66
refactors viewonly to only make one getProgram call
mattxwang Mar 2, 2020
228b8c5
removes unused code
mattxwang Mar 2, 2020
7819567
Fix bug causing code to download incorrectly
jamieliu386 Mar 5, 2020
5b348a5
only triggers save program if user is logged in
mattxwang Mar 25, 2020
55cd132
Merge pull request #245 from uclaacm/view-only-fix-dl
mattxwang Mar 29, 2020
f07573b
Merge branch 'master' into view-only
mattxwang Mar 30, 2020
da9f162
Set initial theme from cookies in ViewOnly.
krashanoff Apr 3, 2020
71133fa
Removes extraneous console.log()s.
krashanoff Apr 3, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions src/actions/outputActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ export function clearOutput() {
return { type: CLEAR_OUTPUT };
}

export const SET_RUN_RESULT = 'SET_RUN_RESULT'
export function setRunResult(value){
return {type: SET_RUN_RESULT, value}
export const SET_RUN_RESULT = "SET_RUN_RESULT";
export function setRunResult(value) {
return { type: SET_RUN_RESULT, value };
}

export const SET_OUTPUT_LANGUAGE = 'SET_OUTPUT_LANGAUGE'
export function setOutputLanguage(value){
return {type: SET_OUTPUT_LANGUAGE, value}
export const SET_OUTPUT_LANGUAGE = "SET_OUTPUT_LANGAUGE";
export function setOutputLanguage(value) {
return { type: SET_OUTPUT_LANGUAGE, value };
}

export const SET_OUTPUT = 'SET_OUTPUT'
export function setOutput({output}){
export const SET_OUTPUT = "SET_OUTPUT";
export function setOutput({ output }) {
//if output is not an object
if(!output){
return {type:"IGNORE"}
if (!output) {
return { type: "IGNORE" };
}
return {type:SET_OUTPUT, runResult:output.code, language: output.language}
}
return { type: SET_OUTPUT, runResult: output.code, language: output.language };
}
101 changes: 101 additions & 0 deletions src/components/EditorAndOutput/EditorAndOutput.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import React from "react";
import SplitPane from "react-split-pane";
import OutputContainer from "../Output/OutputContainer.js";
import TextEditorContainer from "../TextEditor/containers/TextEditorContainer.js";

import { EDITOR_WIDTH_BREAKPOINT, CODE_ONLY, OUTPUT_ONLY, PANEL_SIZE } from "../../constants";
import CodeDownloader from "../../util/languages/CodeDownloader";

import "codemirror/lib/codemirror.css";
import "codemirror/theme/material.css";
import "codemirror/theme/duotone-light.css";
import "styles/CustomCM.scss";
import "styles/Resizer.scss";
import "styles/Editor.scss";

class EditorAndOutput extends React.Component {
handleDownload = () => {
CodeDownloader.download(this.props.sketchName, this.props.language, this.props.code);
};

renderCodeAndOutput = () => (
<SplitPane
resizerStyle={{
height: "67px",
borderLeft: "2px solid #333",
borderRight: "2px solid #333",
width: "10px",
}}
pane1Style={this.props.pane1Style}
//functions called when you start and finish a drag
//removes and re-addsthe transition effect on the first panel when manually resizing
onDragStarted={() => this.props.changePane1Style({ pane1Style: {} })}
onDragFinished={() =>
this.props.changePane1Style({ pane1Style: { transition: "width .5s ease" } })
}
split="vertical" //the resizer is a vertical line (horizontal means resizer is a horizontal bar)
minSize={
(this.props.panelOpen ? this.props.screenWidth - PANEL_SIZE : this.props.screenWidth) * 0.33
} //minimum size of code is 33% of the remaining screen size
maxSize={
(this.props.panelOpen ? this.props.screenWidth - PANEL_SIZE : this.props.screenWidth) * 0.75
} //max size of code is 75% of the remaining screen size
size={
((this.props.panelOpen ? this.props.screenWidth - PANEL_SIZE : this.props.screenWidth) /
5) *
3
} //the initial size of the text editor section
allowResize={true}
>
{this.renderCode()}
{this.renderOutput()}
</SplitPane>
);

renderCode = () => (
<TextEditorContainer
key={this.props.mostRecentProgram}
viewMode={this.props.viewMode}
updateViewMode={this.props.updateViewMode}
screenHeight={this.props.screenHeight}
screenWidth={this.props.screenWidth}
theme={this.props.theme}
viewOnly={this.props.viewOnly}
program={this.props.programid}
sketchName={this.props.sketchName}
language={this.props.language}
handleDownload={this.handleDownload}
handleSave={this.props.handleSave}
saveText={this.props.saveText}
thumbnail={this.props.thumbnail}
/>
);

renderOutput = () => (
<OutputContainer
viewMode={this.props.viewMode}
updateViewMode={this.props.updateViewMode}
isSmall={this.props.screenWidth <= EDITOR_WIDTH_BREAKPOINT}
viewOnly={this.props.viewOnly}
vLanguage={this.props.language}
code={this.props.code}
/>
);
render = () => {
const codeStyle = {
width: this.props.screenWidth - (this.props.left || 0),
height: this.props.screenHeight,
};

switch (this.props.viewMode) {
case CODE_ONLY:
return <div style={codeStyle}>{this.renderCode()}</div>;
case OUTPUT_ONLY:
return <div style={codeStyle}>{this.renderOutput()}</div>;
default:
return this.renderCodeAndOutput();
}
};
}

export default EditorAndOutput;
118 changes: 30 additions & 88 deletions src/components/Main.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
import React from "react";
import { Redirect } from "react-router-dom";
import SplitPane from "react-split-pane";
import OutputContainer from "./Output/OutputContainer.js";
import TextEditorContainer from "./TextEditor/containers/TextEditorContainer.js";

import * as fetch from "../lib/fetch.js";
import * as cookies from "../lib/cookies.js";
import SketchesPageContainer from "./Sketches/containers/SketchesContainer";
import "styles/Main.scss";

import ProfilePanelContainer from "./common/containers/ProfilePanelContainer";
import SketchesPageContainer from "./Sketches/containers/SketchesContainer";
import EditorAndOutput from "./EditorAndOutput/EditorAndOutput";

import { EDITOR_WIDTH_BREAKPOINT, CODE_AND_OUTPUT, CODE_ONLY, OUTPUT_ONLY } from "../constants";
import CodeDownloader from "../util/languages/CodeDownloader";
import { EDITOR_WIDTH_BREAKPOINT, CODE_AND_OUTPUT, CODE_ONLY } from "../constants";

import { PANEL_SIZE } from "../constants";
import "codemirror/lib/codemirror.css";
import "codemirror/theme/material.css";
import "codemirror/theme/duotone-light.css";
import "styles/CustomCM.scss";
import "styles/Resizer.scss";
import "styles/Editor.scss";
import "styles/Main.scss";

/**------Props-------
* togglePanel: function to call when you want the Profile Panel to disappear/reapper
Expand All @@ -39,7 +31,6 @@ class Main extends React.Component {
this.props.setTheme(cookies.getThemeFromCookie());
}

//==============React Lifecycle Functions Start===================//
componentDidUpdate(prevProps) {
if (this.props.screenWidth !== prevProps.screenWidth) {
if (this.props.screenWidth <= EDITOR_WIDTH_BREAKPOINT) {
Expand Down Expand Up @@ -84,10 +75,6 @@ class Main extends React.Component {
this.props.cleanCode(this.props.mostRecentProgram); // Set code's "dirty" state to false
};

handleDownload = () => {
CodeDownloader.download(this.props.name, this.props.language, this.props.code);
};

renderContent = () => {
switch (this.props.contentType) {
case "editor":
Expand All @@ -98,80 +85,35 @@ class Main extends React.Component {
}
};

renderCodeAndOutput = () => (
<SplitPane
resizerStyle={{
height: "67px",
borderLeft: "2px solid #333",
borderRight: "2px solid #333",
width: "10px",
}}
pane1Style={this.state.pane1Style}
//functions called when you start and finish a drag
//removes and re-addsthe transition effect on the first panel when manually resizing
onDragStarted={() => this.setState({ pane1Style: {} })}
onDragFinished={() => this.setState({ pane1Style: { transition: "width .5s ease" } })}
split="vertical" //the resizer is a vertical line (horizontal means resizer is a horizontal bar)
minSize={
(this.props.panelOpen ? this.props.screenWidth - PANEL_SIZE : this.props.screenWidth) * 0.33
} //minimum size of code is 33% of the remaining screen size
maxSize={
(this.props.panelOpen ? this.props.screenWidth - PANEL_SIZE : this.props.screenWidth) * 0.75
} //max size of code is 75% of the remaining screen size
size={
((this.props.panelOpen ? this.props.screenWidth - PANEL_SIZE : this.props.screenWidth) /
5) *
3
} //the initial size of the text editor section
allowResize={true}
>
{this.renderCode()}
{this.renderOutput()}
</SplitPane>
);

updateViewMode = viewMode => {
this.setState({ viewMode });
};

renderCode = () => (
<TextEditorContainer
key={this.props.mostRecentProgram}
renderEditor = () => (
<EditorAndOutput
// view mode
viewMode={this.state.viewMode}
updateViewMode={this.updateViewMode}
handleSave={this.handleSave}
saveText={this.state.saveText}
screenHeight={this.props.screenHeight}
screenWidth={this.props.screenWidth}
handleDownload={this.handleDownload}
updateViewMode={viewMode => this.setState({ viewMode })}
// theme
theme={this.props.theme}
// sizing
left={this.props.left}
screenWidth={this.props.screenWidth}
screenHeight={this.props.screenHeight}
// view only trigger
viewOnly={false}
// pane
panelOpen={this.props.panelOpen}
pane1Style={this.state.pane1Style}
changePane1Style={newStyle => this.setState(newStyle)}
// program information
mostRecentProgram={this.props.mostRecentProgram}
language={this.state.language}
code={this.state.code}
programid={this.props.programid}
sketchName={this.state.sketchName}
// save handler
saveText={this.state.saveText}
handleSave={this.handleSave}
/>
);

renderOutput = () => (
<OutputContainer
viewMode={this.state.viewMode}
updateViewMode={this.updateViewMode}
isSmall={this.props.screenWidth <= EDITOR_WIDTH_BREAKPOINT}
/>
);

renderEditor = () => {
const codeStyle = {
width: this.props.screenWidth - (this.props.left || 0),
height: this.props.screenHeight,
};

switch (this.state.viewMode) {
case CODE_ONLY:
return <div style={codeStyle}>{this.renderCode()}</div>;
case OUTPUT_ONLY:
return <div style={codeStyle}>{this.renderOutput()}</div>;
default:
return this.renderCodeAndOutput();
}
};

render() {
// this stops us from rendering editor with no sketches available
if (this.props.contentType === "editor" && this.props.listOfPrograms.length === 0) {
Expand Down
3 changes: 2 additions & 1 deletion src/components/Output/Output.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ class Output extends React.Component {
};

renderOutput = () => {
let { language, runResult } = this.props;
let language = this.props.viewOnly ? this.props.vLanguage : this.props.language;
let runResult = this.props.viewOnly ? this.props.code : this.props.runResult;
const { showConsole } = this.state;

if (this.firstLoad) {
Expand Down
Loading