Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show loading spinner when waiting for backups (re)load #22485

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions hassio/src/backups/hassio-backups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import { showHassioBackupDialog } from "../dialogs/backup/show-dialog-hassio-bac
import { showHassioCreateBackupDialog } from "../dialogs/backup/show-dialog-hassio-create-backup";
import { supervisorTabs } from "../hassio-tabs";
import { hassioStyle } from "../resources/hassio-style";
import "../../../src/layouts/hass-loading-screen";

type BackupItem = HassioBackup & {
secondary: string;
Expand All @@ -69,6 +70,8 @@ export class HassioBackups extends LitElement {

@state() private _backups?: HassioBackup[] = [];

@state() private _isLoading = false;

@query("hass-tabs-subpage-data-table", true)
private _dataTable!: HaTabsSubpageDataTable;

Expand All @@ -77,15 +80,10 @@ export class HassioBackups extends LitElement {
public connectedCallback(): void {
super.connectedCallback();
if (this.hass && this._firstUpdatedCalled) {
this.refreshData();
this.fetchBackups();
}
}

public async refreshData() {
await reloadHassioBackups(this.hass);
await this.fetchBackups();
}

private _computeBackupContent = (backup: HassioBackup): string => {
if (backup.type === "full") {
return this.supervisor.localize("backup.full_backup");
Expand Down Expand Up @@ -115,7 +113,7 @@ export class HassioBackups extends LitElement {
protected firstUpdated(changedProperties: PropertyValues): void {
super.firstUpdated(changedProperties);
if (this.hass && this.isConnected) {
this.refreshData();
this.fetchBackups();
}
this._firstUpdatedCalled = true;
}
Expand Down Expand Up @@ -175,6 +173,13 @@ export class HassioBackups extends LitElement {
if (!this.supervisor) {
return nothing;
}

if (this._isLoading) {
return html`<hass-loading-screen
.message=${this.supervisor.localize("backup.loading_backups")}
></hass-loading-screen>`;
}

return html`
<hass-tabs-subpage-data-table
.tabs=${atLeastVersion(this.hass.config.version, 2022, 5)
Expand Down Expand Up @@ -281,7 +286,7 @@ export class HassioBackups extends LitElement {
private _handleAction(ev: CustomEvent<ActionDetail>) {
switch (ev.detail.index) {
case 0:
this.refreshData();
this.fetchBackups();
break;
case 1:
showHassioBackupLocationDialog(this, { supervisor: this.supervisor });
Expand All @@ -306,13 +311,15 @@ export class HassioBackups extends LitElement {
supervisor: this.supervisor,
onDelete: () => this.fetchBackups(),
}),
reloadBackup: () => this.refreshData(),
reloadBackup: () => this.fetchBackups(),
});
}

private async fetchBackups() {
this._isLoading = true;
await reloadHassioBackups(this.hass);
this._backups = await fetchHassioBackups(this.hass);
this._isLoading = false;
}

private async _deleteSelected() {
Expand All @@ -339,8 +346,7 @@ export class HassioBackups extends LitElement {
});
return;
}
await reloadHassioBackups(this.hass);
this._backups = await fetchHassioBackups(this.hass);
await this.fetchBackups();
this._dataTable.clearSelection();
}

Expand Down
1 change: 1 addition & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -7659,6 +7659,7 @@
},
"backup": {
"search": "[%key:ui::panel::config::backup::picker::search%]",
"loading_backups": "Loading backups. This can take a few seconds.",
"no_backups": "You don't have any backups yet.",
"create_blocked_not_running": "Creating a backup is not possible right now because the system is in \"{state}\" state.",
"restore_blocked_not_running": "Restoring a backup is not possible right now because the system is in \"{state}\" state.",
Expand Down
Loading