Skip to content

Commit f95709d

Browse files
committed
better handle client errors
1 parent 1b0fb29 commit f95709d

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

client/src/NoteComponents/media/media.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async function getCompressed(uncompressed, type) {
4040
function Media({ setNoteMedia, mediaList = [], style, className, disabled, noteId, sizeData }) {
4141
const { addMedia, removeMedia, getMediaById, getNoteById } = useContext(NotesContext)
4242

43-
const limited = getNoteById(noteId).media.length >= 1
43+
const limited = noteId ? getNoteById(noteId).media.length >= 1 : false
4444

4545
/**хук состояния формы */
4646
const [showForm, setShowForm] = React.useState(false)

client/src/Pages/NotesPage.js

+19-10
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ function NotesPage() {
3434

3535
/** очистка ошибок хука запросов и запись ошибки в сообщение*/
3636
React.useEffect(() => {
37-
if (error) setMessage(error)
37+
if (error) {
38+
setMessage(error)
39+
unsetEditNoteId()
40+
}
3841
/**Выйти в случае неавторизации */
3942
if (error === 'Нет авторизации') auth.logout()
4043
clearError()
@@ -346,23 +349,29 @@ function NotesPage() {
346349
{/**Компонент добавления карточки и модальное окно редактирования */}
347350
<AddNote />
348351
<ModalNoteEdit />
352+
{/**Вывод ошибок */}
353+
{message &&
354+
/**Ошибка загрузки данных */
355+
<div className="container text-center">
356+
<p className="m-3 p-3 h5 text-muted">
357+
{!(notesArr && notesArr.length) && "Data not loaded"}
358+
<br />
359+
{message}
360+
</p>
361+
</div>
362+
}
349363
{/**Вариативное отображение контента (заметок) */}
350-
{notesArr && notesArr.length ? (
364+
{notesArr && notesArr.length ?
351365
/**Список карточек */
352366
<NoteList notes={notesArr} />
353-
) : (loading) ? null : !message ? (
367+
: !loading && !message &&
354368
/**Сообщение об отсутствии карточек */
355369
<div className="container text-center">
356370
<p className="m-3 p-3 h5 text-muted">No Notes. You can add a new one!</p>
357371
</div>
358-
) : (
359-
/**Ошибка загрузки данных */
360-
<div className="container text-center">
361-
<p className="m-3 p-3 h5 text-muted">Data not loaded<br />{message}</p>
362-
</div>
363-
)}
372+
}
364373
{/**Колесико загрузки */}
365-
{(loading && !notesArr && editNoteId === null) &&
374+
{loading && !notesArr && editNoteId === null &&
366375
<div className="container display-4 text-center p-3" >
367376
<Loader />
368377
</div>

0 commit comments

Comments
 (0)