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

status bar #432

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/actions/uiActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ export const SET_THEME = "SET_THEME";
export function setTheme(theme) {
return { type: SET_THEME, theme };
}

export const SHOW_STATUSBAR = "SHOW_STATUSBAR";
export function setStatusBar(value) {
return { type: SHOW_STATUSBAR, value };
}
16 changes: 16 additions & 0 deletions src/components/TextEditor/components/StatusBar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React, { useState } from "react";

const StatusBar = (props) => {
const edit = props.editing;
return (
<div className="status-bar-container">
<p
className="status-bar-info"
className={props.theme === "light" ? "light-status" : "dark-status"}
>
{edit ? "Editing" : "Viewing"} line: {props.line + 1} col: {props.col + 1}{" "}
</p>
</div>
);
};
export default StatusBar;
18 changes: 15 additions & 3 deletions src/components/TextEditor/components/TextEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import sketch from "../../../lib/";

import EditorRadio from "./EditorRadio.js";
import ShareSketchModal from "./ShareSketchModal";
import StatusBar from "./StatusBar";

import { Button } from "reactstrap";
import OpenPanelButtonContainer from "../../common/containers/OpenPanelButtonContainer";
Expand Down Expand Up @@ -37,6 +38,7 @@ class TextEditor extends React.Component {
this.state = {
codeMirrorInstance: null,
currentLine: 0,
currentColumn: 0,
sketch: null,
showForkModal: false,
forking: false,
Expand Down Expand Up @@ -102,17 +104,16 @@ class TextEditor extends React.Component {
}
this.props.setProgramCode(this.props.mostRecentProgram, newCode);
};

setCurrentLine = (cm) => {
const { codeMirrorInstance, currentLine } = this.state;
let { line } = cm.getCursor();
let { line, ch } = cm.getCursor();
if (codeMirrorInstance) {
//removeLineClass removes the back highlight style from the last selected line
codeMirrorInstance.removeLineClass(currentLine, "wrap", "selected-line");
//addLineClass adds the style to the newly selected line
codeMirrorInstance.addLineClass(line, "wrap", "selected-line");
}
this.setState({ currentLine: line });
this.setState({ currentLine: line, currentColumn: ch });
};

renderForkModal = () => {
Expand Down Expand Up @@ -299,6 +300,7 @@ class TextEditor extends React.Component {
showModal={this.state.showShareModal}
toggleModal={this.toggleShareModal}
/>

<div
className="text-editor-container"
style={{
Expand All @@ -322,6 +324,16 @@ class TextEditor extends React.Component {
onBeforeChange={this.updateCode}
onChange={this.updateCode}
/>
{this.props.statusBar ? (
<StatusBar
editing={!this.props.viewOnly}
line={this.state.currentLine}
col={this.state.currentColumn}
theme={this.props.theme}
/>
) : (
""
)}
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const mapStateToProps = (state, ownProps) => {
mostRecentProgram,
theme: ownProps.theme,
uid,
statusBar: state.ui.statusBar,
};
};

Expand Down
17 changes: 15 additions & 2 deletions src/components/common/ProfilePanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ class ProfilePanel extends React.Component {
}

panelButtons.push(this.renderSignOutButton());

//panelButtons.push(this.renderShowStatusBar()); //Status bar. temporarily removed before collab coding
return <div className="panel-buttons">{panelButtons}</div>;
};

Expand Down Expand Up @@ -316,6 +316,20 @@ class ProfilePanel extends React.Component {
</div>
);

renderShowStatusBar = () => {
return (
<Button
className="panel-button"
key="sign-out-button"
id="sign-out-button"
size="lg"
block
onClick={() => this.props.setStatusBar(!this.props.statusBar)}
>
<span className="panel-button-text">Status Bar</span>
</Button>
);
};
renderContent = () => (
<div className="panel-content">
{this.renderPanelImage()}
Expand All @@ -326,7 +340,6 @@ class ProfilePanel extends React.Component {
{this.renderThemeSwitch()}
</div>
);

renderCollapseButton = () => (
<div className="panel-collapse-button" onClick={this.props.togglePanel}>
<FontAwesomeIcon icon={faTimes} />
Expand Down
8 changes: 5 additions & 3 deletions src/components/common/containers/ProfilePanelContainer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ProfilePanel from "../ProfilePanel";
import { connect } from "react-redux";
import { setDisplayName, setPhotoName } from "../../../actions/userDataActions";
import { togglePanel } from "../../../actions/uiActions";
import { setStatusBar, togglePanel } from "../../../actions/uiActions";
import { DEFAULT_PHOTO_NAME, CLOSED_PANEL_LEFT, OPEN_PANEL_LEFT } from "../../../constants";

const mapStateToProps = (state, ownProps) => {
Expand All @@ -12,18 +12,20 @@ const mapStateToProps = (state, ownProps) => {
screenHeight: state.ui.screenHeight,
left: state.ui.panelOpen ? OPEN_PANEL_LEFT : CLOSED_PANEL_LEFT,
theme: ownProps.theme,
statusBar: state.ui.statusBar,
};
};

const mapDispatchToProps = (dispatch, ownProps) => {
return {
onThemeChange: ownProps.onThemeChange,
collectUserPhoto: () => {},
setDisplayName: name => dispatch(setDisplayName(name)),
setPhotoName: name => dispatch(setPhotoName(name)),
setDisplayName: (name) => dispatch(setDisplayName(name)),
setPhotoName: (name) => dispatch(setPhotoName(name)),
togglePanel: () => {
dispatch(togglePanel());
},
setStatusBar: (value) => dispatch(setStatusBar(value)),
};
};

Expand Down
11 changes: 10 additions & 1 deletion src/reducers/uiReducer.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import { SCREEN_RESIZE, TOGGLE_PANEL, SET_PANEL, SET_THEME } from "../actions/uiActions";
import {
SCREEN_RESIZE,
TOGGLE_PANEL,
SET_PANEL,
SET_THEME,
SHOW_STATUSBAR,
} from "../actions/uiActions";

const initialState = {
screenWidth: typeof window === "object" ? window.innerWidth : null,
screenHeight: typeof window === "object" ? window.innerHeight : null,
panelOpen: false,
theme: "dark",
statusBar: false,
};

function uiReducer(state = initialState, action) {
Expand All @@ -17,6 +24,8 @@ function uiReducer(state = initialState, action) {
return Object.assign({}, state, { panelOpen: action.value });
case SET_THEME:
return Object.assign({}, state, { theme: action.theme });
case SHOW_STATUSBAR:
return Object.assign({}, state, { statusBar: action.value });
default:
return state;
}
Expand Down
23 changes: 18 additions & 5 deletions src/styles/Editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@
padding: 4px;
border-radius: 25px;
@include themify($themes) {
background-color: themed("cardBackground")
}
background-color: themed("cardBackground");
}
}


.program-sketch-name {
flex: 0 1 auto;
@include themify($themes) {
Expand All @@ -47,7 +46,6 @@
margin-left: 1em;
}


.code-section-banner {
display: flex;
flex-direction: row;
Expand Down Expand Up @@ -179,4 +177,19 @@
background-color: rgb(255, 255, 255);
padding: 40px;
border-radius: 20px;
}
}

.status-bar-container {
@include themify($themes) {
background-color: themed("backgroundColor");
}
margin-left: 60%;
padding: 10px 20px 0px;
position: absolute;
bottom: 0%;
width: fit-content;
}

.status-bar-info {
font-size: 25px;
}
7 changes: 7 additions & 0 deletions src/styles/Panel.scss
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,13 @@
}
}

.statusbar-button {
@include themify($themes) {
color: themed("color");
border-color: themed("backgroundColor");
background-color: themed("backgroundColor");
}
}
.panel-button:hover,
.panel-button:active {
@include themify($themes) {
Expand Down