Skip to content

PROD-2649 - handle mobile fixes #40

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

Merged
merged 1 commit into from
Aug 1, 2022
Merged
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
7 changes: 7 additions & 0 deletions client/src/templates/Challenges/classic/classic.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@
padding-bottom: 16px;
}

#challenge-page-tabs .tab-content.no-toolpanel {
height: calc(
100vh - var(--header-height, 0px) - var(--flash-message-height, 0px) - 24px -
16px
);
}

#challenge-page-tabs .tab-pane {
height: 100%;
overflow: hidden;
Expand Down
6 changes: 5 additions & 1 deletion client/src/templates/Challenges/classic/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,11 @@ const Editor = (props: EditorProps): JSX.Element => {
focusIfTargetEditor();
}

if (props.initialTests) initTests(props.initialTests);
// Once a challenge has been completed, we don't want changes to the content
// to reset the tests since the user is already done with the challenge.
if (props.initialTests && !challengeIsComplete()) {
initTests(props.initialTests);
}

if (hasEditableRegion() && editor) {
if (props.isResetting) {
Expand Down
34 changes: 29 additions & 5 deletions client/src/templates/Challenges/classic/mobile-layout.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import React, { Component, ReactElement } from 'react';
import { connect } from 'react-redux';
import { createSelector } from 'reselect';

import { Test } from '../../../redux/prop-types';
import ToolPanel from '../components/tool-panel';
import { challengeTestsSelector } from '../redux';
import MobilePaneSelector, { Tab } from './mobile-pane-selector';

const mapStateToProps = createSelector(
challengeTestsSelector,
(tests: Test[]) => ({
tests
})
);
interface MobileLayoutProps {
editor: JSX.Element | null;
guideUrl: string;
Expand All @@ -15,6 +25,8 @@ interface MobileLayoutProps {
testOutput: JSX.Element;
videoUrl: string;
usesMultifileEditor: boolean;
testsRunning: boolean;
tests: Test[];
}

interface MobileLayoutState {
Expand Down Expand Up @@ -45,11 +57,13 @@ class MobileLayout extends Component<MobileLayoutProps, MobileLayoutState> {
hasPreview,
notes,
preview,
guideUrl,
videoUrl,
tests,
testsRunning,
usesMultifileEditor
} = this.props;

const isChallengeComplete = tests.every(test => test.pass && !test.err);

// Unlike the desktop layout the mobile version does not have an ActionRow,
// but still needs a way to switch between the different tabs.

Expand All @@ -63,19 +77,29 @@ class MobileLayout extends Component<MobileLayoutProps, MobileLayoutState> {
hasNotes={hasNotes}
usesMultifileEditor={usesMultifileEditor}
/>
<div className='tab-content'>
<div
className={`tab-content ${
hasEditableBoundaries ? 'no-toolpanel' : ''
}`}
>
{currentTab === Tab.Editor && editor}
{currentTab === Tab.Instructions && instructions}
{currentTab === Tab.Console && testOutput}
{currentTab === Tab.Notes && notes}
{currentTab === Tab.Preview && preview}
</div>
<ToolPanel guideUrl={guideUrl} isMobile={true} videoUrl={videoUrl} />
{!hasEditableBoundaries && (
<ToolPanel
isMobile={true}
isRunningTests={testsRunning}
challengeIsCompleted={isChallengeComplete}
/>
)}
</div>
);
}
}

MobileLayout.displayName = 'MobileLayout';

export default MobileLayout;
export default connect(mapStateToProps)(MobileLayout);
3 changes: 2 additions & 1 deletion client/src/templates/Challenges/classic/show.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ class ShowClassic extends Component<ShowClassicProps, ShowClassicState> {
<Helmet title={`${this.getBlockNameTitle(t)} | freeCodeCamp.org`} />
<Media maxWidth={MAX_MOBILE_WIDTH}>
<MobileLayout
editor={this.renderEditor()}
editor={this.renderEditor(hasEditableBoundaries)}
guideUrl={getGuideUrl({ forumTopicId, title })}
hasEditableBoundaries={hasEditableBoundaries}
hasNotes={!!notes}
Expand All @@ -459,6 +459,7 @@ class ShowClassic extends Component<ShowClassicProps, ShowClassicState> {
testOutput={this.renderTestOutput()}
usesMultifileEditor={usesMultifileEditor}
videoUrl={this.getVideoUrl()}
testsRunning={this.props.testsRunning}
/>
</Media>
<Media minWidth={MAX_MOBILE_WIDTH + 1}>
Expand Down
1 change: 1 addition & 0 deletions client/src/templates/Challenges/components/output.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
width: 100%;
overflow-y: auto;
background: var(--tc-black-5);
margin-bottom: 0;
}

pre.output-text code {
Expand Down
4 changes: 2 additions & 2 deletions client/src/templates/Challenges/components/tool-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ interface ToolPanelProps {
openHelpModal: () => void;
openVideoModal: () => void;
openResetModal: () => void;
guideUrl: string;
videoUrl: string;
guideUrl?: string;
videoUrl?: string;
challengeIsCompleted?: boolean;
}

Expand Down