fix: Corrigindo visualização de imagens das histórias
Some checks are pending
Docker Build and Push / build (push) Waiting to run

This commit is contained in:
Lucas Santana 2025-02-04 15:25:05 -03:00
parent 9e3f7a7c31
commit 69dbb5fa48
2 changed files with 32 additions and 10 deletions

View File

@ -14,7 +14,6 @@ interface DashboardMetrics {
export function StudentDashboardPage() { export function StudentDashboardPage() {
const navigate = useNavigate(); const navigate = useNavigate();
const [student, setStudent] = React.useState<Student | null>(null); const [student, setStudent] = React.useState<Student | null>(null);
const [stories, setStories] = React.useState<Story[]>([]);
const [metrics, setMetrics] = React.useState<DashboardMetrics>({ const [metrics, setMetrics] = React.useState<DashboardMetrics>({
totalStories: 0, totalStories: 0,
averageReadingFluency: 0, averageReadingFluency: 0,
@ -54,18 +53,16 @@ export function StudentDashboardPage() {
.limit(6); .limit(6);
if (storiesError) throw storiesError; if (storiesError) throw storiesError;
setStories(storiesData || []);
// Calcular métricas // Calcular métricas (exemplo simplificado)
// Em produção: Implementar cálculos reais baseados nos dados
setMetrics({ setMetrics({
totalStories: storiesData?.length || 0, totalStories: storiesData?.length || 0,
averageReadingFluency: 85, // Exemplo averageReadingFluency: 85,
totalReadingTime: 120, // Exemplo: 120 minutos totalReadingTime: 120,
currentLevel: 3 // Exemplo currentLevel: 3
}); });
// Buscar histórias recentes com a primeira página como capa // Buscar histórias recentes com a capa definida
const { data, error } = await supabase const { data, error } = await supabase
.from('stories') .from('stories')
.select(` .select(`
@ -80,7 +77,26 @@ export function StudentDashboardPage() {
.limit(6); .limit(6);
if (error) throw error; if (error) throw error;
setRecentStories(data || []);
// Transformar os dados para definir a propriedade 'cover' de forma robusta
const mappedData = (data || []).map(story => {
let coverObj = null;
if (story.cover) {
coverObj = Array.isArray(story.cover) ? story.cover[0] : story.cover;
} else if (story.pages && story.pages.length > 0) {
coverObj = story.pages[0];
}
if (coverObj && typeof coverObj === 'object' && coverObj.image_url) {
return { ...story, cover: coverObj };
} else if (coverObj && typeof coverObj === 'string') {
return { ...story, cover: { image_url: coverObj } };
}
return { ...story, cover: null };
});
setRecentStories(mappedData);
} catch (err) { } catch (err) {
console.error('Erro ao carregar dashboard:', err); console.error('Erro ao carregar dashboard:', err);

View File

@ -42,7 +42,7 @@ export function StudentStoriesPage() {
if (error) throw error; if (error) throw error;
// Aplicar ordenação // Aplicar ordenação
const sortedData = (data || []).sort((a, b) => { let sortedData = (data || []).sort((a, b) => {
switch (sortBy) { switch (sortBy) {
case 'oldest': case 'oldest':
return new Date(a.created_at).getTime() - new Date(b.created_at).getTime(); return new Date(a.created_at).getTime() - new Date(b.created_at).getTime();
@ -55,6 +55,12 @@ export function StudentStoriesPage() {
} }
}); });
// Adicionar a propriedade 'cover', usando a imagem da primeira página
sortedData = sortedData.map(story => ({
...story,
cover: story.pages && story.pages.length > 0 ? story.pages[0] : null
}));
setStories(sortedData); setStories(sortedData);
} catch (err) { } catch (err) {
console.error('Erro ao buscar histórias:', err); console.error('Erro ao buscar histórias:', err);