Skip to content

Commit 0a264a7

Browse files
committed
remove unused Google Analytics scripts and clean up API fetch logic
1 parent e777ed0 commit 0a264a7

File tree

5 files changed

+31
-418
lines changed

5 files changed

+31
-418
lines changed

app/layout.tsx

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,6 @@ export default function RootLayout({
6868

6969
<Footer />
7070

71-
{/* Google Analytics - Replace with your GA ID */}
72-
<Script
73-
src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"
74-
strategy="afterInteractive"
75-
/>
76-
<Script id="google-analytics" strategy="afterInteractive">
77-
{`
78-
window.dataLayer = window.dataLayer || [];
79-
function gtag(){dataLayer.push(arguments);}
80-
gtag('js', new Date());
81-
gtag('config', 'G-XXXXXXXXXX');
82-
`}
83-
</Script>
8471
</body>
8572
</html>
8673
);

components/SearchClientComponent.tsx

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
"use client";
22

3-
import React, { useState, useEffect, Suspense } from "react";
3+
import React, { useEffect, Suspense } from "react";
44
import { useSearchParams } from "next/navigation";
5-
import { fetchApisInfinite } from "@/services/api";
6-
import { cleanDescription } from "@/utils/textProcessing";
75
import { useGridLayout } from "@/hooks/useGridLayout";
86
import { useApiSearch } from "@/hooks/useApiSearch";
97
import { useInfiniteScroll } from "@/hooks/useInfiniteScroll";
@@ -32,14 +30,11 @@ function SearchClientComponentInner({
3230
searchTerm,
3331
setSearchTerm,
3432
allApiCards,
35-
setAllApiCards,
3633
loading,
3734
setLoading,
3835
loadingMore,
3936
hasMore,
40-
currentPage,
4137
loadMoreApis,
42-
searchApis,
4338
resetSearch,
4439
totalCount,
4540
} = useApiSearch(initialCombinedSearchTerm, pageSize);
@@ -52,19 +47,8 @@ function SearchClientComponentInner({
5247
}) as React.RefObject<HTMLDivElement>;
5348

5449
useEffect(() => {
55-
const fetchInitialData = async () => {
56-
try {
57-
setLoading(true);
58-
await resetSearch(initialCombinedSearchTerm);
59-
} catch (error) {
60-
console.error("Error fetching initial data:", error);
61-
} finally {
62-
setLoading(false);
63-
}
64-
};
65-
66-
fetchInitialData();
67-
}, [pageSize, initialCombinedSearchTerm, resetSearch, setLoading]);
50+
resetSearch(initialCombinedSearchTerm);
51+
}, [pageSize, initialCombinedSearchTerm, resetSearch]);
6852

6953
useEffect(() => {
7054
const handleSearchChange = async () => {
@@ -73,31 +57,16 @@ function SearchClientComponentInner({
7357
: searchTerm;
7458

7559
if (combinedSearchTerm !== initialCombinedSearchTerm) {
76-
try {
77-
await resetSearch(combinedSearchTerm);
78-
} catch (error) {
79-
console.error("Error in debounced search:", error);
80-
} finally {
81-
setLoading(false);
82-
}
83-
} else {
84-
setLoading(false);
60+
await resetSearch(combinedSearchTerm);
8561
}
8662
};
8763

8864
const debounceTimer = setTimeout(handleSearchChange, 1000);
8965
return () => clearTimeout(debounceTimer);
90-
}, [
91-
searchTerm,
92-
initialCombinedSearchTerm,
93-
providerSlug,
94-
resetSearch,
95-
setLoading,
96-
]);
66+
}, [searchTerm, initialCombinedSearchTerm, providerSlug, resetSearch]);
9767

9868
const handleSearch = (e: React.ChangeEvent<HTMLInputElement>) => {
99-
const value = e.target.value;
100-
setSearchTerm(value);
69+
setSearchTerm(e.target.value);
10170
setLoading(true);
10271
};
10372

functions/api/fetch-apis.js

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ export async function onRequestGet({ request, env }) {
1313
);
1414
const page = Math.max(parseInt(url.searchParams.get("page") || "1"), 1);
1515
const search = url.searchParams.get("search")?.toLowerCase().trim();
16-
const category = url.searchParams.get("category")?.toLowerCase().trim();
17-
const tag = url.searchParams.get("tag")?.toLowerCase().trim();
18-
const status = url.searchParams.get("status")?.toLowerCase();
16+
1917
const sortBy = url.searchParams.get("sortBy") || "name";
2018
const sortOrder =
2119
url.searchParams.get("sortOrder")?.toLowerCase() === "desc"
@@ -38,28 +36,6 @@ export async function onRequestGet({ request, env }) {
3836
bindings.push(`%${search}%`, `%${search}%`, `%${search}%`);
3937
}
4038

