I created a widget and I need to render the README.md content in it.
I’ve been looking for some time about this but the truth is I don’t even know where to start.
Let’s say you initialize your view similar to how we initialize our own navigator-widget. You can just look through the workspace and search for a README.md in the workspace root:
Where should I import WorkspaceService, FileService and EditorManager from?
If you’re using vscode, that should already propose some imports. Otherwise from the @theia/workspace/lib/browser and @theia/filesystem/lib/browser packages respectively. EditorManager is not necessary, I just copy & pasted some code for this.
Also, what is openView expected to be?
If you follow the link, that I posted earlier, you can see that it’s part of the AbstractViewContribution. See here for some more documentation on that.
@msujew, to be honest, I see no use for this.openView().
I tried using part of the README read function inside the render() property and it manages to find the README.
The problem is that to “read it” the function needs to be asynchronous and apparently this render property cannot return a Promise.
The problem is that to “read it” the function needs to be asynchronous and apparently this render property cannot return a Promise.
That’s exactly what I proposed (i.e. move the code into the initializeLayout function). Note that @postConstruct() shouldn’t be async, since these functions are not awaited by our dependency injection system.
The purpose of calling this.openView is to get a reference to the widget, so we can stuff the readme content in there for it to render correctly.
@arnonrdpinitializeLayout isn’t there to replace render, but to complement it. You should get your data during initializeLayout, and store it somewhere so you can use it when render is called.
@msujew, after a long try (an entire day) and without success I am back here. I am a Vue Dev trying to handle with React because it is the task. That’s why this is a bit complicated to me, everything is so different.
Well, it seems render() is rendered before initializeLayout(). So I am not able to “re-render” the widget.
I still couldn’t apply AbstractViewContribution to solve the openView() issue.
Since you try to implement initializeLayout in your ReactWidget, I assume that it doesn’t get called at all. In one of my previous posts I mentioned how initializeLayout needs to be part of your AbstractViewContribution. Only there will initializeLayout be actually called (and openView actually available. It seems like your class doesn’t compile).
If correctly implemented initializeLayout will always be called before any render of any widget.