Skip to content

Tca 299 UI for js course #44

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 4 commits into from
Aug 15, 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
2 changes: 1 addition & 1 deletion client/src/components/formHelpers/block-save-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useTranslation } from 'react-i18next';
function BlockSaveButton(props?: Record<string, unknown>): JSX.Element {
const { t } = useTranslation();
return (
<Button block={true} bsStyle='primary' {...props} type='submit'>
<Button bsStyle='primary' {...props} type='submit'>
{props?.children || t('buttons.save')}
</Button>
);
Expand Down
51 changes: 24 additions & 27 deletions client/src/components/formHelpers/form-fields.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
Alert,
Col,
ControlLabel,
FormControl,
FormGroup,
Expand Down Expand Up @@ -72,7 +71,7 @@ function FormFields(props: FormFieldsProps): JSX.Element {
) : null;
};
return (
<div>
<>
{formFields
.filter(formField => !ignored.includes(formField.name))
.map(({ name, label }) => (
Expand All @@ -85,35 +84,33 @@ function FormFields(props: FormFieldsProps): JSX.Element {
name in placeholders ? placeholders[name] : '';
const isURL = types[name] === 'url';
return (
<Col key={key} xs={12}>
<FormGroup>
{type === 'hidden' ? null : (
<ControlLabel htmlFor={key}>{label}</ControlLabel>
)}
<FormControl
componentClass={type === 'textarea' ? type : 'input'}
id={key}
name={name}
onChange={onChange}
placeholder={placeholder}
required={required.includes(name)}
rows={4}
type={type}
value={value as string}
/>
{nullOrWarning(
value as string,
!pristine && error,
isURL,
name
)}
</FormGroup>
</Col>
<FormGroup key={key} className='embedded'>
{type === 'hidden' ? null : (
<ControlLabel htmlFor={key}>{label}</ControlLabel>
)}
<FormControl
componentClass={type === 'textarea' ? type : 'input'}
id={key}
name={name}
onChange={onChange}
placeholder={placeholder}
required={required.includes(name)}
rows={4}
type={type}
value={value as string}
/>
{nullOrWarning(
value as string,
!pristine && error,
isURL,
name
)}
</FormGroup>
);
}}
</Field>
))}
</div>
</>
);
}

Expand Down
17 changes: 7 additions & 10 deletions client/src/components/formHelpers/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
ValidatedValues,
FormFields,
BlockSaveButton,
BlockSaveWrapper,
formatUrlValues
} from '../formHelpers/index';

Expand Down Expand Up @@ -54,15 +53,13 @@ function DynamicForm({
style={{ width: '100%' }}
>
<FormFields formFields={formFields} options={options} />
<BlockSaveWrapper>
{hideButton ? null : (
<BlockSaveButton
disabled={(pristine && !enableSubmit) || (error as boolean)}
>
{buttonText ? buttonText : null}
</BlockSaveButton>
)}
</BlockSaveWrapper>
{!hideButton && (
<BlockSaveButton
disabled={(pristine && !enableSubmit) || (error as boolean)}
>
{buttonText ? buttonText : null}
</BlockSaveButton>
)}
</form>
)}
</Form>
Expand Down
32 changes: 31 additions & 1 deletion client/src/components/layouts/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -491,13 +491,43 @@ fieldset[disabled] .btn-primary.focus {
}
}

.button-group .btn:not(:last-child) {
.button-group {
margin-bottom: -10px;
}
.button-group .btn {
margin-bottom: 10px;
}
strong {
color: var(--secondary-color);
}

.form-group.embedded {
border: 1px solid var(--tc-black-40);
padding: 8px 10px 2px;
border-radius: 4px;
position: relative;
max-width: 320px;
}

.form-group.embedded .control-label {
display: block;
font-size: 11px;
font-family: 'Roboto';
line-height: 10px;
color: var(--tc-turq-160);
margin-bottom: 4px;
}

.form-group.embedded .form-control {
border: 0 none;
padding: 0;
height: 22px;
font-size: 14px;
line-height: 22px;
font-family: 'Roboto';
color: var(--tc-black-100);
}

.form-control {
color: var(--primary-color);
outline: none;
Expand Down
4 changes: 4 additions & 0 deletions client/src/components/layouts/learn.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@
#learn-app-wrapper .reflex-container.horizontal > .reflex-splitter {
height: 5px;
}

#learn-app-wrapper .reflex-container > .reflex-element:first-child:last-child {
flex: 1 1 auto !important;
}
10 changes: 10 additions & 0 deletions client/src/components/layouts/prism.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
pre[class*='language-'].line-numbers.line-numbers {
border-radius: 8px;
font-size: 14px;
line-height: 22px;
}

code .token.operator {
background: none;
}
Expand All @@ -7,6 +13,10 @@ pre[class*='language-'] {
background: var(--primary-background);
}

.line-numbers > p {
color: var(--tc-black-100);
}

