Skip to content

Commit

Permalink
Review context
Browse files Browse the repository at this point in the history
  • Loading branch information
tbragaf committed Feb 16, 2024
1 parent 4e82ffa commit 15cdde3
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ export function ComponentWithMountCallback({ mounted, children }: PropsWithChild
mounted?.();
}, []);

return isMounted ? <>{children}</> : null;
return isMounted ? <React.Fragment key={"asd"}>{children}</React.Fragment> : null;
}
2 changes: 1 addition & 1 deletion ReactViewResources/Loader/Internal/Loader.View.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function createView(componentClass: any, properties: {}, view: ViewMetada
export function renderMainView(children: React.ReactElement, container: Element) {
return new Promise<void>(resolve => {
const childrenWithRenderCallback = (
<ComponentWithMountCallback mounted={resolve}>
<ComponentWithMountCallback key={"ooodd"} mounted={resolve}>
{children}
</ComponentWithMountCallback>
);
Expand Down
2 changes: 1 addition & 1 deletion ReactViewResources/Loader/Internal/ViewPortal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class ViewPortal extends React.Component<IViewPortalProps, IViewPortalSta

public render(): React.ReactNode {
return ReactDOM.createPortal(
<div id={webViewRootId} ref={e => this.props.view.root = e!}>
<div id={webViewRootId} key={"fdsdfsdf"} ref={e => this.props.view.root = e!}>
{this.state.component ? this.state.component : null}
</div>,
this.shadowRoot);
Expand Down
3 changes: 2 additions & 1 deletion ReactViewResources/Loader/Internal/ViewPortalsCollection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export class ViewPortalsCollection extends React.Component<IViewPortalsCollectio

private renderViewPortal(view: ViewMetadata) {
return (
<ViewPortal key={view.name}
<ViewPortal
key={view.name}
view={view}
viewMounted={this.props.viewAdded}
viewUnmounted={this.props.viewRemoved}
Expand Down
23 changes: 9 additions & 14 deletions Sample.Avalonia/MainView/MainView.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from "react";
import { ViewFrame } from "ViewFrame";
import ViewPlugin from "./../ViewPlugin/ViewPlugin";
import {IPluginsContext, PluginsContext} from "PluginsProvider";
import { PluginsContext } from "PluginsProvider";
import "./MainView.scss"; // import a stylesheet
import TaskListView from "./../TaskListView/TaskListView"; // import another component
import * as BackgroundImage from "./Tasks.png"; // import images
Expand Down Expand Up @@ -53,26 +53,21 @@ export default class MainView extends React.Component<IMainViewProperties, MainV
private readonly inputRef = React.createRef<HTMLInputElement>();

constructor(props: IMainViewProperties) {
super(props, );
this.initialize();
}

private async initialize(): Promise<void> {
super(props);
this.state = {
tasksCount: 0,
taskListShowStatus: TaskListShowStatus.Show
};

this.refresh();
}

public refresh(): void {
(async () => {
const tasksCount = await this.props.getTasksCount();
this.setState({ tasksCount });
})();
public async refresh(): Promise<void> {
const tasksCount = await this.props.getTasksCount();
this.setState({ tasksCount });
}

public componentDidMount(): void {
public async componentDidMount(): Promise<void> {
this.viewPlugin = this.context.getPluginInstance<ViewPlugin>(ViewPlugin);
this.viewPlugin.notifyViewLoaded("Main View");

Expand Down Expand Up @@ -116,9 +111,9 @@ export default class MainView extends React.Component<IMainViewProperties, MainV

public render(): JSX.Element {
return (
<div className="wrapper">
<div key={"dsdsfdfs"} className="wrapper">
<div className="title">{this.props.titleMessage}</div>
<input className="task-input" ref={this.inputRef} onChange={() => this.props.inputChanged()} />
<input className="task-input" ref={this.inputRef} onChange={() => this.props.inputChanged()}/>
<button className="task-add" onClick={this.onAddTaskButtonClicked}>Add Task</button>
<button className="tasks-toggle-show" onClick={this.toggleShowTasks}>Show/Block/Hide Tasks</button>
{this.renderListView()}
Expand Down
43 changes: 19 additions & 24 deletions Sample.Avalonia/TaskListView/TaskListView.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from "react";
import ViewPlugin from "./../ViewPlugin/ViewPlugin";
import { IPluginsContext } from "PluginsProvider";
import {IPluginsContext, PluginsContext} from "PluginsProvider";
import "./TaskListView.scss";
import { ResourceLoader } from "ResourceLoader";

Expand Down Expand Up @@ -30,9 +30,8 @@ interface ITaskListItemProperties {
}

class TaskListItem extends React.Component<{ task: ITask }, {}, IPluginsContext> {

constructor(props: ITaskListItemProperties, context: IPluginsContext) {
super(props, context);
constructor(props: ITaskListItemProperties) {
super(props);
}

render(): JSX.Element {
Expand All @@ -54,13 +53,18 @@ class TaskListItem extends React.Component<{ task: ITask }, {}, IPluginsContext>
}

export default class TaskListView extends React.Component<ITaskListViewProperties, ITaskListViewState> implements ITaskListViewBehaviors {
declare context: React.ContextType<typeof PluginsContext>;

private readonly viewplugin: ViewPlugin;
private viewPlugin: ViewPlugin;

constructor(props: ITaskListViewProperties, context: IPluginsContext) {
super(props, context);
this.initialize();
this.viewplugin = context.getPluginInstance<ViewPlugin>(ViewPlugin);
constructor(props: ITaskListViewProperties) {
super(props);
this.state = {
tasks: [],
hideCompletedTasks: false
};

this.refresh();
}

public toggleHideCompletedTasks(): void {
Expand All @@ -69,23 +73,14 @@ export default class TaskListView extends React.Component<ITaskListViewPropertie
}));
}

public refresh(): void {
(async () => {
const tasks = await this.props.getTasks();
this.setState({ tasks });
})();
}

private async initialize(): Promise<void> {
this.state = {
tasks: [],
hideCompletedTasks: false
};
this.refresh();
public async refresh(): Promise<void> {
const tasks = await this.props.getTasks();
this.setState({ tasks });
}

public componentDidMount(): void {
this.viewplugin.notifyViewLoaded("Task List View");
public async componentDidMount(): Promise<void> {
this.viewPlugin = this.context.getPluginInstance<ViewPlugin>(ViewPlugin);
this.viewPlugin.notifyViewLoaded("Task List View");
}

private renderItems(): JSX.Element {
Expand Down

0 comments on commit 15cdde3

Please sign in to comment.