Hangar/frontend/pages/_user/index.vue

100 lines
3.9 KiB
Vue
Raw Normal View History

2021-01-22 01:19:00 +08:00
<template>
2021-03-18 04:41:18 +08:00
<v-row>
2021-03-15 01:16:16 +08:00
<v-col cols="12" md="8">
<ProjectList :projects="projects" />
</v-col>
<v-col cols="12" md="4">
<v-card>
<v-card-title>{{ $t('author.orgs') }}</v-card-title>
<v-card-text>
<v-list dense>
<v-list-item v-for="org in orgs.result" :key="org.name">
<NuxtLink :to="'/' + org.name">{{ org.name }}</NuxtLink>
</v-list-item>
</v-list>
<span v-if="!orgs || orgs.result.length === 0">
{{ $t('author.noOrgs', [user.name]) }}
</span>
</v-card-text>
</v-card>
<v-card>
<v-card-title>{{ $t('author.stars') }}</v-card-title>
<v-card-text>
<v-list dense>
<v-list-item v-for="star in starred.result" :key="star.name">
<NuxtLink :to="{ name: `author-slug`, params: { author: star.namespace.owner, slug: star.namespace.slug } }">
{{ star.namespace.owner }}/<b>{{ star.name }}</b>
</NuxtLink>
</v-list-item>
</v-list>
<span v-if="!starred || starred.result.length === 0">
{{ $t('author.noStarred', [user.name]) }}
</span>
</v-card-text>
</v-card>
<v-card class="mb-1">
<v-card-title>{{ $t('author.watching') }}</v-card-title>
<v-card-text>
<v-list dense>
<v-list-item v-for="watch in watching.result" :key="watch.name">
<NuxtLink :to="{ name: `author-slug`, params: { author: watch.namespace.owner, slug: watch.namespace.slug } }">
{{ watch.namespace.owner }}/<b>{{ watch.name }}</b>
</NuxtLink>
</v-list-item>
</v-list>
<span v-if="!watching || watching.result.length === 0">
{{ $t('author.noWatching', [user.name]) }}
</span>
</v-card-text>
</v-card>
2021-03-15 01:16:16 +08:00
</v-col>
2021-03-18 04:41:18 +08:00
</v-row>
2021-01-22 01:19:00 +08:00
</template>
<script lang="ts">
2021-03-18 04:41:18 +08:00
import { Component } from 'nuxt-property-decorator';
2021-03-18 04:16:54 +08:00
import { Organization, PaginatedResult, Project, ProjectCompact } from 'hangar-api';
2021-02-09 02:26:18 +08:00
import { Context } from '@nuxt/types';
2021-03-20 15:24:17 +08:00
import { UserAvatar } from '~/components/users';
import { ProjectList } from '~/components/projects';
2021-03-18 04:41:18 +08:00
import { HangarUserMixin } from '~/components/mixins';
2021-01-22 01:19:00 +08:00
2021-02-09 02:26:18 +08:00
@Component({
components: {
UserAvatar,
ProjectList,
},
})
2021-03-18 04:41:18 +08:00
export default class AuthorPage extends HangarUserMixin {
2021-02-09 02:26:18 +08:00
projects!: PaginatedResult<Project>;
// todo load orgs from server
2021-03-16 01:09:55 +08:00
orgs: PaginatedResult<Organization> = { result: [], pagination: { offset: 0, count: 0, limit: 20 } };
2021-03-18 04:16:54 +08:00
starred!: PaginatedResult<ProjectCompact>;
watching!: PaginatedResult<ProjectCompact>;
2021-02-09 02:26:18 +08:00
head() {
return {
title: this.user.name,
};
}
2021-01-23 02:44:49 +08:00
2021-02-09 02:26:18 +08:00
async asyncData({ $api, route, $util }: Context) {
2021-03-17 13:19:50 +08:00
const data = await Promise.all([
2021-03-18 04:41:18 +08:00
$api.request<PaginatedResult<ProjectCompact>>(`users/${route.params.user}/starred`, false),
$api.request<PaginatedResult<ProjectCompact>>(`users/${route.params.user}/watching`, false),
2021-03-18 04:16:54 +08:00
$api.request<PaginatedResult<Project>>(`projects`, false, 'get', {
2021-03-18 04:41:18 +08:00
owner: route.params.user,
2021-03-17 13:19:50 +08:00
}),
]).catch($util.handlePageRequestError);
if (typeof data === 'undefined') return;
2021-03-18 04:41:18 +08:00
return { starred: data[1], watching: data[0], projects: data[2] };
2021-02-09 02:26:18 +08:00
}
2021-01-23 02:44:49 +08:00
}
2021-01-22 01:19:00 +08:00
</script>
<style lang="scss" scoped>
.v-card {
margin-bottom: 2em;
}
</style>