From 461ae5d7905fd5d8d9c482e753b5de8c154fcb91 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Sun, 8 Sep 2019 09:54:53 -0700 Subject: Add image loading indicator. --- ui/src/components/comment-form.tsx | 22 ++++++++++++++++++---- ui/src/components/post-form.tsx | 21 +++++++++++++++++---- 2 files changed, 35 insertions(+), 8 deletions(-) (limited to 'ui/src/components') diff --git a/ui/src/components/comment-form.tsx b/ui/src/components/comment-form.tsx index 837cefb5..5b60aced 100644 --- a/ui/src/components/comment-form.tsx +++ b/ui/src/components/comment-form.tsx @@ -1,7 +1,7 @@ import { Component, linkEvent } from 'inferno'; import { CommentNode as CommentNodeI, CommentForm as CommentFormI, SearchForm, SearchType, SortType, UserOperation, SearchResponse } from '../interfaces'; import { Subscription } from "rxjs"; -import { capitalizeFirstLetter, mentionDropdownFetchLimit, msgOp, mdToHtml, randomStr, imageUploadUrl, markdownHelpUrl } from '../utils'; +import { capitalizeFirstLetter, mentionDropdownFetchLimit, msgOp, mdToHtml, randomStr, markdownHelpUrl } from '../utils'; import { WebSocketService, UserService } from '../services'; import * as autosize from 'autosize'; import { i18n } from '../i18next'; @@ -21,6 +21,7 @@ interface CommentFormState { commentForm: CommentFormI; buttonTitle: string; previewMode: boolean; + imageLoading: boolean; } export class CommentForm extends Component { @@ -38,6 +39,7 @@ export class CommentForm extends Component { }, buttonTitle: !this.props.node ? capitalizeFirstLetter(i18n.t('post')) : this.props.edit ? capitalizeFirstLetter(i18n.t('edit')) : capitalizeFirstLetter(i18n.t('reply')), previewMode: false, + imageLoading: false, } constructor(props: any, context: any) { @@ -134,12 +136,15 @@ export class CommentForm extends Component { {this.state.commentForm.content && } - {this.props.node && } + {this.props.node && } #
- +
+ {this.state.imageLoading && + + } @@ -187,6 +192,10 @@ export class CommentForm extends Component { const imageUploadUrl = `/pictshare/api/upload.php`; const formData = new FormData(); formData.append('file', file); + + i.state.imageLoading = true; + i.setState(i.state); + fetch(imageUploadUrl, { method: 'POST', body: formData, @@ -198,9 +207,14 @@ export class CommentForm extends Component { let content = i.state.commentForm.content; content = (content) ? `${content} ${markdown}` : markdown; i.state.commentForm.content = content; + i.state.imageLoading = false; + i.setState(i.state); + }) + .catch((error) => { + i.state.imageLoading = false; i.setState(i.state); + alert(error); }) - .catch((error) => alert(error)); } userSearch(text: string, cb: any) { diff --git a/ui/src/components/post-form.tsx b/ui/src/components/post-form.tsx index 1591dde0..b59d07d6 100644 --- a/ui/src/components/post-form.tsx +++ b/ui/src/components/post-form.tsx @@ -4,7 +4,7 @@ import { Subscription } from "rxjs"; import { retryWhen, delay, take } from 'rxjs/operators'; import { PostForm as PostFormI, PostFormParams, Post, PostResponse, UserOperation, Community, ListCommunitiesResponse, ListCommunitiesForm, SortType, SearchForm, SearchType, SearchResponse } from '../interfaces'; import { WebSocketService, UserService } from '../services'; -import { msgOp, getPageTitle, debounce, validURL, capitalizeFirstLetter, imageUploadUrl, markdownHelpUrl, mdToHtml } from '../utils'; +import { msgOp, getPageTitle, debounce, validURL, capitalizeFirstLetter, markdownHelpUrl, mdToHtml } from '../utils'; import * as autosize from 'autosize'; import { i18n } from '../i18next'; import { T } from 'inferno-i18next'; @@ -21,6 +21,7 @@ interface PostFormState { postForm: PostFormI; communities: Array; loading: boolean; + imageLoading: boolean; previewMode: boolean; suggestedTitle: string; suggestedPosts: Array; @@ -40,6 +41,7 @@ export class PostForm extends Component { }, communities: [], loading: false, + imageLoading: false, previewMode: false, suggestedTitle: undefined, suggestedPosts: [], @@ -111,8 +113,11 @@ export class PostForm extends Component { }
- +
+ {this.state.imageLoading && + + } {this.state.crossPosts.length > 0 && <>
#
@@ -275,6 +280,10 @@ export class PostForm extends Component { const imageUploadUrl = `/pictshare/api/upload.php`; const formData = new FormData(); formData.append('file', file); + + i.state.imageLoading = true; + i.setState(i.state); + fetch(imageUploadUrl, { method: 'POST', body: formData, @@ -285,11 +294,15 @@ export class PostForm extends Component { if (res.filetype == 'mp4') { url += '/raw'; } - i.state.postForm.url = url; + i.state.imageLoading = false; + i.setState(i.state); + }) + .catch((error) => { + i.state.imageLoading = false; i.setState(i.state); + alert(error); }) - .catch((error) => alert(error)); } parseMessage(msg: any) { -- cgit v1.2.3