Updated the posts export button to be a GhTaskButton

refs https://github.com/TryGhost/Team/issues/2935

This allows us to track the state with a loading spinner and a
success/error message on completion. This is expecially important for
larger sites where the download can take a long time, and users are
unsure if something is happening.
This commit is contained in:
Fabien "egg" O'Carroll 2023-04-07 12:54:31 +07:00
parent 3dac3cb4e2
commit a890f0b707
2 changed files with 7 additions and 6 deletions

View File

@ -110,9 +110,7 @@
Download a CSV file of all your post data for easy analysis in one place
</p>
</div>
<button type="button" class="gh-btn" {{on "click" this.exportData}}>
<span>Export</span>
</button>
<GhTaskButton @buttonText="Export" @successText="Exported" @task={{this.exportPostsTask}} @class="gh-btn gh-btn-icon"/>
</div>
</div>
</section>

View File

@ -2,6 +2,7 @@ import Component from '@glimmer/component';
import ghostPaths from 'ghost-admin/utils/ghost-paths';
import {action} from '@ember/object';
import {inject as service} from '@ember/service';
import {task} from 'ember-concurrency';
export default class Analytics extends Component {
@service settings;
@ -16,13 +17,15 @@ export default class Analytics extends Component {
this.settings.emailTrackOpens = !this.settings.emailTrackOpens;
}
@action
exportData() {
@task
*exportPostsTask() {
let exportUrl = ghostPaths().url.api('posts/export');
let downloadParams = new URLSearchParams();
downloadParams.set('limit', 'all');
this.utils.downloadFile(`${exportUrl}?${downloadParams.toString()}`);
yield this.utils.fetchAndDownloadFile(`${exportUrl}?${downloadParams.toString()}`);
return true;
}
@action