From d6063f820b9526cd4f2f25403dfdb2a188e40e22 Mon Sep 17 00:00:00 2001 From: Meagan Date: Fri, 1 Nov 2024 13:55:57 -0500 Subject: [PATCH 01/11] Add reviews to posts - not working yet --- src/assets/dog-4-svgrepo-com (2).svg | 7 + src/assets/person-svgrepo-com.svg | 2 + src/components/posts/AverageRatingStars.tsx | 20 +- src/components/posts/FullPostView.tsx | 74 +++++-- .../posts/ReviewPurchasedResource.tsx | 10 +- src/components/posts/ViewPostReviews.tsx | 202 ++++++++++++++++++ src/lib/types.ts | 13 +- src/pages/api/getAllReviews.ts | 2 +- src/styles/global.css | 16 +- 9 files changed, 302 insertions(+), 44 deletions(-) create mode 100644 src/assets/dog-4-svgrepo-com (2).svg create mode 100644 src/assets/person-svgrepo-com.svg create mode 100644 src/components/posts/ViewPostReviews.tsx diff --git a/src/assets/dog-4-svgrepo-com (2).svg b/src/assets/dog-4-svgrepo-com (2).svg new file mode 100644 index 00000000..fe286bba --- /dev/null +++ b/src/assets/dog-4-svgrepo-com (2).svg @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/src/assets/person-svgrepo-com.svg b/src/assets/person-svgrepo-com.svg new file mode 100644 index 00000000..5dc03b8d --- /dev/null +++ b/src/assets/person-svgrepo-com.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/src/components/posts/AverageRatingStars.tsx b/src/components/posts/AverageRatingStars.tsx index fb474f4e..7ab7a793 100644 --- a/src/components/posts/AverageRatingStars.tsx +++ b/src/components/posts/AverageRatingStars.tsx @@ -65,8 +65,14 @@ export const AverageRatingStars: Component = (props) => { }); return ( -
- +
+
= (props) => { -
-

{averageRating()}

-

({totalRatings()}) {t("postLabels.reviews")}

+
+

+ {averageRating()} +

+

+ ({totalRatings()}) {t("postLabels.reviews")} +

diff --git a/src/components/posts/FullPostView.tsx b/src/components/posts/FullPostView.tsx index c2505c67..09556061 100644 --- a/src/components/posts/FullPostView.tsx +++ b/src/components/posts/FullPostView.tsx @@ -1,5 +1,6 @@ import type { Component } from "solid-js"; import type { Post } from "@lib/types"; +import type { Review } from "@lib/types"; import { createSignal, createEffect, Show } from "solid-js"; import supabase from "../../lib/supabaseClient"; import { getLangFromUrl, useTranslations } from "../../i18n/utils"; @@ -12,6 +13,7 @@ import type { AuthSession } from "@supabase/supabase-js"; import type { FilterPostsParams } from "@lib/types"; import { ReportResource } from "./ReportResource"; import { AverageRatingStars } from "../posts/AverageRatingStars"; +import { ViewPostReviews } from "./ViewPostReviews"; const lang = getLangFromUrl(new URL(window.location.href)); const t = useTranslations(lang); @@ -41,6 +43,30 @@ async function fetchPosts({ return data; } +async function fetchReviews({ + created_at, + resource_id, + reviewer_id, + review_title, + review_text, + overall_rating, +}: Review) { + const response = await fetch("/api/getRatings", { + method: "POST", + body: JSON.stringify({ + created_at: created_at, + resource_id: resource_id, + reviewer_id: reviewer_id, + review_title: review_title, + review_text: review_text, + overall_rating: overall_rating, + }), + }); + const data = await response.json(); + + return data; +} + const { data: User, error: UserError } = await supabase.auth.getSession(); export const ViewFullPost: Component = (props) => { @@ -50,10 +76,9 @@ export const ViewFullPost: Component = (props) => { { webpUrl: string; jpegUrl: string }[] >([]); const [quantity, setQuantity] = createSignal(1); - const [session, setSession] = createSignal(null); - const [editRender, setEditRender] = createSignal(false); + const [review, setReview] = createSignal(); if (UserError) { console.log("User Error: " + UserError.message); @@ -99,7 +124,7 @@ export const ViewFullPost: Component = (props) => { } else { setPost(userRes.body[0]); setPostImages(userRes.body[0].image_signedUrls); - console.log(post()); + console.log("this is the post:", post()); } } else if (res.body.length < 1 && User.session === null) { alert(t("messages.noPost")); @@ -107,7 +132,7 @@ export const ViewFullPost: Component = (props) => { } else { setPost(res.body[0]); setPostImages(res.body[0].image_signedUrls); - console.log(post()); + console.log("post() in FullPostView:", post()); } } catch (error) { console.log(error); @@ -391,7 +416,7 @@ export const ViewFullPost: Component = (props) => { // console.log(postImages()); return ( -
+
= (props) => { >

{t("menus.description")}

- {/* TODO : Add back for reviews and Q&A - -

{t("menus.reviews")}

-
- -

{t("menus.qA")}

-
*/} + + +

{t("menus.reviews")}

+
+ {/* TODO: Add Q&A section */} + {/* +

{t("menus.qA")}

+
*/}
@@ -998,9 +1024,13 @@ export const ViewFullPost: Component = (props) => { {/* TODO: Language file in mobile component merge is updated, delete hardcoding upon merging */} {/*

{t("menus.reviews")}Reviews

*/}
+ {post()?.title}

{t("messages.comingSoon")}

+ {typeof post()?.id}: {post()?.id} + +