parent
8e7b4f6671
commit
7146254d3a
@ -1,11 +1,26 @@ |
||||
import React, { useEffect, useState } from "react" |
||||
import { DocViewer } from "./docviewer" |
||||
|
||||
const client = new DocViewer() |
||||
|
||||
export default function App() { |
||||
const [contents, setContents] = useState('') |
||||
useEffect(() => { |
||||
client.eventEmitter.on('contentsReady', (fileContents: string) => { |
||||
console.log('contentsReady', fileContents) |
||||
setContents(fileContents) |
||||
}) |
||||
|
||||
}, []) |
||||
return ( |
||||
<> |
||||
<h1>Documentation Viewer</h1> |
||||
<p> |
||||
Show documentation of compiled contracts. |
||||
</p> |
||||
<p> |
||||
{contents && contents.length} |
||||
</p> |
||||
</> |
||||
) |
||||
} |
@ -0,0 +1,39 @@ |
||||
import { PluginClient } from '@remixproject/plugin' |
||||
import { createClient } from '@remixproject/plugin-webview' |
||||
import EventEmitter from 'events' |
||||
|
||||
export class DocViewer extends PluginClient { |
||||
mdFile: string |
||||
fileContents: string |
||||
eventEmitter: EventEmitter |
||||
constructor() { |
||||
super() |
||||
this.eventEmitter = new EventEmitter() |
||||
this.methods = ['viewDocs'] |
||||
createClient(this) |
||||
this.mdFile = '' |
||||
this.onload() |
||||
} |
||||
|
||||
async setProperties() { |
||||
console.log('inside setProperties') |
||||
this.on('docgen' as any, 'docsGenerated', async (docs: string[]) => { |
||||
console.log('docsGenerated', docs) |
||||
this.mdFile = docs[0] |
||||
const contents = await this.call('fileManager', 'readFile', this.mdFile) |
||||
console.log({ contents }) |
||||
this.fileContents = contents |
||||
this.eventEmitter.emit('docviewer', 'contentsReady', this.fileContents) |
||||
}) |
||||
} |
||||
|
||||
async viewDocs(docs: string[]) { |
||||
console.log('viewDocs', docs) |
||||
console.log('docsGenerated', docs) |
||||
this.mdFile = docs[0] |
||||
const contents = await this.call('fileManager', 'readFile', this.mdFile) |
||||
console.log({ contents }) |
||||
this.fileContents = contents |
||||
this.eventEmitter.emit('contentsReady', contents) |
||||
} |
||||
} |
Loading…
Reference in new issue