Skip to content

Commit 091668b

Browse files
authored
SCM - track "load more" state for each repository (microsoft#226435)
1 parent 00082d1 commit 091668b

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/vs/workbench/contrib/scm/browser/scmHistoryViewPane.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { fromNow } from 'vs/base/common/date';
1818
import { createMatches, FuzzyScore, IMatch } from 'vs/base/common/filters';
1919
import { MarkdownString } from 'vs/base/common/htmlContent';
2020
import { combinedDisposable, Disposable, DisposableMap, DisposableStore, IDisposable } from 'vs/base/common/lifecycle';
21-
import { autorun, autorunWithStore, IObservable, observableValue } from 'vs/base/common/observable';
21+
import { autorun, autorunWithStore, IObservable, ISettableObservable, observableValue } from 'vs/base/common/observable';
2222
import { ThemeIcon } from 'vs/base/common/themables';
2323
import { localize } from 'vs/nls';
2424
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
@@ -362,7 +362,7 @@ class HistoryItemLoadMoreRenderer implements ITreeRenderer<SCMHistoryItemLoadMor
362362
get templateId(): string { return HistoryItemLoadMoreRenderer.TEMPLATE_ID; }
363363

364364
constructor(
365-
private readonly _loadingMore: IObservable<boolean>,
365+
private readonly _loadingMore: (repository: ISCMRepository) => IObservable<boolean>,
366366
private readonly _loadMoreCallback: (repository: ISCMRepository) => void,
367367
@IConfigurationService private readonly _configurationService: IConfigurationService,
368368
@ISCMViewService private readonly _scmViewService: ISCMViewService) { }
@@ -391,7 +391,7 @@ class HistoryItemLoadMoreRenderer implements ITreeRenderer<SCMHistoryItemLoadMor
391391

392392
if (repositoryCount > 1 || alwaysShowRepositories) {
393393
templateData.elementDisposables.add(autorun(reader => {
394-
const loadingMore = this._loadingMore.read(reader);
394+
const loadingMore = this._loadingMore(element.element.repository).read(reader);
395395
const icon = `$(${loadingMore ? 'loading~spin' : 'fold-down'})`;
396396

397397
templateData.historyItemPlaceholderLabel.setLabel(localize('loadMore', "{0} Load More...", icon));
@@ -667,7 +667,7 @@ export class SCMHistoryViewPane extends ViewPane {
667667
private _tree!: WorkbenchAsyncDataTree<ISCMViewService, TreeElement, FuzzyScore>;
668668
private _treeDataSource!: SCMHistoryTreeDataSource;
669669
private _treeIdentityProvider!: SCMHistoryTreeIdentityProvider;
670-
private _isLoadMore = observableValue(this, false);
670+
private _repositoryLoadMore = new Map<ISCMRepository, ISettableObservable<boolean>>();
671671

672672
private readonly _repositories = new DisposableMap<ISCMRepository>();
673673
private readonly _visibilityDisposables = new DisposableStore();
@@ -773,7 +773,7 @@ export class SCMHistoryViewPane extends ViewPane {
773773
[
774774
this.instantiationService.createInstance(RepositoryRenderer, getActionViewItemProvider(this.instantiationService)),
775775
this.instantiationService.createInstance(HistoryItemRenderer, historyItemHoverDelegate),
776-
this.instantiationService.createInstance(HistoryItemLoadMoreRenderer, this._isLoadMore, repository => this._loadMoreCallback(repository)),
776+
this.instantiationService.createInstance(HistoryItemLoadMoreRenderer, repository => this._getLoadMore(repository), repository => this._loadMoreCallback(repository)),
777777
],
778778
this._treeDataSource,
779779
{
@@ -888,6 +888,7 @@ export class SCMHistoryViewPane extends ViewPane {
888888
// Removed repositories
889889
for (const repository of removed) {
890890
this._treeDataSource.clearState(repository);
891+
this._repositoryLoadMore.delete(repository);
891892
this._repositories.deleteAndDispose(repository);
892893
}
893894

@@ -906,16 +907,27 @@ export class SCMHistoryViewPane extends ViewPane {
906907
.filter(r => !!r && isSCMHistoryItemViewModelTreeElement(r))!;
907908
}
908909

910+
private _getLoadMore(repository: ISCMRepository): ISettableObservable<boolean> {
911+
let loadMore = this._repositoryLoadMore.get(repository);
912+
if (!loadMore) {
913+
loadMore = observableValue<boolean>(this, false);
914+
this._repositoryLoadMore.set(repository, loadMore);
915+
}
916+
917+
return loadMore;
918+
}
919+
909920
private _loadMoreCallback(repository: ISCMRepository): void {
910-
if (this._isLoadMore.get()) {
921+
const loadMore = this._getLoadMore(repository);
922+
if (loadMore.get()) {
911923
return;
912924
}
913925

914-
this._isLoadMore.set(true, undefined);
926+
loadMore.set(true, undefined);
915927
this._treeDataSource.loadMore(repository);
916928

917929
this._updateChildren(repository)
918-
.finally(() => this._isLoadMore.set(false, undefined));
930+
.finally(() => loadMore.set(false, undefined));
919931
}
920932

921933
private _updateChildren(element?: ISCMRepository): Promise<void> {

0 commit comments

Comments
 (0)