diff --git a/components/landing/HeaderNews.tsx b/components/landing/HeaderNews.tsx
index 437918c..2a891ef 100644
--- a/components/landing/HeaderNews.tsx
+++ b/components/landing/HeaderNews.tsx
@@ -45,6 +45,7 @@ export default function HeaderNews() {
search: "",
limit: "10",
sort: "desc",
+ isPublish: true,
};
const response = await getListArticle(req);
setArticle(response?.data?.data);
@@ -57,6 +58,7 @@ export default function HeaderNews() {
limit: "10",
sortBy: "view_count",
sort: "desc",
+ category: "586",
isPublish: true,
};
const response = await getListArticle(req);
diff --git a/components/landing/banner-new.tsx b/components/landing/banner-new.tsx
index 3af14fd..85bcf26 100644
--- a/components/landing/banner-new.tsx
+++ b/components/landing/banner-new.tsx
@@ -207,6 +207,15 @@ export default function BannerHumasNew() {
);
};
+
+ const [hasMounted, setHasMounted] = useState(false);
+
+ useEffect(() => {
+ setHasMounted(true);
+ }, []);
+
+ // Render
+ if (!hasMounted) return null;
return (
{
- const { date, type } = props;
+const SuggestionsChart = (props: {
+ type: string;
+ date: string;
+ totals: (data: number) => void;
+}) => {
+ const { date, type, totals } = props;
const [categories, setCategories] = useState
([]);
const [seriesSuggestions, setSeriesSuggestions] = useState([]);
@@ -69,15 +74,17 @@ const SuggestionsChart = (props: { type: string; date: string }) => {
];
const category = [];
const temp = [];
+ let totalData = 0;
for (let i = 0; i < data.length; i++) {
const total = data[i].suggestions.reduce(
(sum: number, list: number) => sum + list,
0
);
temp.push(total);
+ totalData += total;
category.push(months[data[i].month - 1]);
}
- return { categories: category, series: temp };
+ return { categories: category, series: temp, total: totalData };
}
const initFetch = async () => {
@@ -86,16 +93,17 @@ const SuggestionsChart = (props: { type: string; date: string }) => {
// const data = res?.data?.data;
const data = dummyData.data;
if (type === "monthly") {
- const getDatas = data?.filter(
- (a: any) => a.year === Number(splitDate[1])
- );
+ const getDatas = data?.filter((a) => a.year === Number(splitDate[1]));
+ console.log("teemp,tota", getDatas);
+
if (getDatas) {
const temp = processYearlyData(getDatas);
- console.log("temp", temp);
setSeriesSuggestions(temp.series);
setCategories(temp.categories);
+ totals(temp.total);
} else {
setSeriesSuggestions([]);
+ totals(0);
}
} else {
const getDatas = data?.find(
@@ -104,24 +112,25 @@ const SuggestionsChart = (props: { type: string; date: string }) => {
);
if (getDatas) {
const temp = processMonthlyData(getDatas?.suggestions);
+ const sum = getDatas.suggestions.reduce((acc, curr) => acc + curr, 0);
+ totals(sum);
if (type == "weekly") {
setSeriesSuggestions(
temp.weeks.map((list) => {
return list.total;
})
);
- } else {
- setSeriesSuggestions(getDatas.suggestions);
- }
- if (type === "weekly") {
const category = [];
for (let i = 1; i <= temp.weeks.length; i++) {
category.push(`Minggu ke-${i}`);
}
setCategories(category);
+ } else {
+ setSeriesSuggestions(getDatas.suggestions);
}
} else {
setSeriesSuggestions([]);
+ totals(0);
}
}
};
diff --git a/components/main/detail/list-news.tsx b/components/main/detail/list-news.tsx
index 2b833c7..d5ffa07 100644
--- a/components/main/detail/list-news.tsx
+++ b/components/main/detail/list-news.tsx
@@ -20,16 +20,25 @@ import { useEffect, useRef, useState } from "react";
import { getListArticle } from "@/service/article";
import { formatMonthString, htmlToString, textEllipsis } from "@/utils/global";
import Image from "next/image";
-import { useParams } from "next/navigation";
+import {
+ useParams,
+ usePathname,
+ useRouter,
+ useSearchParams,
+} from "next/navigation";
export default function ListNews() {
const [article, setArticle] = useState([]);
- const [search, setSearch] = useState("");
const [page, setPage] = useState(1);
+ const router = useRouter();
+ const pathname = usePathname();
const [totalPage, setTotalPage] = useState(1);
const topRef = useRef(null);
const params = useParams();
const category = params?.name;
+ const searchParams = useSearchParams();
+ const search = searchParams.get("search");
+ const [searchValue, setSearchValue] = useState(search || "");
useEffect(() => {
getArticle();
@@ -41,9 +50,10 @@ export default function ListNews() {
const req = {
page: page,
- search: search,
+ search: searchValue || "",
limit: "9",
category: String(category),
+ isPublish: true,
};
const response = await getListArticle(req);
setArticle(response?.data?.data);
@@ -52,7 +62,7 @@ export default function ListNews() {
}
return (
-
+
@@ -69,13 +79,22 @@ export default function ListNews() {
inputWrapper: "bg-white hover:!bg-gray-100 border-1",
input: "text-sm !text-black",
}}
+ onKeyDown={(event) => {
+ if (event.key === "Enter") {
+ router.push(pathname + `?search=${searchValue}`);
+ getArticle();
+ }
+ }}
labelPlacement="outside"
placeholder="Search..."
- value={search}
- onValueChange={setSearch}
+ value={searchValue || ""}
+ onValueChange={setSearchValue}
endContent={