Skip to content

Commit

Permalink
Fix review star bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
meagan13 committed Nov 25, 2024
1 parent cbdd852 commit d66f591
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 29 deletions.
17 changes: 9 additions & 8 deletions src/components/posts/AverageRatingStars.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const AverageRatingStars: Component<Props> = (props) => {
>
<div class="flex items-center justify-start">
<svg
id="star1"
id="star1AverageRatings"
fill="none"
width="16px"
height="16px"
Expand Down Expand Up @@ -113,7 +113,7 @@ export const AverageRatingStars: Component<Props> = (props) => {
}
>
<svg
id="star1"
id="star1overall"
fill="none"
width="20px"
height="20px"
Expand All @@ -126,11 +126,12 @@ export const AverageRatingStars: Component<Props> = (props) => {

<Show
when={
(averageRating() >= 1 && averageRating() < 2) ||
(averageRating() >= 2 && averageRating() < 3) ||
(averageRating() >= 3 && averageRating() < 4) ||
(averageRating() >= 4 && averageRating() < 5) ||
averageRating() === 5
averageRating() >= 2
// (averageRating() >= 1 && averageRating() < 2) ||
// (averageRating() >= 2 && averageRating() < 3) ||
// (averageRating() >= 3 && averageRating() < 4) ||
// (averageRating() >= 4 && averageRating() < 5) ||
// averageRating() === 5
}
fallback={
<div>
Expand All @@ -147,7 +148,7 @@ export const AverageRatingStars: Component<Props> = (props) => {
}
>
<svg
id="star2"
id="star2Average"
fill="none"
width="20px"
height="20px"
Expand Down
45 changes: 32 additions & 13 deletions src/components/posts/FullPostView.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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 { createSignal, createEffect, Show, onMount } from "solid-js";
import supabase from "../../lib/supabaseClient";
import { getLangFromUrl, useTranslations } from "../../i18n/utils";
import SocialModal from "./SocialModal";
Expand Down Expand Up @@ -64,6 +64,8 @@ async function fetchReviews({
});
const data = await response.json();

console.log("data from fetchReviews function: ", data);

return data;
}

Expand All @@ -79,6 +81,10 @@ export const ViewFullPost: Component<Props> = (props) => {
const [session, setSession] = createSignal<AuthSession | null>(null);
const [editRender, setEditRender] = createSignal<boolean>(false);
const [review, setReview] = createSignal<Review>();
const [resourceReviews, setResourceReviews] = createSignal<Array<object>>(
[]
);
const [loading, setLoading] = createSignal<boolean>(true);

if (UserError) {
console.log("User Error: " + UserError.message);
Expand All @@ -92,6 +98,10 @@ export const ViewFullPost: Component<Props> = (props) => {
}
// setTestImages(test2);

onMount(async () => {
await getResourceReviews(props.postId);
});

createEffect(() => {
if (props.postId === undefined) {
location.href = `/${lang}/404`;
Expand Down Expand Up @@ -137,6 +147,27 @@ export const ViewFullPost: Component<Props> = (props) => {
}
};

const getResourceReviews = async (postID: any) => {
setLoading(true);

const { data: reviews, error } = await supabase
.from("reviews")
.select("*")
.eq("resource_id", postID);

if (error) {
console.log("Reviews Error: " + error.code + " " + error.message);
return;
}

console.log("reviews data: ", reviews);

setResourceReviews(reviews);
console.log("resourceReviews signal: ", resourceReviews());

setLoading(false);
};

const fetchOwnedPost = async function (id: number) {
const { data, error } = await supabase.from("orders").select("*");

Expand Down Expand Up @@ -847,18 +878,6 @@ export const ViewFullPost: Component<Props> = (props) => {
</button>
</Show>

<Show when={session()?.user.id === post()?.user_id}>
<button
class="btn-primary"
onclick={() => {
setEditRender(!editRender());
//(editRender());
}}
>
Reviews
</button>
</Show>

{/* </Show> */}
{/* NOTE: Quantity and AddToCart styles updated/correct in mobile merge */}
<div class="price-div mx-2 mb-4 flex justify-end">
Expand Down
5 changes: 2 additions & 3 deletions src/components/posts/ReviewPurchasedResource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export const ReviewPurchasedResource: Component<Props> = (props) => {
}
>
<svg
id="star1"
id="star1ReviewPurchasedResources"
fill="none"
width="20px"
height="20px"
Expand All @@ -221,7 +221,6 @@ export const ReviewPurchasedResource: Component<Props> = (props) => {

<Show
when={
dbReviewNum() === 1 ||
dbReviewNum() === 2 ||
dbReviewNum() === 3 ||
dbReviewNum() === 4 ||
Expand All @@ -242,7 +241,7 @@ export const ReviewPurchasedResource: Component<Props> = (props) => {
}
>
<svg
id="star2"
id="star2Purchase"
fill="none"
width="20px"
height="20px"
Expand Down
10 changes: 5 additions & 5 deletions src/components/posts/ViewPostReviews.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const ViewPostReviews: Component<Props> = (props) => {
<div>
{reviewsArray()?.map((review) => (
<div class="one-review">
<div class="flex h-8">
<div class="flex h-8 items-center">
{/* <p>{ review.overall_rating }</p> */}
<div class="mr-2 flex items-center">
<Show
Expand Down Expand Up @@ -99,7 +99,7 @@ export const ViewPostReviews: Component<Props> = (props) => {
}
>
<svg
id="star1"
id="star2View"
fill="none"
width="20px"
height="20px"
Expand Down Expand Up @@ -127,7 +127,7 @@ export const ViewPostReviews: Component<Props> = (props) => {
}
>
<svg
id="star1"
id="star3"
fill="none"
width="20px"
height="20px"
Expand Down Expand Up @@ -155,7 +155,7 @@ export const ViewPostReviews: Component<Props> = (props) => {
}
>
<svg
id="star1"
id="star4"
fill="none"
width="20px"
height="20px"
Expand Down Expand Up @@ -183,7 +183,7 @@ export const ViewPostReviews: Component<Props> = (props) => {
}
>
<svg
id="star1"
id="star5"
fill="none"
width="20px"
height="20px"
Expand Down

0 comments on commit d66f591

Please sign in to comment.