mirror of
https://github.com/lucasrcsantana/story-generator.git
synced 2025-12-16 21:37:51 +00:00
fix: Corrigindo visualização de imagens das histórias
Some checks are pending
Docker Build and Push / build (push) Waiting to run
Some checks are pending
Docker Build and Push / build (push) Waiting to run
This commit is contained in:
parent
9e3f7a7c31
commit
69dbb5fa48
@ -14,7 +14,6 @@ interface DashboardMetrics {
|
||||
export function StudentDashboardPage() {
|
||||
const navigate = useNavigate();
|
||||
const [student, setStudent] = React.useState<Student | null>(null);
|
||||
const [stories, setStories] = React.useState<Story[]>([]);
|
||||
const [metrics, setMetrics] = React.useState<DashboardMetrics>({
|
||||
totalStories: 0,
|
||||
averageReadingFluency: 0,
|
||||
@ -54,18 +53,16 @@ export function StudentDashboardPage() {
|
||||
.limit(6);
|
||||
|
||||
if (storiesError) throw storiesError;
|
||||
setStories(storiesData || []);
|
||||
|
||||
// Calcular métricas
|
||||
// Em produção: Implementar cálculos reais baseados nos dados
|
||||
// Calcular métricas (exemplo simplificado)
|
||||
setMetrics({
|
||||
totalStories: storiesData?.length || 0,
|
||||
averageReadingFluency: 85, // Exemplo
|
||||
totalReadingTime: 120, // Exemplo: 120 minutos
|
||||
currentLevel: 3 // Exemplo
|
||||
averageReadingFluency: 85,
|
||||
totalReadingTime: 120,
|
||||
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
|
||||
.from('stories')
|
||||
.select(`
|
||||
@ -80,7 +77,26 @@ export function StudentDashboardPage() {
|
||||
.limit(6);
|
||||
|
||||
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) {
|
||||
console.error('Erro ao carregar dashboard:', err);
|
||||
|
||||
@ -42,7 +42,7 @@ export function StudentStoriesPage() {
|
||||
if (error) throw error;
|
||||
|
||||
// Aplicar ordenação
|
||||
const sortedData = (data || []).sort((a, b) => {
|
||||
let sortedData = (data || []).sort((a, b) => {
|
||||
switch (sortBy) {
|
||||
case 'oldest':
|
||||
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);
|
||||
} catch (err) {
|
||||
console.error('Erro ao buscar histórias:', err);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user