feat: implement market page with QueryProvider and dynamic listings
- wrap root layout with QueryProvider for React Query - replace market UnderConstruction placeholder with MarketClient and real data fetching - implement search, pagination, and sort via search params using getActiveListings - add necessary client components and queries - update dependencies (e.g., prisma, pkg-types)
This commit is contained in:
1 parent
55eebde0ba
commit
ab37b477df
106 files changed
+15261
-301
No files matched your search
@@ -0,0 +1,58 @@
|
||||
"use client";
|
||||
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
export interface SessionUser {
|
||||
userId: number;
|
||||
username: string;
|
||||
email: string;
|
||||
}
|
||||
|
||||
interface SessionResponse {
|
||||
success: boolean;
|
||||
authenticated: boolean;
|
||||
user?: SessionUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook para gerenciar sessão do usuário com React Query
|
||||
* Atualiza automaticamente a cada 30 segundos
|
||||
*/
|
||||
export function useSession() {
|
||||
const { data, isLoading, refetch } = useQuery<SessionResponse>({
|
||||
queryKey: ["session"],
|
||||
queryFn: async () => {
|
||||
const response = await fetch("/api/auth/session", {
|
||||
method: "GET",
|
||||
credentials: "include",
|
||||
});
|
||||
return response.json();
|
||||
},
|
||||
staleTime: 1000 * 30, // 30 segundos
|
||||
refetchInterval: 1000 * 30, // Refetch a cada 30 segundos
|
||||
refetchOnWindowFocus: true,
|
||||
refetchOnReconnect: true,
|
||||
});
|
||||
|
||||
const logout = async () => {
|
||||
try {
|
||||
await fetch("/api/auth/session", {
|
||||
method: "DELETE",
|
||||
credentials: "include",
|
||||
});
|
||||
// Invalidar cache e recarregar
|
||||
window.location.href = "/";
|
||||
} catch (error) {
|
||||
console.error("Erro ao fazer logout:", error);
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
user: data?.user || null,
|
||||
isLoading,
|
||||
isAuthenticated: data?.authenticated || false,
|
||||
logout,
|
||||
refreshSession: refetch,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user