Skip to content
This repository has been archived by the owner on Dec 23, 2021. It is now read-only.

Commit

Permalink
Merge branch 'dev' into users/t-vali/command-pallet-reconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
vandyliu authored Feb 19, 2020
2 parents 294e82a + ea1986c commit 95d20c5
Show file tree
Hide file tree
Showing 8 changed files with 4,018 additions and 4,114 deletions.
6 changes: 4 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ let currentActiveDevice: string = DEFAULT_DEVICE;
export let outChannel: vscode.OutputChannel | undefined;

function loadScript(context: vscode.ExtensionContext, scriptPath: string) {
return `<script src="${vscode.Uri.file(context.asAbsolutePath(scriptPath))
return `<script initialDevice=${currentActiveDevice} src="${vscode.Uri.file(
context.asAbsolutePath(scriptPath)
)
.with({ scheme: "vscode-resource" })
.toString()}"></script>`;
}
Expand Down Expand Up @@ -1150,7 +1152,7 @@ function getWebviewContent(context: vscode.ExtensionContext) {
</head>
<body>
<div id="root"></div>
<script>
<script >
const vscode = acquireVsCodeApi();
</script>
${loadScript(context, "out/vendor.js")}
Expand Down
31 changes: 10 additions & 21 deletions src/view/App.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { PivotItem } from "office-ui-fabric-react";

import * as React from "react";
import "./App.css";
import { Tab } from "./components/tab/Tab";
import {
DEVICE_LIST_KEY,
VSCODE_MESSAGES_TO_WEBVIEW,
WEBVIEW_MESSAGES,
} from "./constants";
import { DEVICE_LIST_KEY, VSCODE_MESSAGES_TO_WEBVIEW } from "./constants";
import { Device } from "./container/device/Device";
import { sendMessage } from "./utils/MessageUtils";

interface IState {
currentDevice: string;
Expand All @@ -28,6 +20,15 @@ class App extends React.Component<{}, IState> {
this.state = defaultState;
}
componentDidMount() {
if (document.currentScript) {
const initialDevice = document.currentScript.getAttribute(
"initialDevice"
);

if (initialDevice) {
this.setState({ currentDevice: initialDevice });
}
}
window.addEventListener("message", this.handleMessage);
}
componentWillUnmount() {
Expand All @@ -38,24 +39,12 @@ class App extends React.Component<{}, IState> {
return (
<div className="App">
<main className="App-main">
<Tab
handleTabClick={this.handleDeviceChange}
currentActiveDevice={this.state.currentDevice}
/>
<Device currentSelectedDevice={this.state.currentDevice} />
</main>
</div>
);
}

handleDeviceChange = (item?: PivotItem) => {
if (item && item.props && item.props.itemKey) {
sendMessage(WEBVIEW_MESSAGES.SWITCH_DEVICE, {
active_device: item.props.itemKey,
});
this.setState({ currentDevice: item.props.itemKey });
}
};
handleMessage = (event: any): void => {
const message = event.data;
console.log(JSON.stringify(message));
Expand Down
87 changes: 0 additions & 87 deletions src/view/__snapshots__/App.spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,93 +7,6 @@ exports[`App component should render correctly 1`] = `
<main
className="App-main"
>
<div
role="toolbar"
>
<div
className="ms-FocusZone css-56"
data-focuszone-id="FocusZone2"
onFocus={[Function]}
onKeyDown={[Function]}
onMouseDownCapture={[Function]}
>
<div
className="ms-Pivot ms-Pivot--tabs root-49"
role="tablist"
>
<button
aria-selected={true}
className="ms-Button ms-Button--action ms-Button--command ms-Pivot-link is-selected linkIsSelected-57"
data-content="CPX"
data-is-focusable={true}
id="Pivot1-Tab0"
name="CPX"
onClick={[Function]}
onKeyDown={[Function]}
onKeyPress={[Function]}
onKeyUp={[Function]}
onMouseDown={[Function]}
onMouseUp={[Function]}
role="tab"
type="button"
>
<span
className="ms-Button-flexContainer flexContainer-58"
data-automationid="splitbuttonprimary"
>
<span
className="ms-Pivot-linkContent linkContent-52"
>
<span
className="ms-Pivot-text text-53"
>
CPX
</span>
</span>
</span>
</button>
<button
aria-selected={false}
className="ms-Button ms-Button--action ms-Button--command ms-Pivot-link link-65"
data-content="micro:bit"
data-is-focusable={true}
id="Pivot1-Tab1"
name="micro:bit"
onClick={[Function]}
onKeyDown={[Function]}
onKeyPress={[Function]}
onKeyUp={[Function]}
onMouseDown={[Function]}
onMouseUp={[Function]}
role="tab"
type="button"
>
<span
className="ms-Button-flexContainer flexContainer-58"
data-automationid="splitbuttonprimary"
>
<span
className="ms-Pivot-linkContent linkContent-52"
>
<span
className="ms-Pivot-text text-53"
>
micro:bit
</span>
</span>
</span>
</button>
</div>
</div>
<div
aria-labelledby="Pivot1-Tab0"
role="tabpanel"
>
<div />
</div>
</div>
<div
className="device-container"
>
Expand Down
Loading

0 comments on commit 95d20c5

Please sign in to comment.