Skip to content

Feature/progress #11

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

Merged
merged 4 commits into from
Jul 14, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor out logs
  • Loading branch information
ShMcK committed Jul 14, 2019
commit 830c01a9248276b987bdd6e0e23790030dddbbe6
62 changes: 33 additions & 29 deletions src/editor/ReactWebView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,35 @@ class ReactWebView {

// Listen for when the panel is disposed
// This happens when the user closes the panel or when the panel is closed programatically
this.panel.onDidDispose(() => this.dispose(), null, this.disposables)
// this.panel.onDidDispose(() => this.dispose(), null, this.disposables)

// Handle messages from the webview
const onReceive = (action: string | CR.Action) => vscode.commands.executeCommand('coderoad.receive_action', action)
this.panel.webview.onDidReceiveMessage(onReceive, null, this.disposables)

// update panel on changes
const updateWindows = () => {

vscode.commands.executeCommand('vscode.setEditorLayout', { orientation: 0, groups: [{ groups: [{}], size: 0.6 }, { groups: [{}], size: 0.4 }] })
this.panel.reveal(vscode.ViewColumn.Two)
}

this.panel.onDidDispose(() => {
updateWindows()
})

// this.panel.onDidChangeViewState(() => {
// console.log('onDidChangeViewState')
// updateWindows()
// })

// prevents new panels from going ontop of coderoad panel
vscode.window.onDidChangeActiveTextEditor((param) => {
if (!param || param.viewColumn !== vscode.ViewColumn.Two) {
updateWindows()
}
})
// prevents moving coderoad panel on top of left panel
// // prevents moving coderoad panel on top of left panel
vscode.window.onDidChangeVisibleTextEditors((param) => {
updateWindows()
})
Expand All @@ -52,10 +63,8 @@ class ReactWebView {
// If we already have a panel, show it.
// Otherwise, create a new panel.
if (this.panel && this.panel.webview) {
console.log('reveal')
this.panel.reveal(column)
} else {
console.log('make new panel')
this.panel = this.createWebviewPanel(column)
}
}
Expand Down Expand Up @@ -84,15 +93,12 @@ class ReactWebView {
}

public async postMessage(action: CR.Action): Promise<void> {
console.log('webview postMessage')
console.log(action)
// Send a message to the webview webview.
// You can send any JSON serializable data.
const success = await this.panel.webview.postMessage(action)
if (!success) {
throw new Error(`Message post failure: ${JSON.stringify(action)}`)
}
console.log('postMessage sent')
}

public dispose(): void {
Expand Down Expand Up @@ -125,31 +131,29 @@ class ReactWebView {
const styleUri = stylePathOnDisk.with({ scheme: 'vscode-resource' })

// Use a nonce to whitelist which scripts can be run
const nonce = this.getNonce()
const nonce2 = this.getNonce()
const nonce3 = this.getNonce()
const [n1, n2, n3] = [1, 2, 3].map(this.getNonce)

return `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<title>React App</title>
<link rel="manifest" href="./manifest.json" />
<link rel="stylesheet" type="text/css" href="${styleUri}">
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src vscode-resource: https:; script-src 'nonce-${nonce}' 'nonce-${nonce2}' 'nonce-${nonce3}'; style-src vscode-resource: 'unsafe-inline' http: https: data:;">
<base href="${vscode.Uri.file(path.join(this.extensionPath, 'build')).with({ scheme: 'vscode-resource' })}/">
<style></style>
</head>

<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root">Loading...</div>
<script nonce=${nonce} src="./webpackBuild.js"></script>
<script nonce=${nonce2} src="${chunkUri}"></script>
<script nonce="${nonce3}" src="${scriptUri}"></script>
</body>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<title>React App</title>
<link rel="manifest" href="./manifest.json" />
<link rel="stylesheet" type="text/css" href="${styleUri}">
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src vscode-resource: https:; script-src 'nonce-${n1}' 'nonce-${n2}' 'nonce-${n3}'; style-src vscode-resource: 'unsafe-inline' http: https: data:;">
<base href="${vscode.Uri.file(path.join(this.extensionPath, 'build')).with({ scheme: 'vscode-resource' })}/">
<style></style>
</head>

<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root">Loading...</div>
<script nonce=${n1} src="./webpackBuild.js"></script>
<script nonce=${n2} src="${chunkUri}"></script>
<script nonce="${n3}" src="${scriptUri}"></script>
</body>
</html>`
}
}
Expand Down
52 changes: 26 additions & 26 deletions src/editor/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,32 @@ export async function isEmptyWorkspace(): Promise<boolean> {
}

// // TODO: workspace change listener
// export async function openReadme(): Promise<void> {
// const { stderr } = await exec('ls')
// if (stderr) {
// throw new Error('Error looking for initial file')
// }
export async function openReadme(): Promise<void> {
const { stderr } = await exec('ls')
if (stderr) {
throw new Error('Error looking for initial file')
}

// const file = 'README.md'
// const filePath = path.join(vscode.workspace.rootPath || '', file)
// console.log('filePath', filePath)
// const hasReadme = await exists(file)
const file = 'README.md'
const filePath = path.join(vscode.workspace.rootPath || '', file)
console.log('filePath', filePath)
const hasReadme = await exists(file)

// if (!hasReadme) {
// // add readme if none exists
// try {
// const content = '# Welcome to CodeRoad!'
// fs.writeFileSync(filePath, content, 'utf8')
// } catch (error) {
// throw new Error('Error writing READM.md')
// }
// }
if (!hasReadme) {
// add readme if none exists
try {
const content = '# Welcome to CodeRoad!'
fs.writeFileSync(filePath, content, 'utf8')
} catch (error) {
throw new Error('Error writing READM.md')
}
}

// try {
// const openPath = vscode.Uri.parse(filePath)
// const doc = await vscode.workspace.openTextDocument(openPath)
// await vscode.window.showTextDocument(doc)
// } catch (error) {
// throw new Error('Error opening README doc')
// }
// }
try {
const openPath = vscode.Uri.parse(filePath)
const doc = await vscode.workspace.openTextDocument(openPath)
await vscode.window.showTextDocument(doc)
} catch (error) {
throw new Error('Error opening README doc')
}
}
1 change: 0 additions & 1 deletion src/services/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const tutorialsData: { [key: string]: CR.Tutorial } = {

// TODO: replace with fetch resource
export default async function fetch(options: Options): Promise<any> {
console.log('options', options)
switch (options.resource) {
case 'getTutorialsSummary':
// list of ids with summaries
Expand Down
3 changes: 0 additions & 3 deletions src/services/git/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@ const gitOrigin = 'coderoad'
export async function gitLoadCommits(actions: CR.TutorialAction, dispatch: CR.EditorDispatch): Promise<void> {
const { commits, commands, files } = actions

console.log('commits to load', commits)

for (const commit of commits) {
const { stdout, stderr } = await exec(`git cherry-pick ${commit}`)
if (stderr) {
console.error(stderr)
throw new Error('Error loading commit')
}
console.log('add commit', stdout)
}

if (commands) {
Expand Down
3 changes: 1 addition & 2 deletions src/state/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ let currentProgress: CR.Progress = {

export default (dispatch: CR.EditorDispatch) => ({
createWebview() {
console.log('execute coderoad.open_webview')
dispatch('coderoad.open_webview')
},
async newOrContinue() {
Expand Down Expand Up @@ -152,7 +151,7 @@ export default (dispatch: CR.EditorDispatch) => ({
...context.position,
stepId: nextStepId,
}
console.log('position update', nextPosition)

return nextPosition
}
}),
Expand Down