From 406fdb68d4534607590075e311fe5959815b9e95 Mon Sep 17 00:00:00 2001 From: chrystalquek Date: Wed, 8 Apr 2020 00:00:09 +0800 Subject: [PATCH 1/8] Added Dropdown to change Default Source version --- src/actions/actionTypes.ts | 3 + src/actions/workspaces.ts | 11 ++++ src/components/Playground.tsx | 2 + src/components/__tests__/Playground.tsx | 3 +- src/components/academy/DefaultChapter.tsx | 70 +++++++++++++++++++++++ src/components/academy/NavigationBar.tsx | 5 ++ src/containers/DefaultChapterContainer.ts | 31 ++++++++++ src/containers/PlaygroundContainer.ts | 4 +- src/reducers/workspaces.ts | 15 ++++- src/sagas/backend.ts | 44 ++++++++++++++ src/sagas/requests.ts | 34 +++++++++++ 11 files changed, 219 insertions(+), 3 deletions(-) create mode 100644 src/components/academy/DefaultChapter.tsx create mode 100644 src/containers/DefaultChapterContainer.ts diff --git a/src/actions/actionTypes.ts b/src/actions/actionTypes.ts index 1329731088..fe4dba8281 100755 --- a/src/actions/actionTypes.ts +++ b/src/actions/actionTypes.ts @@ -58,6 +58,9 @@ export const UPDATE_EDITOR_BREAKPOINTS = 'UPDATE_EDITOR_BREAKPOINTS'; export const UPDATE_HAS_UNSAVED_CHANGES = 'UPDATE_HAS_UNSAVED_CHANGES'; export const UPDATE_REPL_VALUE = 'UPDATE_REPL_VALUE'; export const UPDATE_WORKSPACE = 'UPDATE_WORKSPACE'; +export const FETCH_CHAPTER = 'FETCH_CHAPTER'; +export const UPDATE_CHAPTER = 'UPDATE_CHAPTER'; +export const CHANGE_CHAPTER = 'CHANGE_CHAPTER'; /** Collab Editing */ export const INIT_INVITE = 'INIT_INVITE'; diff --git a/src/actions/workspaces.ts b/src/actions/workspaces.ts index b97f179ffd..c1759023b7 100755 --- a/src/actions/workspaces.ts +++ b/src/actions/workspaces.ts @@ -209,3 +209,14 @@ export const updateHasUnsavedChanges = ( workspaceLocation, hasUnsavedChanges }); + +export const fetchChapter = () => + action(actionTypes.FETCH_CHAPTER); + +// update database +export const changeChapter = (chapterno: number) => + action(actionTypes.CHANGE_CHAPTER, { chapterno }); + +// update state +export const updateChapter = (chapterno: number) => + action(actionTypes.UPDATE_CHAPTER, chapterno); diff --git a/src/components/Playground.tsx b/src/components/Playground.tsx index 21442dc84f..5384b7ecc8 100755 --- a/src/components/Playground.tsx +++ b/src/components/Playground.tsx @@ -104,6 +104,7 @@ export interface IDispatchProps { handleDebuggerResume: () => void; handleDebuggerReset: () => void; handleToggleEditorAutorun: () => void; + handleFetchChapter: () => void; } type PlaygroundState = { @@ -125,6 +126,7 @@ class Playground extends React.Component { }; this.handlers.goGreen = this.toggleIsGreen.bind(this); (window as any).thePlayground = this; + this.props.handleFetchChapter(); } public render() { diff --git a/src/components/__tests__/Playground.tsx b/src/components/__tests__/Playground.tsx index 05897cd15e..941673bbbe 100755 --- a/src/components/__tests__/Playground.tsx +++ b/src/components/__tests__/Playground.tsx @@ -54,7 +54,8 @@ const baseProps = { handleUsingSubst: (usingSubst: boolean) => {}, handleDebuggerPause: () => {}, handleDebuggerResume: () => {}, - handleDebuggerReset: () => {} + handleDebuggerReset: () => {}, + handleFetchChapter: () => {} }; const testValueProps: IPlaygroundProps = { diff --git a/src/components/academy/DefaultChapter.tsx b/src/components/academy/DefaultChapter.tsx new file mode 100644 index 0000000000..7630447f81 --- /dev/null +++ b/src/components/academy/DefaultChapter.tsx @@ -0,0 +1,70 @@ +import { Button, Classes, MenuItem } from '@blueprintjs/core'; +import { IconNames } from '@blueprintjs/icons'; +import { ItemRenderer , Select} from '@blueprintjs/select'; +// +import * as React from 'react'; + +import { RouteComponentProps } from 'react-router'; + +import { sourceChapters } from '../../reducers/states'; + +export interface IChapterProps extends IDispatchProps, IStateProps, RouteComponentProps<{}> {} + +export type IDispatchProps = { + handleFetchChapter: () => void; + handleUpdateChapter: (chapter: IChapter) => void; + handleChapterSelect?: (i: IChapter, e: React.ChangeEvent) => void; +}; + +export interface IStateProps { + sourceChapter: number; +} + +export interface IChapter { + chapter: number; + displayName: string; +} + +// class DefaultChapter extends React.Component { +export function DefaultChapter(props: IChapterProps) { + props.handleFetchChapter(); + const styliseChapter = (chap: number) => `Source \xa7${chap}`; + const chapters = sourceChapters.map(chap => ({ + displayName: styliseChapter(chap), + chapter: chap + })); + + const chapterRenderer: ItemRenderer = (chap, { handleClick }) => ( + + ); + + const ChapterSelectComponent = Select.ofType(); + + const chapSelect = ( + currentChap: number, + handleSelect = (i: IChapter) => {} + ) => ( + +