Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | 5x 1x 1x 1x 1x 1x 1x 1x 109x | import { defineStore } from 'pinia'
import api from '@/services/api'
import type { User } from '@/stores/users'
export interface UserFollow {
followerId: string
followeeId: string
followedAt: string
}
export interface UserListPage {
items: User[]
nextToken: string | null
hasMore: boolean
total: number
}
// Thin API wrappers over the follow endpoints — no shared reactive list state
// here, unlike stores/entities.ts, since followers/following lists are
// page-scoped, one-shot loads owned by the component that renders them
// (FollowersList.vue / FollowingList.vue), not shared/cached across views.
export const useFollowsStore = defineStore('follows', () => {
async function followUser(userId: string): Promise<UserFollow> {
const response = await api.post<UserFollow>(`/v1/users/${userId}/follow`)
return response.data
}
async function unfollowUser(userId: string): Promise<void> {
await api.delete(`/v1/users/${userId}/follow`)
}
async function fetchFollowers(
userId: string,
params?: { limit?: number; nextToken?: string }
): Promise<UserListPage> {
const response = await api.get<UserListPage>(`/v1/users/${userId}/followers`, { params })
return response.data
}
async function fetchFollowing(
userId: string,
params?: { limit?: number; nextToken?: string }
): Promise<UserListPage> {
const response = await api.get<UserListPage>(`/v1/users/${userId}/following`, { params })
return response.data
}
return { followUser, unfollowUser, fetchFollowers, fetchFollowing }
})
|