Skip to content

Commit

Permalink
optimize last comment widget
Browse files Browse the repository at this point in the history
  • Loading branch information
Mavrin authored and umputun committed Feb 22, 2020
1 parent ffb41ab commit 5039e8d
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 7 deletions.
4 changes: 2 additions & 2 deletions frontend/.size-limit.js
Original file line number Diff line number Diff line change
@@ -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',
},
{
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/components/comment-form/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { CommentForm } from './comment-form';
export { CommentForm, Props } from './comment-form';

import '@app/components/raw-content';

Expand Down
1 change: 1 addition & 0 deletions frontend/app/components/comment/comment.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { sleep } from '@app/utils/sleep';
import { StaticStore } from '@app/common/static_store';

const DefaultProps: Partial<Props> = {
CommentForm: null,
post_info: {
read_only: false,
} as PostInfo,
Expand Down
11 changes: 7 additions & 4 deletions frontend/app/components/comment/comment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand All @@ -25,6 +25,7 @@ import postMessage from '@app/utils/postMessage';

export type Props = {
user: User | null;
CommentForm: ComponentType<CommentFormProps> | null;
data: CommentType;
repliesCount?: number;
post_info: PostInfo | null;
Expand Down Expand Up @@ -464,6 +465,8 @@ export class Comment extends Component<Props, State> {
const uploadImageHandler = this.isAnonymous() ? undefined : this.props.uploadImage;
const commentControls = this.getCommentControls();

const CommentForm = this.props.CommentForm;

/**
* CommentType adapted for rendering
*/
Expand Down Expand Up @@ -716,7 +719,7 @@ export class Comment extends Component<Props, State> {
)}
</div>

{isReplying && props.view === 'main' && (
{CommentForm && isReplying && props.view === 'main' && (
<CommentForm
user={props.user}
theme={props.theme}
Expand All @@ -732,7 +735,7 @@ export class Comment extends Component<Props, State> {
/>
)}

{isEditing && props.view === 'main' && (
{CommentForm && isEditing && props.view === 'main' && (
<CommentForm
user={props.user}
theme={props.theme}
Expand Down
1 change: 1 addition & 0 deletions frontend/app/components/list-comments/list-comments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const ListComments = ({ comments = [] }: Props) => (
<div className="list-comments">
{comments.map(comment => (
<Comment
CommentForm={null}
data={comment}
level={0}
view="preview"
Expand Down
1 change: 1 addition & 0 deletions frontend/app/components/root/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ export class Root extends Component<Props, State> {
<div className="root__pinned-comments" role="region" aria-label="Pinned comments">
{this.props.pinnedComments.map(comment => (
<Comment
CommentForm={CommentForm}
key={`pinned-comment-${comment.id}`}
view="pinned"
data={comment}
Expand Down
2 changes: 2 additions & 0 deletions frontend/app/components/thread/thread.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { setCollapse } from '@app/store/thread/actions';
import { getThreadIsCollapsed } from '@app/store/thread/getters';
import { InView } from '@app/components/root/in-view/in-view';
import { ConnectedComment as Comment } from '@app/components/comment/connected-comment';
import { CommentForm } from '@app/components/comment-form';

interface Props {
id: CommentInterface['id'];
Expand Down Expand Up @@ -51,6 +52,7 @@ export const Thread: FunctionComponent<Props> = ({ id, level, mix, getPreview })
<InView>
{inviewProps => (
<Comment
CommentForm={CommentForm}
ref={ref => inviewProps.ref(ref)}
key={`comment-${id}`}
view="main"
Expand Down
1 change: 1 addition & 0 deletions frontend/app/components/user-info/last-comments-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const LastCommentsList = ({ comments, isLoading }: { comments: CommentType[]; is
<div>
{comments.map(comment => (
<Comment
CommentForm={null}
data={comment}
level={0}
view="user"
Expand Down

0 comments on commit 5039e8d

Please sign in to comment.