41-
if (category) {
42-
conditions.push("a.categories LIKE ?");
43-
bindings.push(`%"${category}"%`);
44-
}
45-
46-
if (tag) {
47-
conditions.push("a.tags LIKE ?");
48-
bindings.push(`%"${tag}"%`);
49-
}
50-
51-
if (status === "new") {
52-
const monthAgo = new Date();
53-
monthAgo.setDate(monthAgo.getDate() - 30);
54-
conditions.push("a.added >= ?");
55-
bindings.push(monthAgo.toISOString().split("T")[0]);
56-
} else if (status === "updated") {
57-
const monthAgo = new Date();
58-
monthAgo.setDate(monthAgo.getDate() - 30);
59-
conditions.push("a.updated >= ?");
60-
bindings.push(monthAgo.toISOString().split("T")[0]);
61-
}
62-
6339
if (conditions.length > 0) {
6440
const whereClause = " WHERE " + conditions.join(" AND ");
6541
baseQuery += whereClause;
@@ -121,9 +97,6 @@ export async function onRequestGet({ request, env }) {
12197
},
12298
filters: {
12399
search: search || null,
124-
category: category || null,
125-
tag: tag || null,
126-
status: status || null,
127100
sortBy,
128101
sortOrder: sortOrder.toLowerCase(),
129102
},

hooks/useApiSearch.ts

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState, useEffect, useCallback } from "react";
1+
import { useState, useCallback } from "react";
22
import { ApiCardModel } from "@/models/ApiCardModel";
33
import { fetchApisInfinite } from "@/services/api";
44
import { cleanDescription } from "@/utils/textProcessing";
@@ -13,20 +13,15 @@ export function useApiSearch(initialSearchTerm: string, pageSize: number) {
1313
const [totalCount, setTotalCount] = useState(0);
1414

1515
const cleanApiData = useCallback((apis: ApiCardModel[]) => {
16-
return apis.map((card) => {
17-
const cleanedCard = { ...card };
18-
if (cleanedCard.cardDescription) {
19-
cleanedCard.cardDescription = cleanDescription(
20-
cleanedCard.cardDescription
21-
);
22-
}
23-
if (cleanedCard.markedDescription) {
24-
cleanedCard.markedDescription = cleanDescription(
25-
cleanedCard.markedDescription
26-
);
27-
}
28-
return cleanedCard;
29-
});
16+
return apis.map((card) => ({
17+
...card,
18+
cardDescription: card.cardDescription
19+
? cleanDescription(card.cardDescription)
20+
: card.cardDescription,
21+
markedDescription: card.markedDescription
22+
? cleanDescription(card.markedDescription)
23+
: card.markedDescription,
24+
}));
3025
}, []);
3126

3227
const loadMoreApis = useCallback(async () => {
@@ -45,9 +40,7 @@ export function useApiSearch(initialSearchTerm: string, pageSize: number) {
4540
setAllApiCards((prev) => [...prev, ...cleanedApis]);
4641
setCurrentPage((prev) => prev + 1);
4742
setHasMore(response.hasMore);
48-
if (response.totalCount !== undefined) {
49-
setTotalCount(response.totalCount);
50-
}
43+
setTotalCount(response.totalCount);
5144
} else {
5245
setHasMore(false);
5346
}
@@ -72,7 +65,7 @@ export function useApiSearch(initialSearchTerm: string, pageSize: number) {
7265
setAllApiCards(cleanedApis);
7366
setHasMore(response.hasMore);
7467
setCurrentPage(1);
75-
setTotalCount(response.totalCount || 0);
68+
setTotalCount(response.totalCount);
7669
} catch (error) {
7770
console.error("Error searching APIs:", error);
7871
setAllApiCards([]);
@@ -85,25 +78,15 @@ export function useApiSearch(initialSearchTerm: string, pageSize: number) {
8578
[pageSize, cleanApiData]
8679
);
8780

88-
const searchApis = useCallback(
89-
async (term: string) => {
90-
await resetSearch(term);
91-
},
92-
[resetSearch]
93-
);
94-
9581
return {
9682
searchTerm,
9783
setSearchTerm,
9884
allApiCards,
99-
setAllApiCards,
10085
loading,
10186
setLoading,
10287
loadingMore,
10388
hasMore,
104-
currentPage,
10589
loadMoreApis,
106-
searchApis,
10790
resetSearch,
10891
totalCount,
10992
};

0 commit comments

Comments
 (0)