Skip to content

Commit

Permalink
refactor: removed useCallback
Browse files Browse the repository at this point in the history
Relates #256
  • Loading branch information
nichgalzin committed Jun 27, 2024
1 parent c15ce5e commit 1e1b8bb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
6 changes: 3 additions & 3 deletions app/(dashboard)/search/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import searchItemsByName from '@/supabase/models/searchItemsByName';
import selectItemsByCreatedAt from '@/supabase/models/selectingItems/selectItemsByCreatedAt';
import { SearchParamsType } from '@/types/searchPageTypes';
import { PartialItem } from '@/types/supabaseTypes';
import { useCallback, useEffect, useState } from 'react';
import { useEffect, useState } from 'react';

const initialSearchParams = {
query: '',
Expand All @@ -21,7 +21,7 @@ export default function SearchItemPage() {
useState<SearchParamsType>(initialSearchParams);
const [searchResults, setSearchResults] = useState<PartialItem[]>([]);

const fetchSearchResults = useCallback(async () => {
const fetchSearchResults = async () => {
let data: PartialItem[] = [];
switch (true) {
// case !!searchParams.query &&
Expand Down Expand Up @@ -58,7 +58,7 @@ export default function SearchItemPage() {
break;
}
setSearchResults(data);
}, [searchParams]);
};

useEffect(() => {
fetchSearchResults();
Expand Down
28 changes: 12 additions & 16 deletions components/search/ItemDisplayContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,18 @@ const ItemDisplayContainer: React.FC<ItemDisplayContainerProps> = ({
</span>
</h2>
<div className='mt-10 flex flex-col items-center gap-5'>
{searchResults.length > 0 ? (
searchResults.map((result) => (
<ItemCard
key={result.id}
imageSrc={result.imageSrc}
item_name={result.item_name}
condition={result.condition}
item_type={result.item_type}
postcode={result.postcode}
postable={result.postable}
itemId={result.id}
/>
))
) : (
<p className='text-center'>No results found.</p>
)}
{searchResults.map((result) => (
<ItemCard
key={result.id}
imageSrc={result.imageSrc}
item_name={result.item_name}
condition={result.condition}
item_type={result.item_type}
postcode={result.postcode}
postable={result.postable}
itemId={result.id}
/>
))}
</div>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion supabase/models/selectingItems/selectItemsByCreatedAt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const selectItemsByCreatedAt = async (
let query = supabase
.from('items')
.select('*')
.order('created_at', { ascending: false })
.order('created_at')
.limit(Number(limit));

if (cursor) {
Expand Down

0 comments on commit 1e1b8bb

Please sign in to comment.