summaryrefslogtreecommitdiffstats
path: root/ui/src/components
diff options
context:
space:
mode:
authorRichie Zhang <12566991+StaticallyTypedRice@users.noreply.github.com>2020-01-30 15:59:03 -0800
committerGitHub <noreply@github.com>2020-01-30 15:59:03 -0800
commit43c55027f918b518382cf2ec63ff2ca99bb05ac9 (patch)
tree7a4bea8b5cc10a1955e7fd6874b54f8fea9910dc /ui/src/components
parented842dfb720b4dc23000459eb4a3f203728ab565 (diff)
parent4778f198e16ae64dc054687264d2d5222158a576 (diff)
Merge pull request #6 from dessalines/dev
Merge upstream
Diffstat (limited to 'ui/src/components')
-rw-r--r--ui/src/components/comment-form.tsx24
-rw-r--r--ui/src/components/comment-node.tsx18
-rw-r--r--ui/src/components/communities.tsx2
-rw-r--r--ui/src/components/community-form.tsx2
-rw-r--r--ui/src/components/community.tsx13
-rw-r--r--ui/src/components/inbox.tsx6
-rw-r--r--ui/src/components/login.tsx2
-rw-r--r--ui/src/components/main.tsx2
-rw-r--r--ui/src/components/modlog.tsx2
-rw-r--r--ui/src/components/navbar.tsx6
-rw-r--r--ui/src/components/post-form.tsx20
-rw-r--r--ui/src/components/post-listing.tsx11
-rw-r--r--ui/src/components/post.tsx27
-rw-r--r--ui/src/components/private-message-form.tsx2
-rw-r--r--ui/src/components/search.tsx2
-rw-r--r--ui/src/components/setup.tsx2
-rw-r--r--ui/src/components/user.tsx4
17 files changed, 103 insertions, 42 deletions
diff --git a/ui/src/components/comment-form.tsx b/ui/src/components/comment-form.tsx
index f4eb1181..7eb30f50 100644
--- a/ui/src/components/comment-form.tsx
+++ b/ui/src/components/comment-form.tsx
@@ -96,6 +96,7 @@ export class CommentForm extends Component<CommentFormProps, CommentFormState> {
className={`form-control ${this.state.previewMode && 'd-none'}`}
value={this.state.commentForm.content}
onInput={linkEvent(this, this.handleCommentContentChange)}
+ onPaste={linkEvent(this, this.handleImageUploadPaste)}
required
disabled={this.props.disabled}
rows={2}
@@ -208,9 +209,22 @@ export class CommentForm extends Component<CommentFormProps, CommentFormState> {
i.props.onReplyCancel();
}
+ handleImageUploadPaste(i: CommentForm, event: any) {
+ let image = event.clipboardData.files[0];
+ if (image) {
+ i.handleImageUpload(i, image);
+ }
+ }
+
handleImageUpload(i: CommentForm, event: any) {
- event.preventDefault();
- let file = event.target.files[0];
+ let file: any;
+ if (event.target) {
+ event.preventDefault();
+ file = event.target.files[0];
+ } else {
+ file = event;
+ }
+
const imageUploadUrl = `/pictshare/api/upload.php`;
const formData = new FormData();
formData.append('file', file);
@@ -225,13 +239,15 @@ export class CommentForm extends Component<CommentFormProps, CommentFormState> {
.then(res => res.json())
.then(res => {
let url = `${window.location.origin}/pictshare/${res.url}`;
- let markdown =
+ let imageMarkdown =
res.filetype == 'mp4' ? `[vid](${url}/raw)` : `![](${url})`;
let content = i.state.commentForm.content;
- content = content ? `${content} ${markdown}` : markdown;
+ content = content ? `${content}\n${imageMarkdown}` : imageMarkdown;
i.state.commentForm.content = content;
i.state.imageLoading = false;
i.setState(i.state);
+ var textarea: any = document.getElementById(i.id);
+ autosize.update(textarea);
})
.catch(error => {
i.state.imageLoading = false;
diff --git a/ui/src/components/comment-node.tsx b/ui/src/components/comment-node.tsx
index 046fc88d..a42d096e 100644
--- a/ui/src/components/comment-node.tsx
+++ b/ui/src/components/comment-node.tsx
@@ -117,7 +117,6 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
.viewOnly && 'no-click'}`}
>
<button
- disabled={!UserService.Instance.user}
className={`btn p-0 ${
node.comment.my_vote == 1 ? 'text-info' : 'text-muted'
}`}
@@ -138,7 +137,6 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
</div>
{WebSocketService.Instance.site.enable_downvotes && (
<button
- disabled={!UserService.Instance.user}
className={`btn p-0 ${
node.comment.my_vote == -1 ? 'text-danger' : 'text-muted'
}`}
@@ -761,9 +759,11 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
}
handleCommentUpvote(i: CommentNodeI) {
- this.setState({
- upvoteLoading: true,
- });
+ if (UserService.Instance.user) {
+ this.setState({
+ upvoteLoading: true,
+ });
+ }
let form: CommentLikeForm = {
comment_id: i.comment.id,
post_id: i.comment.post_id,
@@ -773,9 +773,11 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
}
handleCommentDownvote(i: CommentNodeI) {
- this.setState({
- downvoteLoading: true,
- });
+ if (UserService.Instance.user) {
+ this.setState({
+ downvoteLoading: true,
+ });
+ }
let form: CommentLikeForm = {
comment_id: i.comment.id,
post_id: i.comment.post_id,
diff --git a/ui/src/components/communities.tsx b/ui/src/components/communities.tsx
index 867cfd81..b1da9882 100644
--- a/ui/src/components/communities.tsx
+++ b/ui/src/components/communities.tsx
@@ -235,7 +235,7 @@ export class Communities extends Component<any, CommunitiesState> {
parseMessage(msg: WebSocketJsonResponse) {
console.log(msg);
let res = wsJsonToRes(msg);
- if (res.error) {
+ if (msg.error) {
toast(i18n.t(msg.error), 'danger');
return;
} else if (res.op == UserOperation.ListCommunities) {
diff --git a/ui/src/components/community-form.tsx b/ui/src/components/community-form.tsx
index 33c63c89..c8d888be 100644
--- a/ui/src/components/community-form.tsx
+++ b/ui/src/components/community-form.tsx
@@ -261,7 +261,7 @@ export class CommunityForm extends Component<
parseMessage(msg: WebSocketJsonResponse) {
let res = wsJsonToRes(msg);
console.log(msg);
- if (res.error) {
+ if (msg.error) {
toast(i18n.t(msg.error), 'danger');
this.state.loading = false;
this.setState(this.state);
diff --git a/ui/src/components/community.tsx b/ui/src/components/community.tsx
index 9d02dd86..3c5f6890 100644
--- a/ui/src/components/community.tsx
+++ b/ui/src/components/community.tsx
@@ -11,6 +11,7 @@ import {
SortType,
Post,
GetPostsForm,
+ GetCommunityForm,
ListingType,
GetPostsResponse,
CreatePostLikeResponse,
@@ -98,11 +99,11 @@ export class Community extends Component<any, State> {
() => console.log('complete')
);
- if (this.state.communityId) {
- WebSocketService.Instance.getCommunity(this.state.communityId);
- } else if (this.state.communityName) {
- WebSocketService.Instance.getCommunityByName(this.state.communityName);
- }
+ let form: GetCommunityForm = {
+ id: this.state.communityId ? this.state.communityId : null,
+ name: this.state.communityName ? this.state.communityName : null,
+ };
+ WebSocketService.Instance.getCommunity(form);
}
componentWillUnmount() {
@@ -258,7 +259,7 @@ export class Community extends Component<any, State> {
parseMessage(msg: WebSocketJsonResponse) {
console.log(msg);
let res = wsJsonToRes(msg);
- if (res.error) {
+ if (msg.error) {
toast(i18n.t(msg.error), 'danger');
this.context.router.history.push('/');
return;
diff --git a/ui/src/components/inbox.tsx b/ui/src/components/inbox.tsx
index 5c3ff6d2..41c1ce60 100644
--- a/ui/src/components/inbox.tsx
+++ b/ui/src/components/inbox.tsx
@@ -38,6 +38,8 @@ enum UnreadType {
Messages,
}
+type ReplyType = Comment | PrivateMessageI;
+
interface InboxState {
unreadOrAll: UnreadOrAll;
unreadType: UnreadType;
@@ -186,7 +188,7 @@ export class Inbox extends Component<any, InboxState> {
}
all() {
- let combined: Array<Comment | PrivateMessageI> = [];
+ let combined: Array<ReplyType> = [];
combined.push(...this.state.replies);
combined.push(...this.state.mentions);
@@ -324,7 +326,7 @@ export class Inbox extends Component<any, InboxState> {
parseMessage(msg: WebSocketJsonResponse) {
console.log(msg);
let res = wsJsonToRes(msg);
- if (res.error) {
+ if (msg.error) {
toast(i18n.t(msg.error), 'danger');
return;
} else if (res.op == UserOperation.GetReplies) {
diff --git a/ui/src/components/login.tsx b/ui/src/components/login.tsx
index ac60ba74..64687a3d 100644
--- a/ui/src/components/login.tsx
+++ b/ui/src/components/login.tsx
@@ -295,7 +295,7 @@ export class Login extends Component<any, State> {
parseMessage(msg: WebSocketJsonResponse) {
let res = wsJsonToRes(msg);
- if (res.error) {
+ if (msg.error) {
toast(i18n.t(msg.error), 'danger');
this.state = this.emptyState;
this.setState(this.state);
diff --git a/ui/src/components/main.tsx b/ui/src/components/main.tsx
index 9f16edb5..6bf4164f 100644
--- a/ui/src/components/main.tsx
+++ b/ui/src/components/main.tsx
@@ -566,7 +566,7 @@ export class Main extends Component<any, MainState> {
parseMessage(msg: WebSocketJsonResponse) {
console.log(msg);
let res = wsJsonToRes(msg);
- if (res.error) {
+ if (msg.error) {
toast(i18n.t(msg.error), 'danger');
return;
} else if (res.op == UserOperation.GetFollowedCommunities) {
diff --git a/ui/src/components/modlog.tsx b/ui/src/components/modlog.tsx
index dd651092..e03f1ff7 100644
--- a/ui/src/components/modlog.tsx
+++ b/ui/src/components/modlog.tsx
@@ -425,7 +425,7 @@ export class Modlog extends Component<any, ModlogState> {
parseMessage(msg: WebSocketJsonResponse) {
console.log(msg);
let res = wsJsonToRes(msg);
- if (res.error) {
+ if (msg.error) {
toast(i18n.t(msg.error), 'danger');
return;
} else if (res.op == UserOperation.GetModlog) {
diff --git a/ui/src/components/navbar.tsx b/ui/src/components/navbar.tsx
index 849822af..1828fce9 100644
--- a/ui/src/components/navbar.tsx
+++ b/ui/src/components/navbar.tsx
@@ -138,7 +138,7 @@ export class Navbar extends Component<any, NavbarState> {
</li>
<li className="nav-item">
<Link
- class="nav-link ml-2"
+ class="nav-link"
to="/sponsors"
title={i18n.t('donate_to_lemmy')}
>
@@ -202,8 +202,8 @@ export class Navbar extends Component<any, NavbarState> {
parseMessage(msg: WebSocketJsonResponse) {
let res = wsJsonToRes(msg);
- if (res.error) {
- if (res.error == 'not_logged_in') {
+ if (msg.error) {
+ if (msg.error == 'not_logged_in') {
UserService.Instance.logout();
location.reload();
}
diff --git a/ui/src/components/post-form.tsx b/ui/src/components/post-form.tsx
index 677007ca..57d9a964 100644
--- a/ui/src/components/post-form.tsx
+++ b/ui/src/components/post-form.tsx
@@ -160,6 +160,7 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
class="form-control"
value={this.state.postForm.url}
onInput={linkEvent(this, this.handlePostUrlChange)}
+ onPaste={linkEvent(this, this.handleImageUploadPaste)}
/>
{this.state.suggestedTitle && (
<div
@@ -442,9 +443,22 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
i.setState(i.state);
}
+ handleImageUploadPaste(i: PostForm, event: any) {
+ let image = event.clipboardData.files[0];
+ if (image) {
+ i.handleImageUpload(i, image);
+ }
+ }
+
handleImageUpload(i: PostForm, event: any) {
- event.preventDefault();
- let file = event.target.files[0];
+ let file: any;
+ if (event.target) {
+ event.preventDefault();
+ file = event.target.files[0];
+ } else {
+ file = event;
+ }
+
const imageUploadUrl = `/pictshare/api/upload.php`;
const formData = new FormData();
formData.append('file', file);
@@ -475,7 +489,7 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
parseMessage(msg: WebSocketJsonResponse) {
let res = wsJsonToRes(msg);
- if (res.error) {
+ if (msg.error) {
toast(i18n.t(msg.error), 'danger');
this.state.loading = false;
this.setState(this.state);
diff --git a/ui/src/components/post-listing.tsx b/ui/src/components/post-listing.tsx
index aab2cea5..c9a29e87 100644
--- a/ui/src/components/post-listing.tsx
+++ b/ui/src/components/post-listing.tsx
@@ -119,7 +119,6 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
<div class="listing col-12">
<div className={`vote-bar mr-2 float-left small text-center`}>
<button
- disabled={!UserService.Instance.user}
className={`btn p-0 ${
post.my_vote == 1 ? 'text-info' : 'text-muted'
}`}
@@ -138,7 +137,6 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
<div class={`font-weight-bold text-muted`}>{post.score}</div>
{WebSocketService.Instance.site.enable_downvotes && (
<button
- disabled={!UserService.Instance.user}
className={`btn p-0 ${
post.my_vote == -1 ? 'text-danger' : 'text-muted'
}`}
@@ -740,17 +738,22 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
}
handlePostLike(i: PostListing) {
- i.setState({ upvoteLoading: true });
+ if (UserService.Instance.user) {
+ i.setState({ upvoteLoading: true });
+ }
let form: CreatePostLikeForm = {
post_id: i.props.post.id,
score: i.props.post.my_vote == 1 ? 0 : 1,
};
+
WebSocketService.Instance.likePost(form);
}
handlePostDisLike(i: PostListing) {
- i.setState({ downvoteLoading: true });
+ if (UserService.Instance.user) {
+ i.setState({ downvoteLoading: true });
+ }
let form: CreatePostLikeForm = {
post_id: i.props.post.id,
diff --git a/ui/src/components/post.tsx b/ui/src/components/post.tsx
index 931ced2d..36621248 100644
--- a/ui/src/components/post.tsx
+++ b/ui/src/components/post.tsx
@@ -23,6 +23,7 @@ import {
SearchType,
SortType,
SearchForm,
+ GetPostForm,
SearchResponse,
GetSiteResponse,
GetCommunityResponse,
@@ -84,7 +85,10 @@ export class Post extends Component<any, PostState> {
() => console.log('complete')
);
- WebSocketService.Instance.getPost(postId);
+ let form: GetPostForm = {
+ id: postId,
+ };
+ WebSocketService.Instance.getPost(form);
}
componentWillUnmount() {
@@ -231,6 +235,18 @@ export class Post extends Component<any, PostState> {
onChange={linkEvent(this, this.handleCommentSortChange)}
/>
</label>
+ <label
+ className={`btn btn-sm btn-secondary pointer ${this.state
+ .commentSort === CommentSortType.Old && 'active'}`}
+ >
+ {i18n.t('old')}
+ <input
+ type="radio"
+ value={CommentSortType.Old}
+ checked={this.state.commentSort === CommentSortType.Old}
+ onChange={linkEvent(this, this.handleCommentSortChange)}
+ />
+ </label>
</div>
);
}
@@ -313,6 +329,13 @@ export class Post extends Component<any, PostState> {
+a.comment.deleted - +b.comment.deleted ||
b.comment.published.localeCompare(a.comment.published)
);
+ } else if (this.state.commentSort == CommentSortType.Old) {
+ tree.sort(
+ (a, b) =>
+ +a.comment.removed - +b.comment.removed ||
+ +a.comment.deleted - +b.comment.deleted ||
+ a.comment.published.localeCompare(b.comment.published)
+ );
} else if (this.state.commentSort == CommentSortType.Hot) {
tree.sort(
(a, b) =>
@@ -345,7 +368,7 @@ export class Post extends Component<any, PostState> {
parseMessage(msg: WebSocketJsonResponse) {
console.log(msg);
let res = wsJsonToRes(msg);
- if (res.error) {
+ if (msg.error) {
toast(i18n.t(msg.error), 'danger');
return;
} else if (res.op == UserOperation.GetPost) {
diff --git a/ui/src/components/private-message-form.tsx b/ui/src/components/private-message-form.tsx
index c8627845..13b4d2ea 100644
--- a/ui/src/components/private-message-form.tsx
+++ b/ui/src/components/private-message-form.tsx
@@ -283,7 +283,7 @@ export class PrivateMessageForm extends Component<
parseMessage(msg: WebSocketJsonResponse) {
let res = wsJsonToRes(msg);
- if (res.error) {
+ if (msg.error) {
toast(i18n.t(msg.error), 'danger');
this.state.loading = false;
this.setState(this.state);
diff --git a/ui/src/components/search.tsx b/ui/src/components/search.tsx
index 18b5d341..604c2617 100644
--- a/ui/src/components/search.tsx
+++ b/ui/src/components/search.tsx
@@ -479,7 +479,7 @@ export class Search extends Component<any, SearchState> {
parseMessage(msg: WebSocketJsonResponse) {
console.log(msg);
let res = wsJsonToRes(msg);
- if (res.error) {
+ if (msg.error) {
toast(i18n.t(msg.error), 'danger');
return;
} else if (res.op == UserOperation.Search) {
diff --git a/ui/src/components/setup.tsx b/ui/src/components/setup.tsx
index 26475a38..25cfadef 100644
--- a/ui/src/components/setup.tsx
+++ b/ui/src/components/setup.tsx
@@ -188,7 +188,7 @@ export class Setup extends Component<any, State> {
parseMessage(msg: WebSocketJsonResponse) {
let res = wsJsonToRes(msg);
- if (res.error) {
+ if (msg.error) {
toast(i18n.t(msg.error), 'danger');
this.state.userLoading = false;
this.setState(this.state);
diff --git a/ui/src/components/user.tsx b/ui/src/components/user.tsx
index 09129d67..1475de6b 100644
--- a/ui/src/components/user.tsx
+++ b/ui/src/components/user.tsx
@@ -1016,12 +1016,12 @@ export class User extends Component<any, UserState> {
parseMessage(msg: WebSocketJsonResponse) {
console.log(msg);
let res = wsJsonToRes(msg);
- if (res.error) {
+ if (msg.error) {
toast(i18n.t(msg.error), 'danger');
this.state.deleteAccountLoading = false;
this.state.avatarLoading = false;
this.state.userSettingsLoading = false;
- if (res.error == 'couldnt_find_that_username_or_email') {
+ if (msg.error == 'couldnt_find_that_username_or_email') {
this.context.router.history.push('/');
}
this.setState(this.state);