diff options
author | Dessalines <tyhou13@gmx.com> | 2019-09-08 09:54:53 -0700 |
---|---|---|
committer | Dessalines <tyhou13@gmx.com> | 2019-09-08 09:54:53 -0700 |
commit | 461ae5d7905fd5d8d9c482e753b5de8c154fcb91 (patch) | |
tree | 314d60ce975286b99761050d65a7d542dd72b639 /ui/src/components/post-form.tsx | |
parent | a279cfad95d2a52e7d648f6038f181202c2c1e18 (diff) |
Add image loading indicator.
Diffstat (limited to 'ui/src/components/post-form.tsx')
-rw-r--r-- | ui/src/components/post-form.tsx | 21 |
1 files changed, 17 insertions, 4 deletions
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<Community>; loading: boolean; + imageLoading: boolean; previewMode: boolean; suggestedTitle: string; suggestedPosts: Array<Post>; @@ -40,6 +41,7 @@ export class PostForm extends Component<PostFormProps, PostFormState> { }, communities: [], loading: false, + imageLoading: false, previewMode: false, suggestedTitle: undefined, suggestedPosts: [], @@ -111,8 +113,11 @@ export class PostForm extends Component<PostFormProps, PostFormState> { } <form> <label htmlFor="file-upload" class="pointer d-inline-block mr-2 float-right text-muted small font-weight-bold"><T i18nKey="upload_image">#</T></label> - <input id="file-upload" type="file" name="file" class="d-none" onChange={linkEvent(this, this.handleImageUpload)} /> + <input id="file-upload" type="file" accept="image/*,video/*" name="file" class="d-none" onChange={linkEvent(this, this.handleImageUpload)} /> </form> + {this.state.imageLoading && + <svg class="icon icon-spinner spin"><use xlinkHref="#icon-spinner"></use></svg> + } {this.state.crossPosts.length > 0 && <> <div class="my-1 text-muted small font-weight-bold"><T i18nKey="cross_posts">#</T></div> @@ -275,6 +280,10 @@ export class PostForm extends Component<PostFormProps, PostFormState> { 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<PostFormProps, PostFormState> { 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) { |