.default pre[class*='language-']::selection,
.default pre[class*='language-'] ::selection,
.default code[class*='language-']::selection,
Expand Down
2 changes: 2 additions & 0 deletions client/src/components/layouts/variables.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
--tc-link-blue-light: #5fb7ee;
--tc-black: #000;
--tc-black-100: #2a2a2a;
--tc-black-60: #7f7f7f;
--tc-black-40: #aaaaaa;
--tc-black-20: #d4d4d4;
--tc-black-10: #e9e9e9;
--tc-black-5: #f4f4f4;
Expand Down
43 changes: 22 additions & 21 deletions client/src/templates/Challenges/classic/action-row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import EditorTabs from './editor-tabs';
interface ActionRowProps {
block: string;
hasNotes: boolean;
hasPreview: boolean;
isMultifileCertProject: boolean;
showInstructions: boolean;
showConsole: boolean;
Expand All @@ -25,10 +26,10 @@ const mapDispatchToProps = {

const ActionRow = ({
hasNotes,
hasPreview,
togglePane,
showNotes,
showPreview,
isMultifileCertProject,
showInstructions,
showConsole,
superBlock,
Expand All @@ -44,17 +45,15 @@ const ActionRow = ({
</div>
)}
<div className='tabs-row'>
{isMultifileCertProject && (
<button
aria-expanded={showInstructions ? 'true' : 'false'}
className={
showInstructions ? 'btn-tab-primary' : 'btn-tab-primary--outline'
}
onClick={() => togglePane('showInstructions')}
>
Instructions
</button>
)}
<button
aria-expanded={showInstructions ? 'true' : 'false'}
className={
showInstructions ? 'btn-tab-primary' : 'btn-tab-primary--outline'
}
onClick={() => togglePane('showInstructions')}
>
Instructions
</button>
<EditorTabs />
<button
aria-expanded={showConsole ? 'true' : 'false'}
Expand All @@ -76,15 +75,17 @@ const ActionRow = ({
{t('learn.editor-tabs.notes')}
</button>
)}
<button
aria-expanded={showPreview ? 'true' : 'false'}
className={
showPreview ? 'btn-tab-primary' : 'btn-tab-primary--outline'
}
onClick={() => togglePane('showPreview')}
>
{t('learn.editor-tabs.preview')}
</button>
{hasPreview && (
<button
aria-expanded={showPreview ? 'true' : 'false'}
className={
showPreview ? 'btn-tab-primary' : 'btn-tab-primary--outline'
}
onClick={() => togglePane('showPreview')}
>
{t('learn.editor-tabs.preview')}
</button>
)}
</div>
</div>
);
Expand Down
52 changes: 26 additions & 26 deletions client/src/templates/Challenges/classic/desktop-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ interface DesktopLayoutProps {
resizeProps: ResizeProps;
superBlock: string;
testOutput: ReactElement;
visibleEditors: { [key: string]: boolean };
}

const reflexProps = {
Expand Down Expand Up @@ -85,20 +86,20 @@ const DesktopLayout = (props: DesktopLayoutProps): JSX.Element => {
notes,
preview,
hasEditableBoundaries,
superBlock
superBlock,
visibleEditors
} = props;

const challengeFile = getChallengeFile();
const projectBasedChallenge = hasEditableBoundaries;
const isMultifileCertProject =
challengeType === challengeTypes.multifileCertProject;
const displayPreview =
projectBasedChallenge || isMultifileCertProject
? showPreview && hasPreview
: hasPreview;
const displayPreview = showPreview && hasPreview;
const displayNotes = projectBasedChallenge ? showNotes && hasNotes : false;
const displayConsole =
projectBasedChallenge || isMultifileCertProject ? showConsole : true;
const displayConsole = showConsole;
const displayEditor = Object.entries(visibleEditors).some(
([, visible]) => visible
);
const {
codePane,
editorPane,
Expand All @@ -110,33 +111,32 @@ const DesktopLayout = (props: DesktopLayoutProps): JSX.Element => {

return (
<div className='desktop-layout'>
{(projectBasedChallenge || isMultifileCertProject) && (
<ActionRow
block={block}
hasNotes={hasNotes}
isMultifileCertProject={isMultifileCertProject}
showConsole={showConsole}
showNotes={showNotes}
showInstructions={showInstructions}
showPreview={showPreview}
superBlock={superBlock}
showBreadcrumbs={false}
togglePane={togglePane}
/>
)}
<ActionRow
block={block}
hasNotes={hasNotes}
isMultifileCertProject={isMultifileCertProject}
showConsole={showConsole}
showNotes={showNotes}
showInstructions={showInstructions}
hasPreview={hasPreview}
showPreview={showPreview}
superBlock={superBlock}
showBreadcrumbs={false}
togglePane={togglePane}
/>
<div className='editor-row'>
<ReflexContainer orientation='vertical'>
{!projectBasedChallenge && showInstructions && (
<ReflexElement flex={instructionPane.flex} {...resizeProps}>
{instructions}
</ReflexElement>
)}
{!projectBasedChallenge && (
{!projectBasedChallenge && displayEditor && (
<ReflexSplitter propagate={true} {...resizeProps} />
)}

<ReflexElement flex={editorPane.flex} {...resizeProps}>
{challengeFile && (
{challengeFile && displayEditor && (
<ReflexElement flex={editorPane.flex} {...resizeProps}>
<ReflexContainer
key={challengeFile.fileKey}
orientation='horizontal'
Expand All @@ -157,8 +157,8 @@ const DesktopLayout = (props: DesktopLayoutProps): JSX.Element => {
</ReflexElement>
)}
</ReflexContainer>
)}
</ReflexElement>
</ReflexElement>
)}

{(displayPreview || displayConsole) && (
<ReflexSplitter propagate={true} {...resizeProps} />
Expand Down
4 changes: 3 additions & 1 deletion client/src/templates/Challenges/classic/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,9 @@ const Editor = (props: EditorProps): JSX.Element => {
attemptRef.current.attempts++;
}

const tryToSubmitChallenge = debounce(props.submitChallenge, 2000);
const tryToSubmitChallenge = debounce(props.submitChallenge, 2000, {
leading: true
});

function createLowerJaw(outputNode: HTMLElement, callback?: () => void) {
const { output } = props;
Expand Down
Loading