Skip to content
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

Decouple Playground from SICP Workspace #2487

Draft
wants to merge 29 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
476b3a2
Duplicate Playground as SicpWorkspace
RichDom2185 May 18, 2023
3104d66
Remove isSicpEditor prop from SicpWorkspace
RichDom2185 May 18, 2023
2243494
Remove isSicpEditor prop from Playground
RichDom2185 May 18, 2023
8531c98
Remove remote execution logic from SicpWorkspace
RichDom2185 May 18, 2023
3e14d69
Merge branch 'master' into 23-summer/decouple-playground-sicp
RichDom2185 May 18, 2023
8d385af
Merge branch 'master' into 23-summer/decouple-playground-sicp
RichDom2185 May 23, 2023
f8e1d43
Merge branch 'master' of https://github.com/RichDom2185/source-academ…
RichDom2185 May 24, 2023
01b6a4c
Copy over Playground changes post-merge
RichDom2185 May 24, 2023
087eb27
Merge branch 'master' into 23-summer/decouple-playground-sicp
RichDom2185 May 25, 2023
e677142
Undo removal of isSicpEditor prop from Playground
RichDom2185 Jun 14, 2023
1633f86
Merge branch 'master' of https://github.com/RichDom2185/source-academ…
RichDom2185 Jun 14, 2023
89072a1
Migrate over merged changes to SicpWorkspace
RichDom2185 Jun 14, 2023
bb6ee59
Restore changes to Playground post-merge
RichDom2185 Jun 14, 2023
6511478
Update snapshots post-merge
RichDom2185 Jun 14, 2023
85c5fed
Merge branch 'master' into 23-summer/decouple-playground-sicp
RichDom2185 Jun 16, 2023
af9ba59
Merge branch 'master' into 23-summer/decouple-playground-sicp
RichDom2185 Jun 19, 2023
0750228
Merge branch 'master' into 23-summer/decouple-playground-sicp
RichDom2185 Jun 19, 2023
0861029
Merge branch 'master' of https://github.com/RichDom2185/source-academ…
RichDom2185 Jun 20, 2023
7dcd0ef
Migrate over merged changes to SicpWorkspace
RichDom2185 Jun 20, 2023
c185393
Merge branch 'master' into 23-summer/decouple-playground-sicp
RichDom2185 Jun 20, 2023
133da60
Merge branch 'master' into 23-summer/decouple-playground-sicp
RichDom2185 Jun 20, 2023
f9139d5
Merge branch 'master' of https://github.com/RichDom2185/source-academ…
RichDom2185 Jun 20, 2023
6bcb6cc
Migrate over merged changes to SicpWorkspace
RichDom2185 Jun 20, 2023
9c8d6f9
Merge branch 'master' of https://github.com/RichDom2185/source-academ…
RichDom2185 Jun 21, 2023
9aff774
Merge branch 'master' into 23-summer/decouple-playground-sicp
RichDom2185 Jun 22, 2023
6723bfb
Migrate over merged changes to SicpWorkspace
RichDom2185 Jun 22, 2023
598d981
Merge branch 'master' into 23-summer/decouple-playground-sicp
RichDom2185 Jul 5, 2023
3699a27
Merge branch 'master' into 23-summer/decouple-playground-sicp
RichDom2185 Jul 29, 2023
352ed8b
Merge branch 'master' into 23-summer/decouple-playground-sicp
RichDom2185 Aug 4, 2023
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
43 changes: 11 additions & 32 deletions src/pages/playground/Playground.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Classes } from '@blueprintjs/core';
import { IconNames } from '@blueprintjs/icons';
import { Ace, Range } from 'ace-builds';
import { FSModule } from 'browserfs/dist/node/core/FS';
import classNames from 'classnames';
import { Chapter, Variant } from 'js-slang/dist/types';
Expand Down Expand Up @@ -115,7 +114,6 @@ import MobileWorkspace, {
} from '../../commons/mobileWorkspace/MobileWorkspace';
import { SideBarTab } from '../../commons/sideBar/SideBar';
import { SideContentTab, SideContentType } from '../../commons/sideContent/SideContentTypes';
import { Links } from '../../commons/utils/Constants';
import { generateLanguageIntroduction } from '../../commons/utils/IntroductionHelper';
import { convertParamToBoolean, convertParamToInt } from '../../commons/utils/ParamParseHelper';
import { IParsedQuery, parseQuery } from '../../commons/utils/QueryHelper';
Expand All @@ -139,7 +137,6 @@ import {
} from './PlaygroundTabs';

