Skip to content

Commit

Permalink
fix: mobx
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricbet committed Jun 8, 2023
1 parent ab3ebe3 commit c85e183
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
6 changes: 0 additions & 6 deletions packages/scm/src/browser/scm-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ export class ViewModelContext extends Disposable {
private readonly logger: ILogger;

private onDidSelectedRepoChangeEmitter: Emitter<ISCMRepository> = new Emitter();

get onDidSelectedRepoChange() {
return this.onDidSelectedRepoChangeEmitter.event;
}
Expand All @@ -226,9 +225,6 @@ export class ViewModelContext extends Disposable {

private _currentWorkspace: Uri;

@observable
public selectedRepos = observable.array<ISCMRepository>([]);

@observable
public alwaysShowActions: boolean;

Expand Down Expand Up @@ -363,9 +359,7 @@ export class ViewModelContext extends Disposable {
this.onDidSCMRepoListChangeEmitter.fire(this.repoList);
}

@action
private changeSelectedRepos(repos: ISCMRepository[]) {
this.selectedRepos.replace(repos);
const selectedRepo = repos[0];
this.selectedRepo = selectedRepo;
this.onDidSelectedRepoChangeEmitter.fire(selectedRepo);
Expand Down
25 changes: 15 additions & 10 deletions packages/scm/src/browser/scm-view-container.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { observer } from 'mobx-react-lite';
import React, { useEffect, useMemo, useRef, useState, FC, useCallback, memo } from 'react';
import React, { useEffect, useMemo, useRef, useState, FC, useCallback, memo, useDeferredValue } from 'react';

import { ViewState } from '@opensumi/ide-core-browser';
import { IContextKeyService, View, useInjectable } from '@opensumi/ide-core-browser';
Expand Down Expand Up @@ -27,7 +27,7 @@ const SCM_EXTRA_PADDING_TOP = 10;
export const SCMResourcesView: FC<{
repository: ISCMRepository;
viewState: ViewState;
}> = observer(({ repository, viewState }) => {
}> = ({ repository, viewState }) => {
const contextKeyService = useInjectable<IContextKeyService>(IContextKeyService);
const menuRegistry = useInjectable<IMenuRegistry>(IMenuRegistry);
const viewModel = useInjectable<ViewModelContext>(ViewModelContext);
Expand Down Expand Up @@ -120,25 +120,30 @@ export const SCMResourcesView: FC<{
</div>
</div>
);
});
};

SCMResourcesView.displayName = 'SCMResourcesView';

export const SCMResourcesViewWrapper: FC<{ viewState: ViewState }> = observer((props) => {
export const SCMResourcesViewWrapper: FC<{ viewState: ViewState }> = (props) => {
const viewModel = useInjectable<ViewModelContext>(ViewModelContext);
const [repo, setRepo] = useState<ISCMRepository>();
const deferredRepo = useDeferredValue(repo);

if (!viewModel.selectedRepos.length) {
useEffect(() => {
viewModel.onDidSelectedRepoChange((selectedReop) => {
setRepo(selectedReop);
});
}, [viewModel.selectedRepo]);
if (!deferredRepo) {
return <WelcomeView viewId={SCM_WELCOME_ID} />;
}

const selectedRepo = viewModel.selectedRepos[0];

if (!selectedRepo || !selectedRepo.provider) {
if (!deferredRepo.provider) {
return null;
}

return <SCMResourcesView repository={selectedRepo} viewState={props.viewState} />;
});
return <SCMResourcesView repository={deferredRepo} viewState={props.viewState} />;
};

SCMResourcesViewWrapper.displayName = 'SCMResourcesViewWrapper';

Expand Down
3 changes: 0 additions & 3 deletions packages/scm/src/common/scm.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,8 @@ class SCMRepository implements ISCMRepository {
private _onDidFocus = new Emitter<void>();
readonly onDidFocus: Event<void> = this._onDidFocus.event;

@observable
private _selected = false;

@computed
get selected(): boolean {
return this._selected;
}
Expand All @@ -88,7 +86,6 @@ class SCMRepository implements ISCMRepository {
this._onDidFocus.fire();
}

@action
setSelected(selected: boolean): void {
this._selected = selected;
this._onDidChangeSelection.fire(this);
Expand Down

0 comments on commit c85e183

Please sign in to comment.