From 5bb4525f63c86cb8e4fd8650cd3c2eee897b751b Mon Sep 17 00:00:00 2001 From: Web-serfer Date: Tue, 21 Apr 2026 22:43:01 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=BE=D0=B2=D1=8B=D0=B5=20=D0=B8=D0=B7?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F=20=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BC=D0=BF=D0=BE=D0=BD=D0=B5=D0=BD=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../1776793202_updated_review_votes.js | 20 + .../1776793214_updated_review_votes.js | 20 + .../src/components/reviews/ReviewCard.astro | 632 ++++++++++-------- .../src/components/reviews/ReviewsList.astro | 1 - frontend/src/pages/api/reviews/vote.ts | 12 +- 5 files changed, 399 insertions(+), 286 deletions(-) create mode 100644 backend/pb_migrations/1776793202_updated_review_votes.js create mode 100644 backend/pb_migrations/1776793214_updated_review_votes.js diff --git a/backend/pb_migrations/1776793202_updated_review_votes.js b/backend/pb_migrations/1776793202_updated_review_votes.js new file mode 100644 index 0000000..cd6ba68 --- /dev/null +++ b/backend/pb_migrations/1776793202_updated_review_votes.js @@ -0,0 +1,20 @@ +/// +migrate((app) => { + const collection = app.findCollectionByNameOrId("pbc_362615506") + + // update collection data + unmarshal({ + "listRule": "" + }, collection) + + return app.save(collection) +}, (app) => { + const collection = app.findCollectionByNameOrId("pbc_362615506") + + // update collection data + unmarshal({ + "listRule": "@request.auth.id != \"\"" + }, collection) + + return app.save(collection) +}) diff --git a/backend/pb_migrations/1776793214_updated_review_votes.js b/backend/pb_migrations/1776793214_updated_review_votes.js new file mode 100644 index 0000000..b388704 --- /dev/null +++ b/backend/pb_migrations/1776793214_updated_review_votes.js @@ -0,0 +1,20 @@ +/// +migrate((app) => { + const collection = app.findCollectionByNameOrId("pbc_362615506") + + // update collection data + unmarshal({ + "viewRule": "" + }, collection) + + return app.save(collection) +}, (app) => { + const collection = app.findCollectionByNameOrId("pbc_362615506") + + // update collection data + unmarshal({ + "viewRule": "@request.auth.id != \"\"" + }, collection) + + return app.save(collection) +}) diff --git a/frontend/src/components/reviews/ReviewCard.astro b/frontend/src/components/reviews/ReviewCard.astro index ec8d6aa..677312a 100644 --- a/frontend/src/components/reviews/ReviewCard.astro +++ b/frontend/src/components/reviews/ReviewCard.astro @@ -1,14 +1,16 @@ --- +type ColorKey = 'bg-gradient-1' | 'bg-gradient-2' | 'bg-gradient-3' | 'bg-gradient-4' | 'bg-gradient-5' | 'bg-gradient-6'; + export interface Props { name: string; profession: string; text: string; rating: number; initial: string; - color: string; + color: ColorKey; date: string; - votesCount?: number; - reviewId?: string; + reviewId: string; + initialLikes?: number; } const { @@ -19,8 +21,8 @@ const { initial, color, date, - votesCount = 0, - reviewId = '' + reviewId, + initialLikes = 0 } = Astro.props; // Форматируем дату @@ -32,14 +34,41 @@ const formatDate = (dateStr: string) => { year: 'numeric' }); }; + +// Цвета для градиентов аватаров +const gradientColors = { + 'bg-gradient-1': 'from-purple-500 to-pink-500', + 'bg-gradient-2': 'from-blue-500 to-cyan-500', + 'bg-gradient-3': 'from-green-500 to-emerald-500', + 'bg-gradient-4': 'from-orange-500 to-red-500', + 'bg-gradient-5': 'from-indigo-500 to-purple-500', + 'bg-gradient-6': 'from-rose-500 to-orange-500', +}; --- -
+
+ +
+ + +
+ + + +
+
-
- {initial} +
+
+ {initial} +
+
+ + + +

{name}

@@ -53,67 +82,103 @@ const formatDate = (dateStr: string) => {
{[1, 2, 3, 4, 5].map((star) => ( - - - + + + ))}
+ {rating}.0
-

{text}

+

"{text}"

- -
- - + + Чтобы голосовать, нужно войти
+ \ No newline at end of file diff --git a/frontend/src/components/reviews/ReviewsList.astro b/frontend/src/components/reviews/ReviewsList.astro index 969d5dd..dfdf333 100644 --- a/frontend/src/components/reviews/ReviewsList.astro +++ b/frontend/src/components/reviews/ReviewsList.astro @@ -115,7 +115,6 @@ const getAvatarInfo = (name: string) => { initial={avatarInfo.initial} color={avatarInfo.color} date={review.created} - votesCount={review.votesCount || 0} reviewId={review.id} /> ); diff --git a/frontend/src/pages/api/reviews/vote.ts b/frontend/src/pages/api/reviews/vote.ts index 3cac220..8f5e990 100644 --- a/frontend/src/pages/api/reviews/vote.ts +++ b/frontend/src/pages/api/reviews/vote.ts @@ -115,16 +115,21 @@ export const POST: APIRoute = async ({ request, cookies }) => { const votesRes = await fetch( `${POCKETBASE_URL}/api/collections/review_votes/records?filter=(review="${review_id}")`, - {} + { headers: { 'Authorization': `Bearer ${token}` } } ); + console.log('[ReviewVote API] Votes response:', votesRes.status); let likes = 0; let dislikes = 0; if (votesRes.ok) { const votesData = await votesRes.json(); + console.log('[ReviewVote API] Votes data:', JSON.stringify(votesData)); likes = votesData.items?.filter((v: any) => v.vote_type === 'likes').length || 0; dislikes = votesData.items?.filter((v: any) => v.vote_type === 'dislikes').length || 0; + } else { + const errorText = await votesRes.text(); + console.error('[ReviewVote API] Votes error:', errorText); } return new Response( @@ -152,16 +157,19 @@ export const GET: APIRoute = async ({ url, cookies }) => { ); } + const authHeaders = token ? { 'Authorization': `Bearer ${token}` } : {}; const votesRes = await fetch( `${POCKETBASE_URL}/api/collections/review_votes/records?filter=(review="${reviewId}")`, - {} + { headers: authHeaders } ); + console.log('[ReviewVote API GET] Votes response:', votesRes.status); let likes = 0; let dislikes = 0; if (votesRes.ok) { const votesData = await votesRes.json(); + console.log('[ReviewVote API GET] Votes data:', JSON.stringify(votesData)); likes = votesData.items?.filter((v: any) => v.vote_type === 'likes').length || 0; dislikes = votesData.items?.filter((v: any) => v.vote_type === 'dislikes').length || 0; }