From 5039e8d2777510be9c0125e1e1717b548fbde6a1 Mon Sep 17 00:00:00 2001 From: konstantin krivlenia Date: Sat, 22 Feb 2020 16:40:56 +0300 Subject: [PATCH] optimize last comment widget --- frontend/.size-limit.js | 4 ++-- frontend/app/components/comment-form/index.ts | 2 +- frontend/app/components/comment/comment.test.tsx | 1 + frontend/app/components/comment/comment.tsx | 11 +++++++---- .../app/components/list-comments/list-comments.tsx | 1 + frontend/app/components/root/root.tsx | 1 + frontend/app/components/thread/thread.tsx | 2 ++ .../app/components/user-info/last-comments-list.tsx | 1 + 8 files changed, 16 insertions(+), 7 deletions(-) diff --git a/frontend/.size-limit.js b/frontend/.size-limit.js index 9136de1d..fcb67b7c 100644 --- a/frontend/.size-limit.js +++ b/frontend/.size-limit.js @@ -1,14 +1,14 @@ module.exports = [ { path: 'public/embed.js', - limit: '2.5 KB', + limit: '2.55 KB', }, { limit: '68 KB', path: 'public/remark.js', }, { - limit: '55 KB', + limit: '30 KB', path: 'public/last-comments.js', }, { diff --git a/frontend/app/components/comment-form/index.ts b/frontend/app/components/comment-form/index.ts index 1e4c199d..112a9a66 100644 --- a/frontend/app/components/comment-form/index.ts +++ b/frontend/app/components/comment-form/index.ts @@ -1,4 +1,4 @@ -export { CommentForm } from './comment-form'; +export { CommentForm, Props } from './comment-form'; import '@app/components/raw-content'; diff --git a/frontend/app/components/comment/comment.test.tsx b/frontend/app/components/comment/comment.test.tsx index f8cfcc28..2717fa3a 100644 --- a/frontend/app/components/comment/comment.test.tsx +++ b/frontend/app/components/comment/comment.test.tsx @@ -7,6 +7,7 @@ import { sleep } from '@app/utils/sleep'; import { StaticStore } from '@app/common/static_store'; const DefaultProps: Partial = { + CommentForm: null, post_info: { read_only: false, } as PostInfo, diff --git a/frontend/app/components/comment/comment.tsx b/frontend/app/components/comment/comment.tsx index e40c20d9..8b371315 100644 --- a/frontend/app/components/comment/comment.tsx +++ b/frontend/app/components/comment/comment.tsx @@ -2,7 +2,7 @@ import './styles'; -import { createElement, JSX, Component, createRef } from 'preact'; +import { createElement, JSX, Component, createRef, ComponentType } from 'preact'; import b from 'bem-react-helper'; import { getHandleClickProps } from '@app/common/accessibility'; @@ -15,7 +15,7 @@ import { Theme, BlockTTL, Comment as CommentType, PostInfo, User, CommentMode } import { extractErrorMessageFromResponse, FetcherError } from '@app/utils/errorUtils'; import { isUserAnonymous } from '@app/utils/isUserAnonymous'; -import { CommentForm } from '@app/components/comment-form'; +import { Props as CommentFormProps } from '@app/components/comment-form'; import { AvatarIcon } from '@app/components/avatar-icon'; import { Button } from '@app/components/button'; import Countdown from '@app/components/countdown'; @@ -25,6 +25,7 @@ import postMessage from '@app/utils/postMessage'; export type Props = { user: User | null; + CommentForm: ComponentType | null; data: CommentType; repliesCount?: number; post_info: PostInfo | null; @@ -464,6 +465,8 @@ export class Comment extends Component { const uploadImageHandler = this.isAnonymous() ? undefined : this.props.uploadImage; const commentControls = this.getCommentControls(); + const CommentForm = this.props.CommentForm; + /** * CommentType adapted for rendering */ @@ -716,7 +719,7 @@ export class Comment extends Component { )} - {isReplying && props.view === 'main' && ( + {CommentForm && isReplying && props.view === 'main' && ( { /> )} - {isEditing && props.view === 'main' && ( + {CommentForm && isEditing && props.view === 'main' && ( (
{comments.map(comment => ( {
{this.props.pinnedComments.map(comment => ( = ({ id, level, mix, getPreview }) {inviewProps => ( inviewProps.ref(ref)} key={`comment-${id}`} view="main" diff --git a/frontend/app/components/user-info/last-comments-list.tsx b/frontend/app/components/user-info/last-comments-list.tsx index 2dc58767..5511413c 100644 --- a/frontend/app/components/user-info/last-comments-list.tsx +++ b/frontend/app/components/user-info/last-comments-list.tsx @@ -15,6 +15,7 @@ const LastCommentsList = ({ comments, isLoading }: { comments: CommentType[]; is
{comments.map(comment => (