.then(([group, scores]) => { this.setState({ loadingAllSettings: true, group: { ...group, name: updatedFields.name === undefined ? group.name : updatedFields.name, } }); Toast.push('Настройки группы сохранены'); })
handler: () => { restoreComment(); this.setState({ threads }); if (forInstructors && !comment.parentCommentId) { handleInstructorsCommentCount("add"); } Toast.push("Комментарий восстановлен"); this.props.commentsApi.updateComment(comment.id); }
handleDeleteComment = (comment) => { const threads = JSON.parse(JSON.stringify(this.state.threads)); const {forInstructors, handleInstructorsCommentCount} = this.props; this.setState({ animation: true, }); const restoreComment = this.deleteComment(comment.id, threads); this.setState({threads}); try { this.props.commentsApi.deleteComment(comment.id); if (forInstructors && !comment.parentCommentId) { handleInstructorsCommentCount("delete"); } Toast.push("Комментарий удалён", { label: "Восстановить", handler: () => { restoreComment(); this.setState({ threads }); if (forInstructors && !comment.parentCommentId) { handleInstructorsCommentCount("add"); } Toast.push("Комментарий восстановлен"); this.props.commentsApi.updateComment(comment.id); } }) } catch (e) { Toast.push("Комментарий не удалён. Произошла ошибка, попробуйте снова"); this.setState({threads}); console.error(e); } };
render() { if (this.state.error) { /* render fallback UI */ return ( <React.Fragment> <div className={styles["error"]} onClick={() => Raven.lastEventId() && Raven.showReportDialog()}> <p>We're sorry — something's gone wrong.</p> <p>Our team has been notified, but click here fill out a report.</p> </div> {Toast.push('Произошла ошибка. Попробуйте перезагрузить страницу.')} </React.Fragment> ); } /* when there's not an error, render children untouched */ return this.props.children; }
handleAddReplyComment = async (commentId, text) => { const {commentsApi, courseId, slideId, forInstructors} = this.props; this.setState({ animation: true, reply: { commentId: commentId, sending: true, } }); try { const newReply = await commentsApi.addComment(courseId, slideId, text, commentId, forInstructors); const index = this.state.threads.findIndex(comment => comment.id === commentId); const comment = this.state.threads[index]; const newReplies = comment.replies.concat(newReply); const newComment = {...comment, replies: newReplies}; this.setState({ threads: [ ...this.state.threads.slice(0, index), newComment, ...this.state.threads.slice(index + 1), ], reply: { commentId: null, }, }); } catch (e) { Toast.push("Не удалось отправить комментарий. Попробуйте снова."); this.setState({ reply: { commentId: commentId, }, }); console.error(e); } finally { this.setState({ reply: { sending: false, } }); } };
handleAddComment = async (commentId, text) => { const {commentsApi, courseId, slideId, forInstructors, handleInstructorsCommentCount} = this.props; const threads = [...this.state.threads]; this.setState({ sending: true, animation: true, }); try { const newComment = await commentsApi.addComment(courseId, slideId, text, null, forInstructors); const pinnedComments = threads.filter(comment => comment.isPinnedToTop); const filteredComments = threads.filter(comment => !comment.isPinnedToTop) .sort((a, b) => new Date(b.publishTime) - new Date(a.publishTime)); this.setState({ threads: [ ...pinnedComments, newComment, ...filteredComments, ], newCommentId: this.state.newCommentId + 1, }); this.handleScroll(this.lastThreadRef); if (forInstructors) { handleInstructorsCommentCount("add"); } } catch (e) { Toast.push("Не удалось добавить комментарий. Попробуйте снова."); this.setState({ newCommentId: this.state.newCommentId, }); console.error(e); } finally { this.setState({ sending: false, }) } };
handleEditComment = async (commentId, text) => { const {commentsApi} = this.props; this.setState({ commentEditing: { commentId: commentId, sending: true, }, }); try { const newComment = await commentsApi.updateComment(commentId, {"text": text}); this.updateComment(commentId, () => ({ text: text, renderedText: newComment.renderedText, })); this.setState({ commentEditing: { commentId: null, }, }); } catch (e) { Toast.push("Не удалось изменить комментарий. Попробуйте снова."); this.setState({ commentEditing: { commentId: commentId, }, }); console.error(e); } finally { this.setState({ commentEditing: { sending: false, }, }) } };
.catch(e => { Toast.push("Не удалось изменить комментарий. Произошла ошибка, попробуйте снова"); console.error(e); });
<Button use="link" icon={<LinkIcon />} onClick={() => Toast.push('Ссылка скопирована')}>