diff --git a/app/assets/javascripts/directives/views/historyMenu.ts b/app/assets/javascripts/directives/views/historyMenu.ts index 77976e75d..fcbc50a67 100644 --- a/app/assets/javascripts/directives/views/historyMenu.ts +++ b/app/assets/javascripts/directives/views/historyMenu.ts @@ -2,16 +2,15 @@ import { WebDirective } from '../../types'; import { WebApplication } from '@/ui_models/application'; import template from '%/directives/history-menu.pug'; import { SNItem, ItemHistoryEntry, ItemHistory } from '@node_modules/snjs/dist/@types'; -import { PayloadSource } from 'snjs'; +import { PureViewCtrl } from '@/views'; interface HistoryScope { application: WebApplication item: SNItem } -class HistoryMenuCtrl implements HistoryScope { +class HistoryMenuCtrl extends PureViewCtrl implements HistoryScope { - $timeout: ng.ITimeoutService diskEnabled = false autoOptimize = false application!: WebApplication @@ -23,10 +22,14 @@ class HistoryMenuCtrl implements HistoryScope { constructor( $timeout: ng.ITimeoutService ) { - this.$timeout = $timeout; + super($timeout); + this.state = { + fetchingServerHistory: false + }; } $onInit() { + super.$onInit(); this.reloadHistory(); this.fetchServerHistory(); this.diskEnabled = this.application.historyManager!.isDiskEnabled(); @@ -37,8 +40,20 @@ class HistoryMenuCtrl implements HistoryScope { this.sessionHistory = this.application.historyManager!.sessionHistoryForItem(this.item); } + get isFetchingServerHistory() { + return this.state.fetchingServerHistory; + } + async fetchServerHistory() { - this.serverHistory = await this.application.historyManager!.serverHistoryForItem(this.item); + this.setState({ + fetchingServerHistory: true + }); + this.serverHistory = await this.application.historyManager!.serverHistoryForItem(this.item) + .finally(() => { + this.setState({ + fetchingServerHistory: false + }); + }); } openRevision(revision: ItemHistoryEntry) { diff --git a/app/assets/templates/directives/history-menu.pug b/app/assets/templates/directives/history-menu.pug index 0fd6d5a78..e6be80da4 100644 --- a/app/assets/templates/directives/history-menu.pug +++ b/app/assets/templates/directives/history-menu.pug @@ -43,7 +43,9 @@ div(ng-if='ctrl.showServerOptions') menu-row( action='ctrl.fetchServerHistory()' - label="'Refresh'") + label="'Refresh'" + disabled="ctrl.isFetchingServerHistory" + spinner-class="ctrl.isFetchingServerHistory ? 'info' : null") .sk-sublabel | Fetch history from server. menu-row(