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:
Evandro Fonseca Junior committed 2025-11-05 01:58:03 -03:00
1 parent 55eebde0ba
commit ab37b477df
106 files changed
+15261 -301

No files matched your search

+2 -102
View File
@@ -1,105 +1,5 @@
"use client";
import { useState, useEffect, useCallback } from "react";
export interface SessionUser {
userId: number;
username: string;
email: string;
}
interface SessionState {
user: SessionUser | null;
isLoading: boolean;
isAuthenticated: boolean;
}
/**
* Hook para gerenciar sessão do usuário
*/
export function useSession() {
const [session, setSession] = useState<SessionState>({
user: null,
isLoading: true,
isAuthenticated: false,
});
/**
* Verifica a sessão atual
*/
const checkSession = useCallback(async () => {
try {
const response = await fetch("/api/auth/session", {
method: "GET",
credentials: "include",
});
const data = await response.json();
if (data.success && data.authenticated) {
setSession({
user: data.user,
isLoading: false,
isAuthenticated: true,
});
} else {
setSession({
user: null,
isLoading: false,
isAuthenticated: false,
});
}
} catch (error) {
console.error("Erro ao verificar sessão:", error);
setSession({
user: null,
isLoading: false,
isAuthenticated: false,
});
}
}, []);
/**
* Encerra a sessão
*/
const logout = useCallback(async () => {
try {
await fetch("/api/auth/session", {
method: "DELETE",
credentials: "include",
});
setSession({
user: null,
isLoading: false,
isAuthenticated: false,
});
// Recarregar página para limpar estado
window.location.href = "/";
} catch (error) {
console.error("Erro ao fazer logout:", error);
}
}, []);
/**
* Atualiza a sessão após login
*/
const refreshSession = useCallback(async () => {
await checkSession();
}, [checkSession]);
// Verificar sessão ao montar componente
useEffect(() => {
checkSession();
}, [checkSession]);
return {
user: session.user,
isLoading: session.isLoading,
isAuthenticated: session.isAuthenticated,
logout,
refreshSession,
};
}
// Re-exportar o hook que usa React Query
export { useSession, type SessionUser } from "./use-session-query";