Add dev downloads pagination

This commit is contained in:
Dominik Korsa 2020-10-05 21:08:21 +02:00
parent 591a5b370f
commit 4ab75fe9c6
No known key found for this signature in database
GPG key ID: 546F986F71A6FE6E
2 changed files with 60 additions and 28 deletions

View file

@ -20,7 +20,11 @@
:user="version.user"
:build="version.build"
:commit="version.commit" />
<spinner class="loading" v-if="versions === null || master === null" />
<spinner class="loading" v-if="loading || master === null" />
<home-download-load-more-button
v-if="moreLink !== null && !loading"
@click="loadMore"
/>
</div>
</template>
@ -28,6 +32,7 @@
import moment from 'moment';
import HomeDownloadDevItem from './HomeDownloadDevItem.vue';
import HomeDownloadDevMaster from './HomeDownloadDevMaster.vue';
import HomeDownloadLoadMoreButton from './HomeDownloadLoadMoreButton.vue';
import Spinner from './Spinner.vue';
export default {
@ -35,13 +40,26 @@
components: {
HomeDownloadDevItem,
HomeDownloadDevMaster,
HomeDownloadLoadMoreButton,
Spinner,
},
asyncComputed: {
async master() {
data: () => ({
master: null,
versions: [],
moreLink: 'https://api.github.com/repos/wulkanowy/wulkanowy/pulls?state=open',
loading: false,
}),
async created() {
await Promise.all([
this.loadMaster(),
this.loadMore(),
]);
},
methods: {
async loadMaster() {
const redirectorUrl = 'https://bitrise-redirector.herokuapp.com/v0.1/apps/daeff1893f3c8128/builds/develop/artifacts/0/info';
const build = await this.$http.get(redirectorUrl);
return {
this.master = {
released: build.body.finished_at,
download: build.body.public_install_page_url,
build: build.body.build_number,
@ -49,29 +67,41 @@
commitUrl: build.body.commit_view_url,
};
},
async versions() {
const response = await this.$http.get('https://api.github.com/repos/wulkanowy/wulkanowy/pulls?state=open');
return (await Promise.all(response.body.map(async (release) => {
const redirectorUrl = `https://bitrise-redirector.herokuapp.com/v0.1/apps/daeff1893f3c8128/builds/${release.head.ref}/artifacts/0/info`;
const build = await this.$http.get(redirectorUrl).catch((error) => error);
return {
title: release.title,
number: release.number,
released: build.body.finished_at,
github: release.html_url,
download: build.body.public_install_page_url,
url: build.body.build_url,
build: build.body.build_number,
avatar: release.user.avatar_url,
user: release.user.login,
commit: release.head.sha,
id: release.id,
};
}))).sort((a, b) => {
if (moment(a.released).isBefore(b.released)) return 1;
if (moment(a.released).isAfter(b.released)) return -1;
return 0;
});
async loadMore() {
if (this.loading || this.moreLink === null) return;
this.loading = true;
try {
const response = await this.$http.get(this.moreLink);
this.versions.push(
...(await Promise.all(response.body.map(async (release) => {
const redirectorUrl = `https://bitrise-redirector.herokuapp.com/v0.1/apps/daeff1893f3c8128/builds/${release.head.ref}/artifacts/0/info`;
const build = await this.$http.get(redirectorUrl).catch((error) => error);
return {
title: release.title,
number: release.number,
released: build.body.finished_at,
github: release.html_url,
download: build.body.public_install_page_url,
url: build.body.build_url,
build: build.body.build_number,
avatar: release.user.avatar_url,
user: release.user.login,
commit: release.head.sha,
id: release.id,
};
}))).sort((a, b) => {
if (moment(a.released).isBefore(b.released)) return 1;
if (moment(a.released).isAfter(b.released)) return -1;
return 0;
}),
);
const nextLinkRegex = /<([^<>]+)>; ?rel="next"/;
const match = nextLinkRegex.exec(response.headers.get('link'));
this.moreLink = match === null ? null : match[1];
} catch (error) {
console.error(error);
}
this.loading = false;
},
},
};

View file

@ -8,7 +8,9 @@
</template>
<script>
export default {};
export default {
name: 'home-download-load-more-button',
};
</script>
<style lang="scss">