Skip to content

Commit

Permalink
feat: + following latest
Browse files Browse the repository at this point in the history
  • Loading branch information
dragon-fish committed Feb 29, 2024
1 parent 766b5d6 commit e159892
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 4 deletions.
2 changes: 0 additions & 2 deletions src/components/ArtworksList/ArtworkCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,6 @@ async function handleBookmark() {
transform: translate(-50%, -50%)
transition: all 0.25s ease-in-out
&:hover a,
& a.router-link-active
&:hover a,
& a.router-link-active
&::before
Expand Down
4 changes: 3 additions & 1 deletion src/components/SideNav/SideNav.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ aside.global-side-nav(:class='{ hidden: !sideNavStore.isOpened }')
ul
ListLink(link='/' text='首页')
IFasHome.link-icon
ListLink.not-allowed(link='' text='插画')
ListLink.not-allowed(link='' text='探索发现')
IFasImage.link-icon
ListLink(link='/ranking' text='排行榜')
IFasCrown.link-icon
Expand All @@ -35,6 +35,8 @@ aside.global-side-nav(:class='{ hidden: !sideNavStore.isOpened }')
text='我的关注'
)
IFasUser.link-icon
ListLink(link='/following/latest' text='关注用户的作品')
IFasUser.link-icon

.group
.title PixivNow
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ const routes: RouteRecordRaw[] = [
name: 'artworks',
component: () => import('@/view/artworks.vue'),
},
{
path: '/following/latest',
alias: ['/bookmark_new_illust'],
name: 'following-latest',
component: () => import('@/view/following-latest.vue'),
},
{
path: '/users/:id',
name: 'users',
Expand Down
59 changes: 59 additions & 0 deletions src/view/following-latest.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<template lang="pug">
#following-latest-view.body-inner
h1 已关注用户的作品
ArtworkList(:list='illusts', :loading='isLoading && !illusts.length')
ShowMore(
:loading='isLoading',
:method='fetchList',
:text='isLoading ? "加载中" : "加载更多"'
v-if='hasNextPage && illusts.length'
)
</template>

<script lang="ts" setup>
import { type ArtworkInfo } from '@/types'
onMounted(() => {
setTitle('New Artworks from Following Users')
fetchList()
})
const illusts = ref<ArtworkInfo[]>([])
const userStore = useUserStore()
const route = useRoute()
const router = useRouter()
const nextPage = ref(1)
const hasNextPage = ref(true)
const isLoading = ref(false)
async function fetchList() {
if (!userStore.isLoggedIn) {
return router.push({
name: 'login',
query: { back: route.fullPath },
})
}
if (isLoading.value) return
isLoading.value = true
try {
// https://www.pixiv.net/ajax/follow_latest/illust?p=1&mode=all
const { data } = await ajax.get<{
page: {
isLastPage: boolean
}
thumbnails: {
illust: ArtworkInfo[]
}
}>(`/ajax/follow_latest/illust`, {
params: { p: nextPage.value, mode: 'all' },
})
illusts.value.push(...data.thumbnails.illust)
nextPage.value++
hasNextPage.value = !data.page.isLastPage
} finally {
isLoading.value = false
}
}
</script>
2 changes: 1 addition & 1 deletion src/view/following.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
h1
.flex.gap-1
NButton(
@click='$router.push({ name: "user", params: { id: targetUserId } })'
@click='$router.push({ name: "users", params: { id: targetUserId } })'
circle
secondary
)
Expand Down
2 changes: 2 additions & 0 deletions src/view/users.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
:loading='loadingUserFollow',
:type='user.isFollowed ? "success" : undefined'
@click='handleUserFollow'
round
size='small'
)
template(#icon)
IFasCheck(v-if='user.isFollowed')
Expand Down

0 comments on commit e159892

Please sign in to comment.