Skip to content

Commit

Permalink
Merge pull request #184 from datagrove/reviewsBugs
Browse files Browse the repository at this point in the history
Reviews bugs
  • Loading branch information
r-southworth authored Nov 25, 2024
2 parents 1834f9b + 5de67a4 commit 14ecfd4
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 31 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
24 changes: 21 additions & 3 deletions src/components/posts/ReviewPurchasedResource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export const ReviewPurchasedResource: Component<Props> = (props) => {
const [showReviewForm, setShowReviewForm] = createSignal(true);
const [dbReviewNum, setDbReviewNum] = createSignal<number>(0);
const [showReviewFieldAlert, setShowReviewFieldAlert] = createSignal(false);
const [showTitleAlert, setShowTitleAlert] = createSignal(false);

onMount(async () => {
try {
Expand Down Expand Up @@ -143,6 +144,16 @@ export const ReviewPurchasedResource: Component<Props> = (props) => {
return false;
}

if (reviewText() !== "" && reviewTitle() === "") {
setShowTitleAlert(true);

setTimeout(() => {
setShowTitleAlert(false);
}, 3000);

return false;
}

const formData = new FormData(e.target as HTMLFormElement);
formData.append("review_title", reviewTitle());
formData.append("review_text", reviewText());
Expand Down Expand Up @@ -208,7 +219,7 @@ export const ReviewPurchasedResource: Component<Props> = (props) => {
}
>
<svg
id="star1"
id="star1ReviewPurchasedResources"
fill="none"
width="20px"
height="20px"
Expand All @@ -221,7 +232,6 @@ export const ReviewPurchasedResource: Component<Props> = (props) => {

<Show
when={
dbReviewNum() === 1 ||
dbReviewNum() === 2 ||
dbReviewNum() === 3 ||
dbReviewNum() === 4 ||
Expand All @@ -242,7 +252,7 @@ export const ReviewPurchasedResource: Component<Props> = (props) => {
}
>
<svg
id="star2"
id="star2Purchase"
fill="none"
width="20px"
height="20px"
Expand Down Expand Up @@ -457,6 +467,14 @@ export const ReviewPurchasedResource: Component<Props> = (props) => {
</p>
</Show>

<Show when={showTitleAlert() === true}>
<p class="text-lg text-alert1 dark:text-alert1-DM">
{t(
"messages.titleRequiredIfTextEntered"
)}
</p>
</Show>

<div>
<span class="text-alert1">* </span>
<span class="italic">
Expand Down
12 changes: 6 additions & 6 deletions src/components/posts/ViewPostReviews.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ export const ViewPostReviews: Component<Props> = (props) => {
>
<div>
{reviewsArray()?.map((review) => (
<div class="one-review">
<div class="flex h-8">
<div class="one-review border border-x-0 border-t-0 border-border1 border-opacity-25 pb-2 dark:border-border1-DM">
<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
3 changes: 2 additions & 1 deletion src/i18n/UI/English.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ export const English = {
resourceLinks: "Thanks for using LearnGrove! Here are your links:",
externalResourceDisclaimer: "LearnGrove provides links to these external resources as a convenience. LearnGrove is not responsible for and has no control over information at any external site. LearnGrove is not responsible for the quality, content, privacy, or reliability of any linked site. In no event shall LearnGrove be responsible for your use of a linked site. Many of these external sites are funded through advertising which may make use of cookies and other tracking technology to target your interests for that advertising. Please be careful when clicking on any links on an external site to ensure you are only accessing links you intend to.",
submitted: "Submitted",
overallReviewRequired: "Please include an overall rating for your review"
overallReviewRequired: "Please include an overall rating for your review",
titleRequiredIfTextEntered: "Please include a title for your review if you enter a review description",
},

formLabels: {
Expand Down
1 change: 1 addition & 0 deletions src/i18n/UI/French.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ export const French = {
externalResourceDisclaimer: "LearnGrove fournit des liens vers ces ressources externes pour plus de commodité. LearnGrove n'est pas responsable et n'a aucun contrôle sur les informations contenues dans aucun site externe. LearnGrove n'est pas responsable de la qualité, du contenu, de la confidentialité ou de la fiabilité de tout site lié. En aucun cas LearnGrove ne sera responsable de votre utilisation d’un site lié. Beaucoup de ces sites externes sont financés par la publicité qui peut utiliser des cookies et d'autres technologies de suivi pour cibler vos intérêts pour cette publicité. Veuillez être prudent lorsque vous cliquez sur des liens sur un site externe pour vous assurer que vous accédez uniquement aux liens auxquels vous avez l'intention d'accéder.",
submitted: "Soumise",
overallReviewRequired: "Veuillez inclure une note globale pour votre avis",
titleRequiredIfTextEntered: "Veuillez inclure un titre pour votre avis si vous saisissez une description d'avis",
},

formLabels: {
Expand Down
1 change: 1 addition & 0 deletions src/i18n/UI/Spanish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ export const Spanish = {
externalResourceDisclaimer: "LearnGrove proporciona enlaces a estos recursos externos para su comodidad. LearnGrove no es responsable ni tiene control sobre la información contenida en ningún sitio externo. LearnGrove no es responsable de la calidad, el contenido, la privacidad o la confiabilidad de ningún sitio vinculado. En ningún caso LearnGrove será responsable del uso que usted haga de un sitio vinculado. Muchos de estos sitios externos se financian a través de publicidad que puede utilizar cookies y otras tecnologías de seguimiento para orientar sus intereses para esa publicidad. Tenga cuidado al hacer clic en cualquier enlace de un sitio externo para asegurarse de acceder solo a los enlaces que desea.",
submitted: "Enviada",
overallReviewRequired: "Incluya una calificación general para su revisión",
titleRequiredIfTextEntered: "Incluya un título para su reseña si ingresa una descripción de la reseña",
},

formLabels: {
Expand Down
1 change: 1 addition & 0 deletions src/i18n/uiType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ export interface uiObject {
externalResourceDisclaimer: string;
submitted: string,
overallReviewRequired: string,
titleRequiredIfTextEntered: string,
};

formLabels: {
Expand Down

0 comments on commit 14ecfd4

Please sign in to comment.