Новые правки в компоенты

This commit is contained in:
Web-serfer 2026-04-18 18:25:10 +05:00
parent e85d1ce668
commit 6f727aae7b
23 changed files with 1483 additions and 37 deletions

View file

@ -60,13 +60,15 @@ export async function getPostVotes(postId: string): Promise<VoteStats> {
}
export async function getPostVotesStats(postId: string): Promise<{ likes: number; dislikes: number }> {
// Получаем данные поста напрямую (likes/dislikes хранятся в самом посте)
const post = await pb.collection('posts').getOne(postId);
// Получаем данные из коллекции голосов
const votes = await pb.collection('post_votes').getList(1, 1000, {
filter: `post="${postId}"`,
});
return {
likes: post.likes || 0,
dislikes: post.dislikes || 0,
};
const likes = votes.items.filter((v: any) => v.vote_type === 'like').length;
const dislikes = votes.items.filter((v: any) => v.vote_type === 'dislike').length;
return { likes, dislikes };
}
export async function vote(postId: string, voteType: 'like' | 'dislike'): Promise<VoteStats> {