Skip to content

Add dropdown to map button #55

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

Open
wants to merge 2 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/app/actions/code/Submission.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as SubmissionInterfaces from 'app/types/code/Submission';
import * as SubmitBarInterfaces from 'app/types/SubmitBar';
import { action } from 'typesafe-actions';

export namespace SubmissionActions {
Expand All @@ -12,6 +13,7 @@ export namespace SubmissionActions {
HANDLE_EXECUTE_ERROR = 'HANDLE_EXECUTE_ERROR',
HANDLE_DEBUG_RUN_SUCCESS = 'HANDLE_DEBUG_RUN_SUCCESS',
HANDLE_DEBUG_RUN_ERROR = 'HANDLE_DEBUG_RUN_ERROR',
UPDATE_MAP = 'UPDATE_MAP',
UPDATE_MAP_ID = 'UPDATE_MAP_ID',
UPDATE_CURRENT_AI_ID = 'UPDATE_CURRENT_AI_ID',
UPDATE_DEBUG_RUN_REQUEST = 'UPDATE_DEBUG_RUN_REQUEST',
Expand Down Expand Up @@ -58,6 +60,8 @@ export namespace SubmissionActions {

export const handleDebugRunError = () => action(Type.HANDLE_EXECUTE_ERROR);

export const updateMap = (map: SubmitBarInterfaces.Map) => action(Type.UPDATE_MAP, { map });

export const updateMapId = (mapId: number) => action(Type.UPDATE_MAP_ID, { mapId });

export const updateCurrentAiId = (aiId: number) => action(Type.UPDATE_CURRENT_AI_ID, { aiId });
Expand Down
102 changes: 101 additions & 1 deletion src/app/components/SubmitBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
faCodeBranch,
faCog,
faLock,
faMap,
faPlay,
faSave,
faTrash,
Expand All @@ -22,15 +23,37 @@ export class SubmitBar extends React.Component<
SubmitBarInterfaces.Props,
SubmitBarInterfaces.State
> {
private faqBodyStyle = {
maxHeight: '0',
};
constructor(props: SubmitBarInterfaces.Props) {
super(props);
this.state = {
commitMessage: '',
isCommitMessageBoxOpen: false,
isMapOptionsOpen: false,
isRunOptionsOpen: false,
};
}

public expandDropDown = () => {
const { isMapOptionsOpen } = this.state;

if (!isMapOptionsOpen) {
this.faqBodyStyle = {
maxHeight: '168px',
};
} else {
this.faqBodyStyle = {
maxHeight: '0px',
};
}

this.setState({
isMapOptionsOpen: !isMapOptionsOpen,
});
};

public render() {
const {
saveCode,
Expand All @@ -42,8 +65,15 @@ export class SubmitBar extends React.Component<
aiIds,
clearLogs,
debugRunAvailable,
map,
updateMap,
} = this.props;
const { commitMessage, isCommitMessageBoxOpen, isRunOptionsOpen } = this.state;
const {
commitMessage,
isCommitMessageBoxOpen,
isMapOptionsOpen,
isRunOptionsOpen,
} = this.state;
return (
<div
className={classnames(styles.SubmitBar, {
Expand Down Expand Up @@ -111,10 +141,27 @@ export class SubmitBar extends React.Component<
className={classnames(styles.icon)}
style={{ padding: 0, margin: 0, border: 0 }}
title={'Clear Renderer Log'}
onClick={() => {
this.setState({ isMapOptionsOpen: !isMapOptionsOpen });
}}
>
<FontAwesomeIcon icon={faTrash} />
</span>
</button>
<button
className={classnames(styles.customBtn)}
id="map_dropdown"
onClick={this.expandDropDown}
>
<span
className={classnames(styles.icon)}
style={{ padding: 0, margin: 0, border: 0 }}
title={'Show Maps'}
>
<FontAwesomeIcon icon={faMap} />
</span>
</button>

<button
className={classnames(styles.customBtn)}
id="run_button"
Expand Down Expand Up @@ -195,6 +242,59 @@ export class SubmitBar extends React.Component<
closeOptions={this.closeRunOptions}
/>
) : null}

<div className={classnames(styles.mapDropdown)} style={this.faqBodyStyle}>
<div
className={
map === SubmitBarInterfaces.Map.MAP1
? classnames(styles.mapItem, styles.mapItemActive)
: classnames(styles.mapItem)
}
onClick={() => updateMap(SubmitBarInterfaces.Map.MAP1)}
>
MAP 1
</div>
<div
className={
map === SubmitBarInterfaces.Map.MAP2
? classnames(styles.mapItem, styles.mapItemActive)
: classnames(styles.mapItem)
}
onClick={() => updateMap(SubmitBarInterfaces.Map.MAP2)}
>
MAP 2
</div>
<div
className={
map === SubmitBarInterfaces.Map.MAP3
? classnames(styles.mapItem, styles.mapItemActive)
: classnames(styles.mapItem)
}
onClick={() => updateMap(SubmitBarInterfaces.Map.MAP3)}
>
MAP 3
</div>
<div
className={
map === SubmitBarInterfaces.Map.MAP4
? classnames(styles.mapItem, styles.mapItemActive)
: classnames(styles.mapItem)
}
onClick={() => updateMap(SubmitBarInterfaces.Map.MAP4)}
>
MAP 4
</div>
<div
className={
map === SubmitBarInterfaces.Map.MAP5
? classnames(styles.mapItem, styles.mapItemActive)
: classnames(styles.mapItem)
}
onClick={() => updateMap(SubmitBarInterfaces.Map.MAP5)}
>
MAP 5
</div>
</div>
</div>
);
}
Expand Down
2 changes: 2 additions & 0 deletions src/app/containers/SubmitBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const mapStateToProps = (rootState: RootState) => {
return {
aiIds: rootState.submission.aiIds,
debugRunAvailable: rootState.submission.debugRunRequest !== Request.NONE,
map: rootState.submission.selectedMap,
maps: rootState.submission.maps,
};
};
Expand All @@ -29,6 +30,7 @@ const mapDispatchToProps = (dispatch: Dispatch) => {
lockCode: () => dispatch(SubmissionActions.lockCode()),
saveCode: () => dispatch(CodeActions.save()),
selfMatch: (mapId: number) => dispatch(SubmissionActions.selfMatch(mapId)),
updateMap: (map: SubmitBarInterfaces.Map) => dispatch(SubmissionActions.updateMap(map)),
};
};

Expand Down
8 changes: 8 additions & 0 deletions src/app/reducers/code/Submission.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { SubmissionActions } from 'app/actions';
import * as SubmissionInterfaces from 'app/types/code/Submission';
import * as SubmitBarInterfaces from 'app/types/SubmitBar';

const submissionStoreState: SubmissionInterfaces.SubmissionStoreState = {
aiIds: [],
Expand All @@ -10,6 +11,7 @@ const submissionStoreState: SubmissionInterfaces.SubmissionStoreState = {
mapId: 1,
maps: [],
request: SubmissionInterfaces.Request.NONE,
selectedMap: SubmitBarInterfaces.Map.MAP1,
state: SubmissionInterfaces.RequestState.IDLE,
};

Expand All @@ -36,6 +38,12 @@ export const submissionReducer = (
mapId: action.payload.mapId,
};
}
case SubmissionActions.Type.UPDATE_MAP: {
return {
...state,
selectedMap: action.payload.map,
};
}
case SubmissionActions.Type.UPDATE_CURRENT_AI_ID: {
return {
...state,
Expand Down
32 changes: 32 additions & 0 deletions src/app/styles/SubmitBar.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
position: fixed;
box-sizing: border-box;
z-index: 1;
transition: 2s ease-in;
}

.SubmitBar .customBtn {
Expand Down Expand Up @@ -48,3 +49,34 @@
padding-right: 0px;
border-right: 0px;
}

.mapDropdown {
width: 100px;
height: 168px;
background-color: #525252;
color: white;
margin-left: 90px;
margin-top: 5px;
overflow: hidden;
display: flex;
flex-direction: column;
transition: max-height 0.7s ease;
}

.mapDropdownInactive {
display: none;
}

.mapItem {
width: 100%;
margin-top: 3px;
text-align: center;
height: 30px;
}

.mapItem:hover {
background-color: #292929;
}
.mapItemActive {
background-color: #292929;
}
11 changes: 11 additions & 0 deletions src/app/types/SubmitBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,23 @@ import { SubmissionActions } from 'app/actions';
import * as SubmissionInterfaces from 'app/types/code/Submission';
import { SplitPaneState } from 'app/types/Dashboard';

export enum Map {
MAP1,
MAP2,
MAP3,
MAP4,
MAP5,
}

export interface State {
commitMessage: string;
isCommitMessageBoxOpen: boolean;
isRunOptionsOpen: boolean;
isMapOptionsOpen: boolean;
}

export interface StateProps {
map: Map;
maps: SubmissionInterfaces.Map[];
debugRunAvailable: boolean;
aiIds: number[];
Expand All @@ -25,6 +35,7 @@ export interface DispatchProps {
loadMaps: () => void;
getAiIds: () => void;
clearLogs: () => void;
updateMap: (map: Map) => void;
}

export interface RunOptionsOwnState {
Expand Down
3 changes: 3 additions & 0 deletions src/app/types/code/Submission.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { SubmissionActions } from 'app/actions';
import * as SubmitBarInterfaces from 'app/types/SubmitBar';
import { ActionType } from 'typesafe-actions';

const actions = {
Expand All @@ -11,6 +12,7 @@ const actions = {
updateDebugRunCode: SubmissionActions.updateDebugRunCode,
updateDebugRunCommitHash: SubmissionActions.updateDebugRunCommitHash,
updateDebugRunRequest: SubmissionActions.updateDebugRunRequest,
updateMap: SubmissionActions.updateMap,
updateMapId: SubmissionActions.updateMapId,
};

Expand Down Expand Up @@ -43,6 +45,7 @@ export interface SubmissionStoreState {
debugRunCommitHash: string;
mapId: number;
maps: Map[];
selectedMap: SubmitBarInterfaces.Map;
}

export interface Map {
Expand Down