Skip to content

Commit

Permalink
Fix small issues (#228)
Browse files Browse the repository at this point in the history
* Decode title and description for helmet

* Reuse existing language clients

* Remove unused console.log

* Redirect from empty project id
  • Loading branch information
MaxStalker committed Feb 17, 2022
1 parent 4bf94dc commit 2e3323a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
36 changes: 21 additions & 15 deletions src/components/CadenceEditor.tsx
Expand Up @@ -134,6 +134,7 @@ class CadenceEditor extends React.Component<
languageClient?: MonacoLanguageClient;
_subscription: any;
editorStates: { [key: string]: EditorState };
clients: { [key: string]: MonacoLanguageClient }
private callbacks: Callbacks;

constructor(props: {
Expand All @@ -150,6 +151,7 @@ class CadenceEditor extends React.Component<
super(props);

this.editorStates = {};
this.clients = {};
this.handleResize = this.handleResize.bind(this);
window.addEventListener('resize', this.handleResize);
configureCadence();
Expand Down Expand Up @@ -197,21 +199,26 @@ class CadenceEditor extends React.Component<

private async loadLanguageClient() {
this.callbacks = this.props.callbacks;

this.languageClient = createCadenceLanguageClient(this.callbacks);
this.languageClient.start();
this.languageClient.onReady().then(() => {
const clientId = this.props.activeId;
if(!this.clients[clientId]){
this.languageClient = createCadenceLanguageClient(this.callbacks);
this.languageClient.start();
await this.languageClient.onReady()
this.languageClient.onNotification(
CadenceCheckCompleted.methodName,
async (result: CadenceCheckCompleted.Params) => {
if (result.valid) {
const params = await this.getParameters();
this.setExecutionArguments(params);
}
this.processMarkers();
},
CadenceCheckCompleted.methodName,
async (result: CadenceCheckCompleted.Params) => {
if (result.valid) {
const params = await this.getParameters();
this.setExecutionArguments(params);
}
this.processMarkers();
},
);
});
this.clients[clientId] = this.languageClient;
} else {
this.languageClient = this.clients[clientId]
}

}

private async getParameters() {
Expand Down Expand Up @@ -317,6 +324,7 @@ class CadenceEditor extends React.Component<
const serverStatusChanged = this.props.serverReady !== prevProps.serverReady
const activeIdChanged = this.props.activeId !== prevProps.activeId
const typeChanged = this.props.type !== prevProps.type

if (serverStatusChanged || activeIdChanged || typeChanged) {
if (this.props.callbacks.toServer !== null) {
await this.loadLanguageClient()
Expand Down Expand Up @@ -344,8 +352,6 @@ class CadenceEditor extends React.Component<
}

extract(code: string, keyWord: string): string[] {
// TODO: add different processors for contract, scripts and transactions

const target = code
.split(/\r\n|\n|\r/)
.find((line) => line.includes(keyWord));
Expand Down
5 changes: 5 additions & 0 deletions src/containers/Editor/index.tsx
Expand Up @@ -3,11 +3,16 @@ import { ProjectProvider } from 'providers/Project';
import EditorLayout from './layout';
import { Base } from 'layout/Base';
import { LOCAL_PROJECT_ID } from 'util/url';
import { Redirect} from '@reach/router';

const Playground: any = (props: any) => {
const { projectId } = props;
const isLocalProject = projectId === LOCAL_PROJECT_ID;

if (!projectId) {
return <Redirect noThrow to={`/${LOCAL_PROJECT_ID}`} />;
}

return (
<Base>
<ProjectProvider urlProjectId={isLocalProject ? null : projectId}>
Expand Down
9 changes: 5 additions & 4 deletions src/containers/Editor/layout.tsx
Expand Up @@ -32,6 +32,7 @@ import {
} from './components';

import { useProject } from 'providers/Project/projectHooks';
import { decodeText } from "util/readme";

const FDP = [
'f1383d67-6f0a-4be7-8e61-f6141ebdd92c',
Expand Down Expand Up @@ -72,16 +73,16 @@ const EditorLayout: React.FC = () => {
return <></>;
}

const [helmetTitle, setHelmetTitle] = useState(project.title);
const [helmetDescription, setHelmetDescription] = useState(project.title);
const [helmetTitle, setHelmetTitle] = useState(decodeText(project.title));
const [helmetDescription, setHelmetDescription] = useState(decodeText(project.title));

useEffect(() => {
if (project.title) {
const titleDebounce = setTimeout(() => {
setHelmetTitle(project.title);
setHelmetTitle(decodeText(project.title));
}, 3000);
const descriptionDebounce = setTimeout(() => {
setHelmetDescription(project.description);
setHelmetDescription(decodeText(project.description));
}, 3000);

return () => {
Expand Down

1 comment on commit 2e3323a

@vercel
Copy link

@vercel vercel bot commented on 2e3323a Feb 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.