Cambios a las 3 bases Model mapper repo para que funcionen a partir de las clases heredando todos los metodos comunes
This commit is contained in:
@@ -36,6 +36,9 @@ export function Biblioteca() {
|
||||
const [tituloNota, setTituloNota] = useState('');
|
||||
const [contenidoNota, setContenidoNota] = useState('');
|
||||
const [loadingNotas, setLoadingNotas] = useState(false);
|
||||
const [notaEnEdicion, setNotaEnEdicion] = useState<Nota | null>(null);
|
||||
const [modalEditarAbierto, setModalEditarAbierto] = useState(false);
|
||||
|
||||
|
||||
const fetchBibliotecas = async () => {
|
||||
try {
|
||||
@@ -93,12 +96,54 @@ export function Biblioteca() {
|
||||
fetchBibliotecas();
|
||||
}, []);
|
||||
|
||||
// Eliminar nota
|
||||
const eliminarNota = async (notaId: string) => {
|
||||
if (!bibliotecaSeleccionada) return;
|
||||
try {
|
||||
await axios.delete(`/api/v1/text_manager/nota/${bibliotecaSeleccionada.id}/${notaId}`);
|
||||
await fetchBibliotecas();
|
||||
} catch (error) {
|
||||
console.error("Error al eliminar nota:", error);
|
||||
}
|
||||
};
|
||||
|
||||
// Editar nota
|
||||
const abrirModalEditar = (nota: Nota) => {
|
||||
setNotaEnEdicion(nota);
|
||||
setModalEditarAbierto(true);
|
||||
};
|
||||
|
||||
// Guardar cambios de edición
|
||||
const guardarEdicionNota = async () => {
|
||||
if (!notaEnEdicion || !bibliotecaSeleccionada) return;
|
||||
try {
|
||||
await axios.put(`/api/v1/text_manager/nota/${bibliotecaSeleccionada.id}/${notaEnEdicion.id}`, {
|
||||
titulo: notaEnEdicion.titulo,
|
||||
texto: notaEnEdicion.texto,
|
||||
tags: [],
|
||||
conexiones: [],
|
||||
resumen: ""
|
||||
});
|
||||
setModalEditarAbierto(false);
|
||||
setNotaEnEdicion(null);
|
||||
await fetchBibliotecas();
|
||||
} catch (error) {
|
||||
console.error("Error al actualizar nota:", error);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<AppShellWithMenu>
|
||||
<Box display="flex" h="100%">
|
||||
<Box w={240} p="md">
|
||||
<ScrollArea h="100%">
|
||||
<Stack>
|
||||
<Button color="teal" onClick={fetchBibliotecas}>
|
||||
🔄 Recuperar bibliotecas
|
||||
</Button>
|
||||
|
||||
{bibliotecas.map((biblio) => (
|
||||
<Button
|
||||
key={biblio.id}
|
||||
@@ -120,9 +165,6 @@ export function Biblioteca() {
|
||||
<Stack>
|
||||
<Title order={2}>{bibliotecaSeleccionada.nombre}</Title>
|
||||
<Group>
|
||||
<Button color="teal" onClick={fetchBibliotecas}>
|
||||
🔄 Recuperar bibliotecas
|
||||
</Button>
|
||||
<Button onClick={() => setModalAbierto(true)}>Agregar nota</Button>
|
||||
</Group>
|
||||
<Group>
|
||||
@@ -130,10 +172,45 @@ export function Biblioteca() {
|
||||
<Loader />
|
||||
) : (
|
||||
bibliotecaSeleccionada.notas.map((nota) => (
|
||||
<Card key={nota.id} shadow="sm" padding="lg" radius="md" withBorder style={{ width: 300 }}>
|
||||
<Title order={4}>{nota.titulo}</Title>
|
||||
<Text>{nota.texto}</Text>
|
||||
</Card>
|
||||
|
||||
// Cards de notas
|
||||
|
||||
<Card
|
||||
key={nota.id}
|
||||
shadow="sm"
|
||||
padding="lg"
|
||||
radius="md"
|
||||
withBorder
|
||||
style={{ width: 300, position: 'relative' }}
|
||||
>
|
||||
{/* Botones en esquina superior derecha */}
|
||||
<Box style={{ position: 'absolute', top: 8, right: 8, display: 'flex', gap: 4, zIndex: 1 }}>
|
||||
<Button
|
||||
size="xs"
|
||||
color="blue"
|
||||
variant="light"
|
||||
p={4}
|
||||
onClick={() => abrirModalEditar(nota)}
|
||||
>
|
||||
✏️
|
||||
</Button>
|
||||
<Button
|
||||
size="xs"
|
||||
color="red"
|
||||
variant="light"
|
||||
p={4}
|
||||
onClick={() => eliminarNota(nota.id)}
|
||||
>
|
||||
🗑️
|
||||
</Button>
|
||||
</Box>
|
||||
|
||||
<Title order={4} style={{ marginBottom: 10 }}>{nota.titulo}</Title>
|
||||
<Text>{nota.texto}</Text>
|
||||
</Card>
|
||||
|
||||
// Fin de notas en cards
|
||||
|
||||
))
|
||||
)}
|
||||
</Group>
|
||||
@@ -149,6 +226,7 @@ export function Biblioteca() {
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
{/* Modal para agregar */}
|
||||
<Modal opened={modalAbierto} onClose={() => setModalAbierto(false)} title="Agregar nueva nota">
|
||||
<Stack>
|
||||
<TextInput
|
||||
@@ -164,6 +242,28 @@ export function Biblioteca() {
|
||||
<Button onClick={agregarNota}>Guardar</Button>
|
||||
</Stack>
|
||||
</Modal>
|
||||
|
||||
{/* Modal para editar */}
|
||||
<Modal opened={modalEditarAbierto} onClose={() => setModalEditarAbierto(false)} title="Editar nota">
|
||||
<Stack>
|
||||
<TextInput
|
||||
label="Título"
|
||||
value={notaEnEdicion?.titulo || ""}
|
||||
onChange={(e) =>
|
||||
setNotaEnEdicion((prev) => (prev ? { ...prev, titulo: e.currentTarget.value } : null))
|
||||
}
|
||||
/>
|
||||
<TextInput
|
||||
label="Contenido"
|
||||
value={notaEnEdicion?.texto || ""}
|
||||
onChange={(e) =>
|
||||
setNotaEnEdicion((prev) => (prev ? { ...prev, texto: e.currentTarget.value } : null))
|
||||
}
|
||||
/>
|
||||
<Button onClick={guardarEdicionNota}>Guardar cambios</Button>
|
||||
</Stack>
|
||||
</Modal>
|
||||
</AppShellWithMenu>
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user