Skip to content

Commit

Permalink
fix(frontend): ⚡ Add refetch to home page and category select | fix a…
Browse files Browse the repository at this point in the history
…dd product form
  • Loading branch information
kjarret committed Jul 17, 2024
1 parent c0287cd commit 3836106
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
8 changes: 6 additions & 2 deletions frontend/src/components/CategorySelect.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useQuery } from "@apollo/client";
import * as Select from "@radix-ui/react-select";
import { GET_ALL_CATEGORIES } from "lib/graphql/queries";
import { useState } from "react";
import { useEffect, useState } from "react";

interface Category {
id: string;
Expand All @@ -19,9 +19,13 @@ const CategorySelect: React.FC<CategorySelectProps> = ({
selectedCategoryName,
onCategoryChange,
}) => {
const { loading, error, data } = useQuery(GET_ALL_CATEGORIES);
const { loading, error, data, refetch } = useQuery(GET_ALL_CATEGORIES);
const [isOpen, setIsOpen] = useState(false);

useEffect(() => {
refetch();
});

const handleSelectChange = (categoryId: string, categoryName: string) => {
onCategoryChange(categoryId, categoryName);
};
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/components/ui/SearchInput.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { useQuery } from "@apollo/client";
import { GET_ALL_PRODUCTS_BY_KEYWORD } from "lib/graphql/queries";
import Link from "next/link";
import { useEffect, useState } from "react";

import { FaTimes } from "react-icons/fa";
import { IoMdSearch } from "react-icons/io";

import Link from "next/link";

const SearchInput = () => {
const [searchActive, setSearchActive] = useState(false);
const [searchValue, setSearchValue] = useState("");
Expand Down
8 changes: 7 additions & 1 deletion frontend/src/containers/public/home/hot-products-section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ import LoadingProgress from "components/ui/LoadingProgress";
import { GET_PRODUCTS } from "lib/graphql/queries";
import { HiPlusCircle } from "react-icons/hi";

import { useEffect } from "react";

import styles from "styles/pages/ProductsPage.module.scss";

const HomeHotProductsSection = () => {
const { data, loading, error } = useQuery(GET_PRODUCTS);
const { data, loading, error, refetch } = useQuery(GET_PRODUCTS);

useEffect(() => {
refetch();
});

if (loading) return <LoadingProgress />;
if (error) return <p>Error: {error.message}</p>;
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/products/add.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ const ProductsAddPage = () => {
<br />
<label>
Description courte: <br />
<input className="text-field" {...register("description_long")} />
<input className="text-field" {...register("description_short")} />
</label>
<br />
<label>
Description longue: <br />
<input className="text-field" {...register("description_short")} />
<input className="text-field" {...register("description_long")} />
</label>
<br />
<div className="flex gap-4">
Expand Down

0 comments on commit 3836106

Please sign in to comment.