Skip to content

Commit

Permalink
Merge pull request #532 from jf-kelly/fontsize
Browse files Browse the repository at this point in the history
Font Size
  • Loading branch information
kdvalin authored Feb 16, 2022
2 parents 19ba2ac + c57196c commit 3791245
Show file tree
Hide file tree
Showing 18 changed files with 196 additions and 34 deletions.
3 changes: 2 additions & 1 deletion src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export { default as ProjectActions } from "./projectActions";
export { default as SceneActions } from "./sceneActions";
export { default as CourseActions } from "./courseActions";
export { default as CollectionActions } from "./collectionActions";
export { default as ReferenceExampleActions } from "./referenceExampleActions";
export { default as ReferenceExampleActions } from "./referenceExampleActions";
export { default as UserActions } from "./userActions";
2 changes: 1 addition & 1 deletion src/actions/sceneActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,5 @@ export default {
toggleDefaultLight,
toggleCastShadow,
toggleLightIndicator,
updateMoveSpeed
updateMoveSpeed,
};
47 changes: 47 additions & 0 deletions src/actions/userActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import * as types from "../constants/ActionTypes";

const googleLoginRef = "apiv1/googlelogins";

export function updateFontSize(fontSize){
return{ type: types.UPDATE_FONT_SIZE, fontSize };
}

export function updateUserSettings(id,settings){
return ()=>{
if(id){
fetch(`${googleLoginRef}/settings`,{
method:"PUT",
body:JSON.stringify(settings),
headers: {
"Content-Type":"application/json",
"x-access-token":id
}
});
}
};
}

export function asyncUserSettings(id){
return dispatch => {
if(id){
fetch(`${googleLoginRef}/settings`,{headers:{"x-access-token": id}}).then(response=>{
if(response.status === 200){
response.json().then(json =>{
dispatch(syncUserSettings(json));
});
}
});
}
};
}

export function syncUserSettings(settings){
return { type: types.SYNC_USER_SETTINGS, settings: settings };
}

export default {
updateFontSize,
asyncUserSettings,
syncUserSettings,
updateUserSettings
};
15 changes: 14 additions & 1 deletion src/components/editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import "brace/ext/language_tools";
import customCompleter from "./customCompleter.js";
import KeyboardShortcut from "./KeyboardShortcut.js";
import { browserType } from "../../utils/browserType";
import FontSize from "./FontSize.js";

