Skip to content

Commit

Permalink
resizeable
Browse files Browse the repository at this point in the history
  • Loading branch information
sdankel committed Mar 15, 2024
1 parent c8db7d0 commit 482c748
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 78 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ target
build
node_modules
tmp
projects
.vscode/*
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ This will open http://localhost:3000 in your browser. By default, it will use th
To test against the backend running locally, make this change in `app/src/constants.ts`:

```diff
- export const SERVER_URI = 'https://api.sway-playground.org/compile';
- // export const SERVER_URI = 'http://0.0.0.0:8080/compile';
+ // export const SERVER_URI = 'https://api.sway-playground.org/compile';
+ export const SERVER_URI = 'http://0.0.0.0:8080/compile';
- export const SERVER_URI = 'https://api.sway-playground.org';
- // export const SERVER_URI = 'http://0.0.0.0:8080';
+ // export const SERVER_URI = 'https://api.sway-playground.org';
+ export const SERVER_URI = 'http://0.0.0.0:8080';
```

## Contributing to Sway
Expand Down
43 changes: 17 additions & 26 deletions app/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useCallback, useEffect, useState } from 'react';
import SwayEditor from './features/editor/components/SwayEditor';
import ActionToolbar from './features/toolbar/components/ActionToolbar';
import LogView from './features/editor/components/LogView';
import { useCompile } from './features/editor/hooks/useCompile';
Expand All @@ -13,8 +12,8 @@ import {
import InteractionDrawer from './features/interact/components/InteractionDrawer';
import { useLog } from './features/editor/hooks/useLog';
import { Toolchain } from './features/editor/components/ToolchainDropdown';
import SolidityEditor from './features/editor/components/SolidityEditor';
import { useTranspile } from './features/editor/hooks/useTranspile';
import EditorView from './features/editor/components/EditorView';

const DRAWER_WIDTH = '40vw';

Expand Down Expand Up @@ -96,7 +95,13 @@ function App() {
}
}, [showSolidity, swayCode, solidityCode, setCodeToCompile, updateLog]);

useTranspile(codeToTranspile, setCodeToCompile, onSwayCodeChange, setError, updateLog);
useTranspile(
codeToTranspile,
setCodeToCompile,
onSwayCodeChange,
setError,
updateLog
);
useCompile(codeToCompile, setError, setIsCompiled, updateLog, toolchain);

return (
Expand Down Expand Up @@ -126,29 +131,15 @@ function App() {
display: 'flex',
flexDirection: 'column',
}}>
<div
style={{
display: 'flex',
flexDirection: 'row',
// TODO
// resize: 'vertical',
// overflow: 'auto'
}}>
{showSolidity && <div style={{ flex: 1, marginRight: '1rem' }}>
<SolidityEditor
code={solidityCode}
onChange={onSolidityCodeChange}
/>
</div>}
<div style={{ flex: 1 }}>
<SwayEditor
code={swayCode}
onChange={onSwayCodeChange}
toolchain={toolchain}
setToolchain={setToolchain}
/>
</div>
</div>
<EditorView
swayCode={swayCode}
onSwayCodeChange={onSwayCodeChange}
solidityCode={solidityCode}
onSolidityCodeChange={onSolidityCodeChange}
toolchain={toolchain}
setToolchain={setToolchain}
showSolidity={showSolidity}
/>
<LogView results={log} />
</div>
<InteractionDrawer
Expand Down
11 changes: 5 additions & 6 deletions app/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export const FUEL_GREEN = '#00f58c';

// TODO: Determine the URL based on the NODE_ENV.
export const SERVER_URI = 'https://api.sway-playground.org/compile';
// export const SERVER_URI = 'http://0.0.0.0:8080/transpile';
// export const SERVER_URI = 'https://api.sway-playground.org';
export const SERVER_URI = 'http://0.0.0.0:8080';

export const DEFAULT_SWAY_CONTRACT = `contract;
Expand Down Expand Up @@ -32,14 +32,13 @@ impl TestContract for Contract {
}
}`;

export const DEFAULT_SOLIDITY_CONTRACT = `// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
export const DEFAULT_SOLIDITY_CONTRACT = `pragma solidity ^0.8.24;
contract Counter {
uint256 public count;
uint64 public count;
// Function to get the current count
function get_counter() public view returns (uint256) {
function get_counter() public view returns (uint64) {
return count;
}
Expand Down
50 changes: 50 additions & 0 deletions app/src/features/editor/components/EditorView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React, { useEffect, useRef } from 'react';
import SolidityEditor from './SolidityEditor';
import SwayEditor from './SwayEditor';
import { Toolchain } from './ToolchainDropdown';

export interface EditorViewProps {
swayCode: string;
onSwayCodeChange: (value: string) => void;
solidityCode: string;
onSolidityCodeChange: (value: string) => void;
toolchain: Toolchain;
setToolchain: (toolchain: Toolchain) => void;
showSolidity: boolean;
}

function EditorView({
swayCode,
solidityCode,
onSolidityCodeChange,
onSwayCodeChange,
toolchain,
setToolchain,
showSolidity,
}: EditorViewProps) {
return (
<div
style={{
display: 'flex',
flexDirection: 'row',
height: '50vh',
minHeight: '10vh',
maxHeight: '80vh',
position: 'relative',
resize: 'vertical',
overflow: 'auto',
}}>
{showSolidity && (
<SolidityEditor code={solidityCode} onChange={onSolidityCodeChange} />
)}
<SwayEditor
code={swayCode}
onChange={onSwayCodeChange}
toolchain={toolchain}
setToolchain={setToolchain}
/>
</div>
);
}

export default EditorView;
34 changes: 15 additions & 19 deletions app/src/features/editor/components/SolidityEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,22 @@ export interface SolidityEditorProps {

function SolidityEditor({ code, onChange }: SolidityEditorProps) {
return (
<div>
<StyledBorder style={{ flex: 1, marginRight: '1rem' }}>
<ActionOverlay handleReset={() => onChange(DEFAULT_SOLIDITY_CONTRACT)} />
<StyledBorder>
<AceEditor
style={{
width: '100%',
resize: 'vertical',
minHeight: '10vh',
maxHeight: '80vh',
}}
mode='solidity'
theme='chrome'
name='editor'
fontSize='14px'
onChange={onChange}
value={code}
editorProps={{ $blockScrolling: true }}
/>
</StyledBorder>
</div>
<AceEditor
style={{
width: '100%',
height: '100%',
}}
mode='solidity'
theme='chrome'
name='editor'
fontSize='14px'
onChange={onChange}
value={code}
editorProps={{ $blockScrolling: true }}
/>
</StyledBorder>
);
}

Expand Down
41 changes: 21 additions & 20 deletions app/src/features/editor/components/SwayEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,33 @@ export interface SwayEditorProps {
setToolchain: (toolchain: Toolchain) => void;
}

function SwayEditor({ code, onChange, toolchain, setToolchain }: SwayEditorProps) {
function SwayEditor({
code,
onChange,
toolchain,
setToolchain,
}: SwayEditorProps) {
return (
<div>
<StyledBorder style={{ flex: 1 }}>
<ActionOverlay
handleReset={() => onChange(DEFAULT_SWAY_CONTRACT)}
toolchain={toolchain}
setToolchain={setToolchain}
/>
<StyledBorder>
<AceEditor
style={{
width: '100%',
resize: 'vertical',
minHeight: '10vh',
maxHeight: '80vh',
}}
mode='rust'
theme='chrome'
name='editor'
fontSize='14px'
onChange={onChange}
value={code}
editorProps={{ $blockScrolling: true }}
/>
</StyledBorder>
</div>
<AceEditor
style={{
width: '100%',
height: '100%',
}}
mode='rust'
theme='chrome'
name='editor'
fontSize='14px'
onChange={onChange}
value={code}
editorProps={{ $blockScrolling: true }}
/>
</StyledBorder>
);
}

Expand Down
4 changes: 2 additions & 2 deletions app/src/features/editor/hooks/useCompile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function useCompile(
onError: (error: string | undefined) => void,
setIsCompiled: (isCompiled: boolean) => void,
setResults: (entry: React.ReactElement[]) => void,
toolchain: Toolchain,
toolchain: Toolchain
) {
const [serverError, setServerError] = useState<boolean>(false);
const [version, setVersion] = useState<string | undefined>();
Expand All @@ -50,7 +50,7 @@ export function useCompile(
}
setResults([<>Compiling Sway contract...</>]);

const request = new Request(SERVER_URI, {
const request = new Request(`${SERVER_URI}/compile`, {
method: 'POST',
body: JSON.stringify({
contract: code,
Expand Down
2 changes: 1 addition & 1 deletion app/src/features/editor/hooks/useTranspile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function useTranspile(
</>,
]);

const request = new Request(SERVER_URI, {
const request = new Request(`${SERVER_URI}/transpile`, {
method: 'POST',
body: JSON.stringify({
contract: code,
Expand Down

0 comments on commit 482c748

Please sign in to comment.