Skip to content

Commit e7ed3b5

Browse files
committed
fix: following and follower list loadMoreKey
1 parent 318fb2e commit e7ed3b5

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

src/api/user-relation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type {
1313
*/
1414
export const getFollowingList = <T = UserRelation.GetFollowingListResponse>(
1515
username: string,
16-
option: PaginationOption = {}
16+
option: PaginationOption<string> = {}
1717
) =>
1818
toResponse<T>(
1919
request.post('1.0/userRelation/getFollowingList', {
@@ -32,7 +32,7 @@ export const getFollowingList = <T = UserRelation.GetFollowingListResponse>(
3232
*/
3333
export const getFollowerList = <T = UserRelation.GetFollowerListResponse>(
3434
username: string,
35-
option: PaginationOption<{ createdAt: string }> = {}
35+
option: PaginationOption<string> = {}
3636
) =>
3737
toResponse<T>(
3838
request.post('1.0/userRelation/getFollowerList', {

src/client/user.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,12 @@ export class JikeUser<M extends boolean = boolean> {
111111
await this.getUsername(),
112112
{
113113
limit: 20,
114-
loadMoreKey: lastKey ? { createdAt: lastKey } : undefined,
114+
loadMoreKey: lastKey,
115115
}
116116
)
117117
if (!isSuccess(result)) throwRequestFailureError(result, '查询用户被关注')
118118

119-
const newKey = result.data.loadMoreKey?.createdAt
119+
const newKey = result.data.loadMoreKey
120120
return [newKey, result.data.data]
121121
}
122122

@@ -140,11 +140,14 @@ export class JikeUser<M extends boolean = boolean> {
140140
) => {
141141
const result = await this.#client.apiClient.userRelation.getFollowerList(
142142
await this.getUsername(),
143-
{ limit: 1, loadMoreKey: lastKey ? { createdAt: lastKey } : undefined }
143+
{
144+
limit: 1,
145+
loadMoreKey: lastKey,
146+
}
144147
)
145148
if (!isSuccess(result)) throwRequestFailureError(result, '查询用户被关注')
146149

147-
const newKey = result.data.loadMoreKey?.createdAt
150+
const newKey = result.data.loadMoreKey
148151
const data: FollowerWithTime[] = result.data.data[0]
149152
? [
150153
{
@@ -221,11 +224,11 @@ export class JikeUser<M extends boolean = boolean> {
221224
const fetcher: PaginatedFetcher<User, string> = async (lastKey) => {
222225
const result = await this.#client.apiClient.userRelation.getFollowingList(
223226
await this.getUsername(),
224-
{ limit: 20, loadMoreKey: lastKey ? { createdAt: lastKey } : undefined }
227+
{ limit: 20, loadMoreKey: lastKey }
225228
)
226229
if (!isSuccess(result)) throwRequestFailureError(result, '查询用户被关注')
227230

228-
const newKey = result.data.loadMoreKey?.createdAt
231+
const newKey = result.data.loadMoreKey
229232
return [newKey, result.data.data]
230233
}
231234

src/types/api-responses.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,12 @@ export namespace Notifications {
4848
export namespace UserRelation {
4949
export interface GetFollowingListResponse {
5050
data: User[]
51-
loadMoreKey?: {
52-
createdAt: string
53-
}
51+
loadMoreKey?: string
5452
}
5553

5654
export interface GetFollowerListResponse {
5755
data: User[]
58-
loadMoreKey?: {
59-
createdAt: string
60-
}
56+
loadMoreKey?: string
6157
}
6258

6359
export interface FollowResponse {

tests/api/user-relation.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ describe('user relation should work', () => {
1212
const result = await api.userRelation.getFollowerList(username, { limit })
1313
expect(isSuccess(result)).toBe(true)
1414
expect(result.data.data.length).toBe(limit)
15+
expect(result.data.loadMoreKey).toBeTypeOf('string')
1516
})
1617

1718
it('getFollowingList should work', async () => {
1819
const result = await api.userRelation.getFollowingList(username, { limit })
1920
expect(isSuccess(result)).toBe(true)
2021
expect(result.data.data.length).toBe(limit)
22+
expect(result.data.loadMoreKey).toBeTypeOf('string')
2123
})
2224

2325
it.todo('follow should work')

0 commit comments

Comments
 (0)