/**
* Editor is a React Component that creat the Ace Editor in the DOM.
Expand Down Expand Up @@ -45,6 +46,8 @@ class Editor extends Component {
event.returnValue = "You may have unsaved scene changes!";
}
});

this.setState({"previousSettings":this.props.settings});
}

onLoad() {
Expand All @@ -53,6 +56,14 @@ class Editor extends Component {
"esversion": 6
}]);
}

componentDidUpdate(){
if(JSON.stringify(this.state.previousSettings) !== JSON.stringify(this.props.settings) &&
this.props.user) {
this.props.userActions.updateUserSettings(this.props.user.uid,this.props.settings);
this.setState({"previousSettings":this.props.settings});
}
}

/**
* Creates the editor in the DOM
Expand All @@ -70,14 +81,16 @@ class Editor extends Component {
// eslint-disable-next-line
ref="aceEditor"
theme="github"
fontSize = {this.props.settings.fontSize}
value={this.props.text}
width="100%"
wrapEnabled={true}
enableBasicAutocompletion={false}
enableLiveAutocompletion={true}
onLoad={this.onLoad}
/>
{ browserType() === "desktop" ? <KeyboardShortcut/> : null }
{ browserType() === "desktop" ? <div><KeyboardShortcut/>
<FontSize userActions={this.props.userActions} settings={this.props.settings}/></div> : null }
</div>
);
}
Expand Down
40 changes: 40 additions & 0 deletions src/components/editor/FontSize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from "react";
import {
Select,
Button,
Tooltip,
Icon
} from "@material-ui/core";
import "../../css/KeyboardShortcut.css";

const options=[12, 14, 18, 24, 30, 36, 48];
class FontSize extends React.Component {

handleFontSizeUpdate = (e) => {
this.props.userActions.updateFontSize(e.target.value);
}

render(){
return(
<div className="font">
<Tooltip title="Font Size">
<Button className="font-button"
variant="contained"
size="small"
color="primary">
<Icon className="material-icons">format_size</Icon>
<Select className="select"
labelId="input-label"
defaultValue = {12}
value = {this.props.settings.fontSize}
onChange = {this.handleFontSizeUpdate}>
{options.map(size=>(<option value={size}>{size}</option>))}
</Select>
</Button>
</Tooltip>
</div>
);
}
}
export default FontSize;

2 changes: 1 addition & 1 deletion src/components/editor/KeyboardShortcut.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class KeyboardShortcut extends React.Component {

render(){
return(
<div>
<div className="whole-keyboard">
<Tooltip title="Keyboard Shortcut">
<Button
variant="contained"
Expand Down
5 changes: 3 additions & 2 deletions src/components/layouts/Collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import SelectProject from "../collection/SelectProject.js";

import * as layoutTypes from "../../constants/LayoutTypes.js";

export const Collection = ({ editor, editorActions, user, authActions, scene, sceneActions, projectActions, courseActions, projects, courses, match, collectionActions, collections }) => (
export const Collection = ({ editor, editorActions, user, userSettings, userActions, authActions, scene, sceneActions, projectActions, courseActions, projects, courses, match, collectionActions, collections }) => (
<div className="App">
<Header
logging={authActions}
sceneActions={sceneActions}
actions={editorActions}
user={user}
userActions={userActions}
scene={scene}
text={editor.text}
message={editor.message}
Expand All @@ -39,7 +40,7 @@ export const Collection = ({ editor, editorActions, user, authActions, scene, sc
savedText={editor.savedText}
/>
<div className='collection'>
<Editor text={editor.text} user={user} savedText={editor.savedText} />
<Editor text={editor.text} user={user} settings={userSettings} savedText={editor.savedText} />
</div>
</div>
<div id="scene" className="col-12 col-md-8">
Expand Down
5 changes: 3 additions & 2 deletions src/components/layouts/Guided.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import View from "../structural/View";

import * as layoutTypes from "../../constants/LayoutTypes.js";

export const Guided = ({ editor, user, scene, editorActions, authActions, projectActions, projects, courseActions, courses, course, match, sceneActions, collectionActions, collections }) => (
export const Guided = ({ editor, user, usersettings, userActions, scene, editorActions, authActions, projectActions, projects, courseActions, courses, course, match, sceneActions, collectionActions, collections }) => (
<div className="App">
<Header
viewOnly={scene.settings.viewOnly}
logging={authActions}
sceneActions={sceneActions}
actions={editorActions}
user={user}
userActions={userActions}
scene={scene}
text={editor.text}
message={editor.message}
Expand Down Expand Up @@ -42,7 +43,7 @@ export const Guided = ({ editor, user, scene, editorActions, authActions, projec
<div id="interface" className="col-12 col-md-4">
<Course lesson={courses.currentLesson} courses={courses} course={course} courseName={match.params.shortname} actions={editorActions} courseActions={courseActions} savedText={editor.savedText}/>
<div className='guided'>
<Editor refresh={editorActions.refresh} render={editorActions.render} text={editor.text} user={user} savedText={editor.savedText} />
<Editor refresh={editorActions.refresh} render={editorActions.render} text={editor.text} user={user} settings={usersettings} savedText={editor.savedText} />
</div>
</div>
<div id="scene" className="col-12 col-md-8">
Expand Down
6 changes: 4 additions & 2 deletions src/components/layouts/Ide.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Banner from "../structural/header/Banner";

import * as layoutTypes from "../../constants/LayoutTypes.js";

export const Ide = ({ editor, editorActions, user, authActions, scene, sceneActions, projectActions, courseActions, projects, courses, match, collectionActions, collections }) => (
export const Ide = ({ editor, editorActions, user, usersettings, userActions, authActions, scene, sceneActions, projectActions, courseActions, projects, courses, match, collectionActions, collections }) => (
<div className="App">
<Banner
endpoint="/apiv1/notifications"
Expand All @@ -21,6 +21,8 @@ export const Ide = ({ editor, editorActions, user, authActions, scene, sceneActi
sceneActions={sceneActions}
actions={editorActions}
user={user}
settings={usersettings}
userActions={userActions}
scene={scene}
text={editor.text}
message={editor.message}
Expand All @@ -44,7 +46,7 @@ export const Ide = ({ editor, editorActions, user, authActions, scene, sceneActi
:
<>
<div id="interface" className="col-12 col-md-4" >
<Editor refresh={editorActions.refresh} render={editorActions.render} text={editor.text} user={user} savedText={editor.savedText} />
<Editor refresh={editorActions.refresh} render={editorActions.render} text={editor.text} user={user} settings={usersettings} savedText={editor.savedText} userActions={userActions} />
</div>
<div id="scene" className="col-12 col-md-8" >
<View objects={editor.objects} sceneConfig={scene} assets={editor.assets} />
Expand Down
6 changes: 5 additions & 1 deletion src/components/structural/header/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class Header extends Component {
event.returnValue = "You may have unsaved changes!";
}
});
}
}
}


Expand Down Expand Up @@ -207,6 +207,8 @@ class Header extends Component {

this.props.projectActions.asyncUserProj(this.props.user.uid);
this.props.collectionActions.asyncCollections(this.props.user.uid);
this.props.userActions.asyncUserSettings(this.props.user.uid);

this.setRefreshTime(googleAuth.tokenObj.expires_at);

//send uid to google analyrica
Expand Down Expand Up @@ -770,6 +772,8 @@ class Header extends Component {
sceneActions={this.props.sceneActions}
collectionActions={this.props.collectionActions}
user={this.props.user}
settings={this.props.settings}
userActions={this.props.userActions}
handleRender={this.handleRender}
handleSave={this.handleSave}
handleSaveClose={this.handleSaveClose}
Expand Down
2 changes: 1 addition & 1 deletion src/components/structural/header/SceneConfigMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -759,4 +759,4 @@ class ConfigModal extends Component {

const SceneConfigMenu = withStyles(modelStyles)(ConfigModal);

export default SceneConfigMenu;
export default SceneConfigMenu;
3 changes: 3 additions & 0 deletions src/constants/ActionTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ export const TOGGLE_CAST_SHADOW = "TOGGLE_CAST_SHADOW";
export const TOGGLE_LIGHT_INDICATOR = "TOGGLE_LIGHT_INDICATOR";
export const UPDATE_MOVE_SPEED = "UPDATE_MOVE_SPEED";

export const SYNC_USER_SETTINGS = "SYNC_USER_SETTINGS";
export const UPDATE_FONT_SIZE = "UPDATE_FONT_SIZE";

export const SYNC_CLASSES = "SYNC_CLASSES";
export const SYNC_CLASS = "SYNC_CLASS";
export const DELETE_CLASS = "DELETE_CLASS";
Expand Down
22 changes: 10 additions & 12 deletions src/containers/Collection.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import Collection from "../components/layouts/Collection.js";
import PropTypes from "prop-types";

import * as AuthActions from "../actions/authActions.js";
import * as EditorActions from "../actions/editorActions.js";
import * as ProjectActions from "../actions/projectActions.js";
import * as SceneActions from "../actions/sceneActions.js";
import * as CourseActions from "../actions/courseActions.js";
import * as CollectionActions from "../actions/collectionActions.js";
import * as Actions from "../actions";


import { bindActionCreators } from "redux";
import { connect } from "react-redux";
Expand All @@ -28,6 +24,7 @@ Collection.propTypes = {
const mapStateToProps = state => ({
editor: state.editor,
user: state.user.user,
userSettings: state.user.settings,
scene: state.scene,
projects: state.project,
courses: state.courses,
Expand All @@ -39,12 +36,13 @@ const mapStateToProps = state => ({
* @param {*} dispatch !!!DESCRIPTION NEEDED!!!
*/
const mapDispatchToProps = dispatch => ({
editorActions: bindActionCreators(EditorActions, dispatch),
authActions: bindActionCreators(AuthActions, dispatch),
sceneActions: bindActionCreators(SceneActions, dispatch),
projectActions: bindActionCreators(ProjectActions, dispatch),
courseActions: bindActionCreators(CourseActions, dispatch),
collectionActions: bindActionCreators(CollectionActions, dispatch)
editorActions: bindActionCreators(Actions.EditorActions, dispatch),
authActions: bindActionCreators(Actions.AuthActions, dispatch),
sceneActions: bindActionCreators(Actions.SceneActions, dispatch),
projectActions: bindActionCreators(Actions.ProjectActions, dispatch),
courseActions: bindActionCreators(Actions.CourseActions, dispatch),
collectionActions: bindActionCreators(Actions.CollectionActions, dispatch),
userActions: bindActionCreators(Actions.UserActions, dispatch),
});