export type PlaygroundProps = {
isSicpEditor?: boolean;
initialEditorValueHash?: string;
prependLength?: number;
handleCloseEditor?: () => void;
Expand Down Expand Up @@ -233,8 +230,7 @@ export async function handleHash(
}

const Playground: React.FC<PlaygroundProps> = props => {
const { isSicpEditor } = props;
const workspaceLocation: WorkspaceLocation = isSicpEditor ? 'sicp' : 'playground';
const workspaceLocation: WorkspaceLocation = 'playground';
const { isMobileBreakpoint } = useResponsive();

const [deviceSecret, setDeviceSecret] = useState<string | undefined>();
Expand Down Expand Up @@ -328,8 +324,7 @@ const Playground: React.FC<PlaygroundProps> = props => {
[deviceSecret]
);

const usingRemoteExecution =
useTypedSelector(state => !!state.session.remoteExecutionSession) && !isSicpEditor;
const usingRemoteExecution = useTypedSelector(state => !!state.session.remoteExecutionSession);
// this is still used by remote execution (EV3)
// specifically, for the editor Ctrl+B to work
const externalLibraryName = useTypedSelector(
Expand All @@ -348,7 +343,7 @@ const Playground: React.FC<PlaygroundProps> = props => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [editorSessionId]);

const hash = isSicpEditor ? props.initialEditorValueHash : location.hash;
const hash = location.hash;

useEffect(() => {
if (!hash) {
Expand Down Expand Up @@ -403,7 +398,7 @@ const Playground: React.FC<PlaygroundProps> = props => {
[isGreen]
);

const onEditorValueChange = React.useCallback(
const onEditorValueChange = useCallback(
(editorTabIndex: number, newEditorValue: string) => {
setLastEdit(new Date());
handleEditorValueChange(editorTabIndex, newEditorValue);
Expand Down Expand Up @@ -697,19 +692,19 @@ const Playground: React.FC<PlaygroundProps> = props => {
);

const shareButton = useMemo(() => {
const qs = isSicpEditor ? Links.playground + '#' + props.initialEditorValueHash : queryString;
const qs = queryString;
return (
<ControlBarShareButton
handleGenerateLz={() => dispatch(generateLzString())}
handleShortenURL={s => dispatch(shortenURL(s))}
handleUpdateShortURL={s => dispatch(updateShortURL(s))}
queryString={qs}
shortURL={shortURL}
isSicp={isSicpEditor}
isSicp={false}
key="share"
/>
);
}, [dispatch, isSicpEditor, props.initialEditorValueHash, queryString, shortURL]);
}, [dispatch, queryString, shortURL]);

const toggleFolderModeButton = useMemo(() => {
return (
Expand Down Expand Up @@ -776,17 +771,14 @@ const Playground: React.FC<PlaygroundProps> = props => {
}
}

if (!isSicpEditor) {
tabs.push(remoteExecutionTab);
}
tabs.push(remoteExecutionTab);

return tabs;
}, [
playgroundIntroductionTab,
languageConfig.chapter,
output,
usingRemoteExecution,
isSicpEditor,
dispatch,
workspaceLocation,
shouldShowDataVisualizer,
Expand All @@ -798,18 +790,6 @@ const Playground: React.FC<PlaygroundProps> = props => {
// Remove Intro and Remote Execution tabs for mobile
const mobileTabs = [...tabs].filter(({ id }) => !(id && desktopOnlyTabIds.includes(id)));

const onLoadMethod = useCallback(
(editor: Ace.Editor) => {
const addFold = () => {
editor.getSession().addFold(' ', new Range(1, 0, props.prependLength!, 0));
editor.renderer.off('afterRender', addFold);
};

editor.renderer.on('afterRender', addFold);
},
[props.prependLength]
);

const onChangeMethod = useCallback(
(newCode: string, delta: CodeDelta) => {
const input: Input = {
Expand Down Expand Up @@ -928,7 +908,6 @@ const Playground: React.FC<PlaygroundProps> = props => {
onChange: onChangeMethod,
onCursorChange: onCursorChangeMethod,
onSelectionChange: onSelectionChangeMethod,
onLoad: isSicpEditor && props.prependLength ? onLoadMethod : undefined,
sourceChapter: languageConfig.chapter,
externalLibraryName,
sourceVariant: languageConfig.variant,
Expand Down Expand Up @@ -960,7 +939,7 @@ const Playground: React.FC<PlaygroundProps> = props => {
selectedTab === SideContentType.envVisualizer,
inputHidden: replDisabled,
replButtons: [replDisabled ? null : evalButton, clearButton],
disableScrolling: isSicpEditor
disableScrolling: false
};

const sideBarProps: { tabs: SideBarTab[] } = useMemo(() => {
Expand Down Expand Up @@ -997,7 +976,7 @@ const Playground: React.FC<PlaygroundProps> = props => {
autorunButtons,
languageConfig.chapter === Chapter.FULL_JS ? null : shareButton,
chapterSelectButton,
isSicpEditor ? null : sessionButtons,
sessionButtons,
languageConfig.supports.multiFile ? toggleFolderModeButton : null,
persistenceButtons,
githubButtons,
Expand Down Expand Up @@ -1041,7 +1020,7 @@ const Playground: React.FC<PlaygroundProps> = props => {
autorunButtons,
chapterSelectButton,
languageConfig.chapter === Chapter.FULL_JS ? null : shareButton,
isSicpEditor ? null : sessionButtons,
sessionButtons,
languageConfig.supports.multiFile ? toggleFolderModeButton : null,
persistenceButtons,
githubButtons
Expand Down
7 changes: 3 additions & 4 deletions src/pages/sicp/subcomponents/CodeSnippet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import ControlBar from 'src/commons/controlBar/ControlBar';
import { ControlBarCloseButton } from 'src/commons/controlBar/ControlBarCloseButton';
import { useResponsive } from 'src/commons/utils/Hooks';
import { SourceTheme } from 'src/features/sicp/SourceTheme';
import Playground from 'src/pages/playground/Playground';

import { CodeSnippetContext } from '../Sicp';
import SicpWorkspace from './SicpWorkspace';

export type CodeSnippetProps = OwnProps;
type OwnProps = {
Expand Down Expand Up @@ -55,7 +55,6 @@ const CodeSnippet: React.FC<CodeSnippetProps> = props => {
const WorkspaceProps = {
initialEditorValueHash: props.initialEditorValueHash,
prependLength: props.prependLength,
isSicpEditor: true,

handleCloseEditor: handleClose
};
Expand All @@ -81,13 +80,13 @@ const CodeSnippet: React.FC<CodeSnippetProps> = props => {
<ControlBar {...controlBarProps} />
{isMobileBreakpoint ? (
<div className="sicp-workspace-container-container">
<Playground {...WorkspaceProps} />
<SicpWorkspace {...WorkspaceProps} />
</div>
) : (
<div className="sicp-code-snippet-desktop-open">
<Resizable {...resizableProps}>
<div className="sicp-workspace-container-container">
<Playground {...WorkspaceProps} />
<SicpWorkspace {...WorkspaceProps} />
</div>
</Resizable>
</div>
Expand Down
Loading
Loading