From 5952d83ec86ee2131cd314a51a5a80e89c91a98e Mon Sep 17 00:00:00 2001 From: Lucas Santana Date: Fri, 20 Dec 2024 11:11:28 -0300 Subject: [PATCH] =?UTF-8?q?feat:=20implementa=20p=C3=A1ginas=20do=20dashbo?= =?UTF-8?q?ard=20do=20aluno?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Adiciona página de listagem de histórias com filtros e ordenação - Cria formulário de criação de novas histórias com temas - Implementa visualizador de história com navegação entre páginas - Integra gravador de áudio para leitura - Adiciona funcionalidade de compartilhamento - Implementa estados de loading e tratamento de erros --- .../student-dashboard/CreateStoryPage.tsx | 185 +++++++++++++ src/pages/student-dashboard/StoryPage.tsx | 165 +++++++++++ .../StudentDashboardLayout.tsx | 142 ++++++++++ .../StudentDashboardPage.tsx | 261 ++++++++++++++++++ .../student-dashboard/StudentStoriesPage.tsx | 227 +++++++++++++++ src/routes.tsx | 32 +++ 6 files changed, 1012 insertions(+) create mode 100644 src/pages/student-dashboard/CreateStoryPage.tsx create mode 100644 src/pages/student-dashboard/StoryPage.tsx create mode 100644 src/pages/student-dashboard/StudentDashboardLayout.tsx create mode 100644 src/pages/student-dashboard/StudentDashboardPage.tsx create mode 100644 src/pages/student-dashboard/StudentStoriesPage.tsx diff --git a/src/pages/student-dashboard/CreateStoryPage.tsx b/src/pages/student-dashboard/CreateStoryPage.tsx new file mode 100644 index 0000000..b536305 --- /dev/null +++ b/src/pages/student-dashboard/CreateStoryPage.tsx @@ -0,0 +1,185 @@ +import React from 'react'; +import { ArrowLeft, Sparkles, Send } from 'lucide-react'; +import { useNavigate } from 'react-router-dom'; +import { supabase } from '../../lib/supabase'; + +interface StoryForm { + title: string; + theme: string; + prompt: string; +} + +export function CreateStoryPage() { + const navigate = useNavigate(); + const [formData, setFormData] = React.useState({ + title: '', + theme: '', + prompt: '' + }); + const [generating, setGenerating] = React.useState(false); + const [error, setError] = React.useState(null); + + const themes = [ + { id: 'nature', name: 'Natureza e Meio Ambiente' }, + { id: 'culture', name: 'Cultura Brasileira' }, + { id: 'science', name: 'Ciência e Descobertas' }, + { id: 'adventure', name: 'Aventura e Exploração' }, + { id: 'friendship', name: 'Amizade e Cooperação' } + ]; + + const handleChange = (e: React.ChangeEvent) => { + const { name, value } = e.target; + setFormData(prev => ({ ...prev, [name]: value })); + }; + + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); + setGenerating(true); + setError(null); + + try { + const { data: { session } } = await supabase.auth.getSession(); + if (!session?.user?.id) throw new Error('Usuário não autenticado'); + + // Em produção: Integrar com API de IA para gerar história + const generatedStory = { + title: formData.title, + content: { + pages: [ + { + text: "Era uma vez...", + image: "https://images.unsplash.com/photo-1472162072942-cd5147eb3902" + } + ] + }, + theme: formData.theme, + status: 'draft' + }; + + const { error: saveError } = await supabase + .from('stories') + .insert({ + student_id: session.user.id, + title: generatedStory.title, + theme: generatedStory.theme, + content: generatedStory.content, + status: generatedStory.status, + created_at: new Date().toISOString(), + updated_at: new Date().toISOString() + }); + + if (saveError) throw saveError; + navigate('/aluno/historias'); + + } catch (err) { + console.error('Erro ao criar história:', err); + setError('Não foi possível criar sua história. Tente novamente.'); + } finally { + setGenerating(false); + } + }; + + return ( +
+ + +
+

Criar Nova História

+ + {error && ( +
+ {error} +
+ )} + +
+
+ + +
+ +
+ + +
+ +
+ +