/**
Expand Down
4 changes: 3 additions & 1 deletion src/containers/Guided.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Guided.propTypes = {
const mapStateToProps = state => ({
editor: state.editor,
user: state.user.user,
usersettings: state.user.settings,
scene: state.scene,
lesson: state.courses.currentLesson,
projects: state.project,
Expand All @@ -39,7 +40,8 @@ const mapDispatchToProps = dispatch => ({
sceneActions: bindActionCreators(Actions.SceneActions, dispatch),
projectActions: bindActionCreators(Actions.ProjectActions, dispatch),
courseActions: bindActionCreators(Actions.CourseActions, dispatch),
collectionActions: bindActionCreators(Actions.CollectionActions, dispatch)
collectionActions: bindActionCreators(Actions.CollectionActions, dispatch),
userActions: bindActionCreators(Actions.UserActions, dispatch),
});

/**
Expand Down
4 changes: 3 additions & 1 deletion src/containers/Ide.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Ide.propTypes = {
const mapStateToProps = state => ({
editor: state.editor,
user: state.user.user,
usersettings: state.user.settings,
scene: state.scene,
projects: state.project,
courses: state.courses,
Expand All @@ -37,7 +38,8 @@ const mapDispatchToProps = dispatch => ({
sceneActions: bindActionCreators(Actions.SceneActions, dispatch),
projectActions: bindActionCreators(Actions.ProjectActions, dispatch),
courseActions: bindActionCreators(Actions.CourseActions, dispatch),
collectionActions: bindActionCreators(Actions.CollectionActions, dispatch)
collectionActions: bindActionCreators(Actions.CollectionActions, dispatch),
userActions: bindActionCreators(Actions.UserActions, dispatch),
});

/**
Expand Down
19 changes: 19 additions & 0 deletions src/css/KeyboardShortcut.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,23 @@

.note {
margin-left: 1%;
}

.font-button {
height:33px;
width:70px;
}

.font {
display: inline-block;
margin-left:2px;
}

.whole-keyboard {
display: inline-block;
}

.select {
color: white !important;
margin-left: 5px;
}
Loading

0 comments on commit 3791245

Please sign in to comment.