Skip to content

Clean up some tabs #465

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

Draft
wants to merge 1 commit into
base: yarn-workspaces
Choose a base branch
from
Draft
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
6 changes: 2 additions & 4 deletions src/tabs/Csg/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ import { IconNames } from '@blueprintjs/icons';
import { Core } from '@sourceacademy/bundle-csg/core';
import type { CsgModuleState } from '@sourceacademy/bundle-csg/utilities';
import { defineTab } from '@sourceacademy/modules-lib/tabs/utils';
import type { DebuggerContext } from '@sourceacademy/modules-lib/types';
import type { ReactElement } from 'react';
import CanvasHolder from './canvas_holder';

/* [Exports] */
export default defineTab({
// Called by the frontend to decide whether to spawn the CSG tab
toSpawn(debuggerContext: DebuggerContext): boolean {
toSpawn(debuggerContext) {
const moduleState: CsgModuleState = debuggerContext.context.moduleContexts.csg.state;
// toSpawn() is checked before the frontend calls body() if needed, so we
// initialise Core for the first time over on the tabs' end here
Expand All @@ -20,7 +18,7 @@ export default defineTab({
.shouldRender();
},
// Called by the frontend to know what to render in the CSG tab
body(_debuggerContext: DebuggerContext): ReactElement {
body() {
return (
<CanvasHolder
componentNumber={Core.nextComponent()}
Expand Down
6 changes: 3 additions & 3 deletions src/tabs/Curve/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import AnimationCanvas from '@sourceacademy/modules-lib/tabs/AnimationCanvas';
import MultiItemDisplay from '@sourceacademy/modules-lib/tabs/MultItemDisplay';
import WebGLCanvas from '@sourceacademy/modules-lib/tabs/WebglCanvas';
import { defineTab, getModuleState } from '@sourceacademy/modules-lib/tabs/utils';
import { glAnimation, type DebuggerContext, type ModuleTab } from '@sourceacademy/modules-lib/types';
import { glAnimation, type ModuleTab } from '@sourceacademy/modules-lib/types';
import Curve3DAnimationCanvas from './animation_canvas_3d_curve';
import CurveCanvas3D from './canvas_3d_curve';

Expand Down Expand Up @@ -43,11 +43,11 @@ export const CurveTab: ModuleTab = ({ context }) => {
};

export default defineTab({
toSpawn(context: DebuggerContext) {
toSpawn(context) {
const drawnCurves = context.context?.moduleContexts?.curve?.state?.drawnCurves;
return drawnCurves.length > 0;
},
body(context: DebuggerContext) {
body(context) {
return <CurveTab context={context} />;
},
label: 'Curves Tab',
Expand Down
52 changes: 21 additions & 31 deletions src/tabs/Game/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,31 @@ import { defineTab } from '@sourceacademy/modules-lib/tabs/utils';
import React from 'react';
import { Links } from './constants';

type Props = {
children?: never;
className?: string;
debuggerContext?: any;
const Game: React.FC = () => {
return <div>
Info: You need to visit the game to see the effect of your program.
Remember to save your work first!
<br />
<br />
You may find the game module{' '}
<a
href={Links.gameAPIDocumentation}
rel="noopener noreferrer"
target="_blank"
>
documentation{' '}
</a>
and{' '}
<a href={Links.gameUserGuide} rel="noopener noreferrer" target="_blank">
user guide{' '}
</a>
useful.
</div>;
};

class Game extends React.PureComponent<Props> {
public render() {
return (
<div>
Info: You need to visit the game to see the effect of your program.
Remember to save your work first!
<br />
<br />
You may find the game module{' '}
<a
href={Links.gameAPIDocumentation}
rel="noopener noreferrer"
target="_blank"
>
documentation{' '}
</a>
and{' '}
<a href={Links.gameUserGuide} rel="noopener noreferrer" target="_blank">
user guide{' '}
</a>
useful.
</div>
);
}
}

export default defineTab({
toSpawn: () => true,
body: (debuggerContext: any) => <Game debuggerContext={debuggerContext} />,
body: () => <Game />,
label: 'Game Info Tab',
iconName: 'info-sign'
});
9 changes: 4 additions & 5 deletions src/tabs/MarkSweep/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Slider, Icon } from '@blueprintjs/core';
import { Icon, Slider } from '@blueprintjs/core';
import { defineTab } from '@sourceacademy/modules-lib/tabs/utils';
import type { DebuggerContext } from '@sourceacademy/modules-lib/types/index';
import React from 'react';
import { ThemeColor } from './style';

type Props = {
children?: never;
className?: string;
debuggerContext: any;
debuggerContext: DebuggerContext;
};

type State = {
Expand Down Expand Up @@ -466,7 +465,7 @@ class MarkSweep extends React.Component<Props, State> {

export default defineTab({
toSpawn: () => true,
body: (debuggerContext: any) => (
body: (debuggerContext) => (
<MarkSweep debuggerContext={debuggerContext} />
),
label: 'Mark Sweep Garbage Collector',
Expand Down
8 changes: 2 additions & 6 deletions src/tabs/Nbody/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Button, ButtonGroup, NumericInput } from '@blueprintjs/core';
import { IconNames } from '@blueprintjs/icons';
import { defineTab } from '@sourceacademy/modules-lib/tabs/utils';
import type { DebuggerContext } from '@sourceacademy/modules-lib/types/index';
import type { Simulation } from 'nbody';
import React from 'react';

Expand All @@ -13,9 +14,7 @@ import React from 'react';
* React Component props for the Tab.
*/
type Props = {
children?: never;
className?: never;
context?: any;
context: DebuggerContext;
};

/**
Expand All @@ -27,9 +26,6 @@ type State = {};
* React component props for the control buttons.
*/
type SimControlProps = {
children?: never;
className?: never;
context?: any;
sim: Simulation;
};

Expand Down
5 changes: 2 additions & 3 deletions src/tabs/Painter/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import type { LinePlot } from '@sourceacademy/bundle-painter/painter';
import Modal from '@sourceacademy/modules-lib/tabs/ModalDiv';
import { defineTab } from '@sourceacademy/modules-lib/tabs/utils';
import type { DebuggerContext } from '@sourceacademy/modules-lib/types/index';
import React from 'react';

type Props = {
children?: never
className?: string
debuggerContext: any
debuggerContext: DebuggerContext
};

type State = {
Expand Down
5 changes: 2 additions & 3 deletions src/tabs/Pixnflix/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ import {
type TabsPacket
} from '@sourceacademy/bundle-pix_n_flix/types';
import { defineTab } from '@sourceacademy/modules-lib/tabs/utils';
import type { DebuggerContext } from '@sourceacademy/modules-lib/types/index';
import React, { type ChangeEvent, type DragEvent } from 'react';

type Props = {
children?: never;
className?: string;
debuggerContext: any;
debuggerContext: DebuggerContext;
};

enum VideoMode {
Expand Down
5 changes: 2 additions & 3 deletions src/tabs/Plotly/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import type { DrawnPlot } from '@sourceacademy/bundle-plotly/plotly';
import Modal from '@sourceacademy/modules-lib/tabs/ModalDiv';
import { defineTab } from '@sourceacademy/modules-lib/tabs/utils';
import type { DebuggerContext } from '@sourceacademy/modules-lib/types/index';
import React from 'react';

type Props = {
children?: never
className?: string
debuggerContext: any
debuggerContext: DebuggerContext
};

type State = {
Expand Down
14 changes: 3 additions & 11 deletions src/tabs/Repeat/index.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
import { defineTab } from '@sourceacademy/modules-lib/tabs/utils';
import React from 'react';

type Props = {
children?: never;
className?: string;
debuggerContext?: any;
const Repeat: React.FC = () => {
return <div>This is spawned from the repeat package</div>;
};

class Repeat extends React.PureComponent<Props> {
public render() {
return <div>This is spawned from the repeat package</div>;
}
}

export default defineTab({
toSpawn: () => true,
body: (debuggerContext: any) => <Repeat debuggerContext={debuggerContext} />,
body: () => <Repeat />,
label: 'Repeat Test Tab',
iconName: 'build'
});
2 changes: 1 addition & 1 deletion src/tabs/Repl/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import { defineTab } from '@sourceacademy/modules-lib/tabs/utils';
import React from 'react';
import AceEditor from 'react-ace';

import 'ace-builds/src-noconflict/ext-language_tools';
import 'ace-builds/src-noconflict/mode-javascript';
import 'ace-builds/src-noconflict/theme-twilight';
import 'ace-builds/src-noconflict/ext-language_tools';

type Props = {
programmableReplInstance: ProgrammableRepl;
Expand Down
6 changes: 3 additions & 3 deletions src/tabs/Sound/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { SoundModuleState } from '@sourceacademy/bundle-sound/types';
import MultiItemDisplay from '@sourceacademy/modules-lib/tabs/MultItemDisplay';
import { defineTab, getModuleState } from '@sourceacademy/modules-lib/tabs/utils';
import type { DebuggerContext, ModuleTab } from '@sourceacademy/modules-lib/types';
import type { ModuleTab } from '@sourceacademy/modules-lib/types';

/**
* Tab for Source Academy Sounds Module
Expand Down Expand Up @@ -35,11 +35,11 @@ const SoundTab: ModuleTab = ({ context }) => {
};

export default defineTab({
toSpawn(context: DebuggerContext) {
toSpawn(context) {
const audioPlayed = context.context?.moduleContexts?.sound?.state?.audioPlayed;
return audioPlayed.length > 0;
},
body(context: DebuggerContext) {
body(context) {
return <SoundTab context={context} />;
},
label: 'Sounds',
Expand Down