Skip to content

Commit

Permalink
better handle client errors
Browse files Browse the repository at this point in the history
  • Loading branch information
maxchistt committed Jun 20, 2021
1 parent 1b0fb29 commit f95709d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion client/src/NoteComponents/media/media.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async function getCompressed(uncompressed, type) {
function Media({ setNoteMedia, mediaList = [], style, className, disabled, noteId, sizeData }) {
const { addMedia, removeMedia, getMediaById, getNoteById } = useContext(NotesContext)

const limited = getNoteById(noteId).media.length >= 1
const limited = noteId ? getNoteById(noteId).media.length >= 1 : false

/**хук состояния формы */
const [showForm, setShowForm] = React.useState(false)
Expand Down
29 changes: 19 additions & 10 deletions client/src/Pages/NotesPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ function NotesPage() {

/** очистка ошибок хука запросов и запись ошибки в сообщение*/
React.useEffect(() => {
if (error) setMessage(error)
if (error) {
setMessage(error)
unsetEditNoteId()
}
/**Выйти в случае неавторизации */
if (error === 'Нет авторизации') auth.logout()
clearError()
Expand Down Expand Up @@ -346,23 +349,29 @@ function NotesPage() {
{/**Компонент добавления карточки и модальное окно редактирования */}
<AddNote />
<ModalNoteEdit />
{/**Вывод ошибок */}
{message &&
/**Ошибка загрузки данных */
<div className="container text-center">
<p className="m-3 p-3 h5 text-muted">
{!(notesArr && notesArr.length) && "Data not loaded"}
<br />
{message}
</p>
</div>
}
{/**Вариативное отображение контента (заметок) */}
{notesArr && notesArr.length ? (
{notesArr && notesArr.length ?
/**Список карточек */
<NoteList notes={notesArr} />
) : (loading) ? null : !message ? (
: !loading && !message &&
/**Сообщение об отсутствии карточек */
<div className="container text-center">
<p className="m-3 p-3 h5 text-muted">No Notes. You can add a new one!</p>
</div>
) : (
/**Ошибка загрузки данных */
<div className="container text-center">
<p className="m-3 p-3 h5 text-muted">Data not loaded<br />{message}</p>
</div>
)}
}
{/**Колесико загрузки */}
{(loading && !notesArr && editNoteId === null) &&
{loading && !notesArr && editNoteId === null &&
<div className="container display-4 text-center p-3" >
<Loader />
</div>
Expand Down

0 comments on commit f95709d

Please sign in to comment.