У меня проблема. Когда я обновляю или удаляю заметку, изменения не отражаются в разделе «Мои заметки». Я подозреваю, что это связано с тем, что сигналы неправильно реализованы в файле obtenerFormulario.tsx.
Ссылка на приложение на github:
https://github.com/NachoCano123/AppNotas/tree/main
Ссылка на приложение:
https://appnotas-rzjc42pkh960.nachocano123.deno.net/
Будем очень благодарны за любую помощь.
//routes/enviar_nota.tsx
import { Handlers, PageProps } from "$fresh/server.ts";
import { Nota, notas } from "../Types.ts";
import Notas from "../components/Notas.tsx";
import { Signal, signal } from "@preact/signals";
export const handler: Handlers = {
GET(_req, ctx) {
const notesSignal = signal(notas);
return ctx.render({ notes: notesSignal });
},
};
export default function Page(props: PageProps) {
return ;
}
islands/NotasInteractivas.tsx
import { Signal } from "@preact/signals";
import { useState } from "preact/hooks";
import { Nota } from "../Types.ts";
type Props = {
notes: Signal;
};
export default function NotasInteractivas({ notes }: Props) {
const [editingId, setEditingId] = useState(null);
const [editForm, setEditForm] = useState({
title: "",
content: "",
category: ""
});
const BorrarNota = (id: number) => {
notes.value = notes.value.filter(nota => nota.id !== id);
console.log("Nota borrada con ID:", id);
};
const IniciarEdicion = (nota: Nota) => {
setEditingId(nota.id);
setEditForm({
title: nota.title,
content: nota.content,
category: nota.category
});
};
const GuardarEdicion = () => {
if (editingId === null) return;
notes.value = notes.value.map(nota => {
if (nota.id === editingId) {
return {...nota, ...editForm};
}
else {
return nota;
}
});
CancelarEdicion();
console.log("Nota editada con ID:", editingId);
};
const CancelarEdicion = () => {
setEditingId(null);
setEditForm({ title: "", content: "", category: "" });
};
const ManejarCambio = (field: string, value: string) => {
setEditForm(prev => ({ ...prev, [field]: value }));
};
return (
{notes.value.map((nota) => (
{editingId === nota.id ? (
ManejarCambio("title", (e.target as HTMLInputElement).value)}
className="edit-input"
placeholder="Título"
/>
ManejarCambio("category", (e.target as HTMLInputElement).value)}
className="edit-input"
placeholder="Categoría"
/>
ManejarCambio("content", (e.target as HTMLTextAreaElement).value)}
className="edit-textarea"
placeholder="Contenido"
/>
Guardar
Cancelar
) : (
{nota.title}
{nota.category}
{nota.content}
IniciarEdicion(nota)}
>
Editar
BorrarNota(nota.id)}
>
Borrar
)}
))}
);
}
Подробнее здесь: https://stackoverflow.com/questions/798 ... -correctly
В моем приложении заметки обновляются неправильно. ⇐ Javascript
Форум по Javascript
-
Anonymous
1764772222
Anonymous
У меня проблема. Когда я обновляю или удаляю заметку, изменения не отражаются в разделе «Мои заметки». Я подозреваю, что это связано с тем, что сигналы неправильно реализованы в файле obtenerFormulario.tsx.
Ссылка на приложение на github:
https://github.com/NachoCano123/AppNotas/tree/main
Ссылка на приложение:
https://appnotas-rzjc42pkh960.nachocano123.deno.net/
Будем очень благодарны за любую помощь.
//routes/enviar_nota.tsx
import { Handlers, PageProps } from "$fresh/server.ts";
import { Nota, notas } from "../Types.ts";
import Notas from "../components/Notas.tsx";
import { Signal, signal } from "@preact/signals";
export const handler: Handlers = {
GET(_req, ctx) {
const notesSignal = signal(notas);
return ctx.render({ notes: notesSignal });
},
};
export default function Page(props: PageProps) {
return ;
}
islands/NotasInteractivas.tsx
import { Signal } from "@preact/signals";
import { useState } from "preact/hooks";
import { Nota } from "../Types.ts";
type Props = {
notes: Signal;
};
export default function NotasInteractivas({ notes }: Props) {
const [editingId, setEditingId] = useState(null);
const [editForm, setEditForm] = useState({
title: "",
content: "",
category: ""
});
const BorrarNota = (id: number) => {
notes.value = notes.value.filter(nota => nota.id !== id);
console.log("Nota borrada con ID:", id);
};
const IniciarEdicion = (nota: Nota) => {
setEditingId(nota.id);
setEditForm({
title: nota.title,
content: nota.content,
category: nota.category
});
};
const GuardarEdicion = () => {
if (editingId === null) return;
notes.value = notes.value.map(nota => {
if (nota.id === editingId) {
return {...nota, ...editForm};
}
else {
return nota;
}
});
CancelarEdicion();
console.log("Nota editada con ID:", editingId);
};
const CancelarEdicion = () => {
setEditingId(null);
setEditForm({ title: "", content: "", category: "" });
};
const ManejarCambio = (field: string, value: string) => {
setEditForm(prev => ({ ...prev, [field]: value }));
};
return (
{notes.value.map((nota) => (
{editingId === nota.id ? (
ManejarCambio("title", (e.target as HTMLInputElement).value)}
className="edit-input"
placeholder="Título"
/>
ManejarCambio("category", (e.target as HTMLInputElement).value)}
className="edit-input"
placeholder="Categoría"
/>
ManejarCambio("content", (e.target as HTMLTextAreaElement).value)}
className="edit-textarea"
placeholder="Contenido"
/>
Guardar
Cancelar
) : (
{nota.title}
{nota.category}
{nota.content}
IniciarEdicion(nota)}
>
Editar
BorrarNota(nota.id)}
>
Borrar
)}
))}
);
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79836995/in-my-app-the-notes-are-not-updating-correctly[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия