Skip to content

Commit

Permalink
fixed bug that caused multiple requests
Browse files Browse the repository at this point in the history
  • Loading branch information
chuma-beep committed Oct 22, 2024
1 parent 3cf3118 commit 10dd8e4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/postlist/PostList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ interface Post {
avatar_url: string | null;
};
}
const supabase = createClient();

export default function PostList() {
const supabase = createClient();
const [posts, setPosts] = useState<Post[]>([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
Expand Down Expand Up @@ -115,7 +115,7 @@ export default function PostList() {
(node: HTMLElement | null) => {
if (loading) return;
if (observer.current) observer.current.disconnect();

observer.current = new IntersectionObserver((entries) => {
if (entries[0].isIntersecting && hasMore) {
setPage((prevPage) => prevPage + 1);
Expand Down
2 changes: 2 additions & 0 deletions app/tags/[tag]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export default function TagsPostsPage() {
[loading, hasMore]
);



useEffect(() => {
const fetchData = async () => {
try {
Expand Down
6 changes: 3 additions & 3 deletions components/BlogSideBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ export function ComponentsBlogSidebar() {
const [loading, setLoading] = useState(true); // State for loading
const [error, setError] = useState<string | null>(null); // State for error

// Fetch Tags from the database
// Fetch Tags from the database
useEffect(() => {
const fectchTags = async () => {
try{
const { data, error } = await supabase
.from('tags').select('name');
.from('tags').select('*,name');
if(error) throw error;
setTags(data.map((tag: { name: string}) => tag.name));
}
Expand All @@ -43,7 +43,7 @@ export function ComponentsBlogSidebar() {
}
}
fectchTags();
})
},[])



Expand Down

0 comments on commit 10dd8e4

Please sign in to comment.