'use strict' ; import * as vscode from 'vscode' ; import * as path from 'path' ; import * as fs from 'fs-extra' ; import { ReactView } from './ReactView' ; import { ExtensionUtil } from '../util/ExtensionUtil' ; import { Reporter } from '../util/Reporter' ; export class TutorialView extends ReactView { private seriesName : string ; private tutorialName : string ; constructor ( context , seriesName , tutorialName ) { const seriesAndName = `${ tutorialName } (${ seriesName })` ; super ( context , seriesAndName , seriesAndName ) ; this . seriesName = seriesName ; this . tutorialName = tutorialName ; } async openPanelInner ( panel ) { Reporter . instance ( ) . sendTelemetryEvent ( 'openedView' , { openedView : panel . title } ) ; const extensionPath = ExtensionUtil . getExtensionPath ( ) ; const panelIcon = vscode . Uri . file ( path . join ( extensionPath , 'resources' , 'logo.svg' ) ) ; panel . iconPath = panelIcon ; panel . webview . onDidReceiveMessage ( async ( message ) => { await vscode . commands . executeCommand ( message . command , ... message . data ) ; } ) ; await this . loadComponent ( panel ) ; } async loadComponent ( panel ) { Reporter . instance ( ) . sendTelemetryEvent ( 'Tutorial Viewed' , { series : this . seriesName , tutorial : this . tutorialName } ) ; const series = await this . getSeries ( this . seriesName ) ; const tutorial = await this . getTutorial ( series , this . tutorialName ) ; const tutorialPath = path . join ( this . getTutorialsDirectory ( ) , tutorial . file ) ; const markdown = await fs . readFile ( tutorialPath , 'utf8' ) ; const tutorials = await this . getTutorialInfo ( ) ; panel . webview . postMessage ( { path : '/viewTutorial' , tutorialData : { tutorials , activeTutorial : { ... tutorial , markdown , } , } } ) ; } }