Hangar/frontend/pages/_author/index.vue

105 lines
4.1 KiB
Vue
Raw Normal View History

2021-01-22 01:19:00 +08:00
<template>
2021-03-15 01:16:16 +08:00
<UserProfile :user="user">
<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>
</UserProfile>
2021-01-22 01:19:00 +08:00
</template>
<script lang="ts">
import { Component, Vue } 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';
import { HangarUser } from 'hangar-internal';
import UserAvatar from '~/components/UserAvatar.vue';
2021-02-11 20:37:06 +08:00
import ProjectList from '~/components/projects/ProjectList.vue';
2021-03-15 01:16:16 +08:00
import UserProfile from '~/components/layouts/UserProfile.vue';
2021-01-22 01:19:00 +08:00
2021-02-09 02:26:18 +08:00
@Component({
components: {
2021-03-15 01:16:16 +08:00
UserProfile,
2021-02-09 02:26:18 +08:00
UserAvatar,
ProjectList,
},
})
2021-01-23 02:44:49 +08:00
export default class AuthorPage extends Vue {
2021-02-09 02:26:18 +08:00
user!: HangarUser;
2021-01-23 02:44:49 +08:00
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:16:54 +08:00
$api.requestInternal<HangarUser>(`users/${route.params.author}`, false),
$api.request<PaginatedResult<ProjectCompact>>(`users/${route.params.author}/starred`, false),
$api.request<PaginatedResult<ProjectCompact>>(`users/${route.params.author}/watching`, false),
$api.request<PaginatedResult<Project>>(`projects`, false, 'get', {
2021-02-09 02:26:18 +08:00
owner: route.params.author,
2021-03-17 13:19:50 +08:00
}),
]).catch($util.handlePageRequestError);
if (typeof data === 'undefined') return;
return { user: data[0], starred: data[2], watching: data[1], projects: data[3] };
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>