diff options
author | crupest <crupest@outlook.com> | 2020-08-10 16:56:09 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-08-10 16:56:09 +0800 |
commit | 0024672d75d061167fb9de67629cc796a52861e6 (patch) | |
tree | 969091ee5d7078165f0c1324728fc1182943988a | |
parent | 38f4fdc3229638059953f9e058d49ad7c81c0ca9 (diff) | |
download | timeline-0024672d75d061167fb9de67629cc796a52861e6.tar.gz timeline-0024672d75d061167fb9de67629cc796a52861e6.tar.bz2 timeline-0024672d75d061167fb9de67629cc796a52861e6.zip |
Do not block when get post data.
-rw-r--r-- | Timeline/ClientApp/src/app/common/BlobImage.tsx | 6 | ||||
-rw-r--r-- | Timeline/ClientApp/src/app/data/common.ts | 2 | ||||
-rw-r--r-- | Timeline/ClientApp/src/app/data/timeline.ts | 12 |
3 files changed, 12 insertions, 8 deletions
diff --git a/Timeline/ClientApp/src/app/common/BlobImage.tsx b/Timeline/ClientApp/src/app/common/BlobImage.tsx index 91497705..7e5e2447 100644 --- a/Timeline/ClientApp/src/app/common/BlobImage.tsx +++ b/Timeline/ClientApp/src/app/common/BlobImage.tsx @@ -3,14 +3,16 @@ import React from 'react'; import { ExcludeKey } from '../utilities/type';
const BlobImage: React.FC<
- ExcludeKey<React.ImgHTMLAttributes<HTMLImageElement>, 'src'> & { blob?: Blob }
+ ExcludeKey<React.ImgHTMLAttributes<HTMLImageElement>, 'src'> & {
+ blob?: Blob | unknown;
+ }
> = (props) => {
const { blob, ...otherProps } = props;
const [url, setUrl] = React.useState<string | undefined>(undefined);
React.useEffect(() => {
- if (blob != null) {
+ if (blob instanceof Blob) {
const url = URL.createObjectURL(blob);
setUrl(url);
return () => {
diff --git a/Timeline/ClientApp/src/app/data/common.ts b/Timeline/ClientApp/src/app/data/common.ts index 35934a29..87984e21 100644 --- a/Timeline/ClientApp/src/app/data/common.ts +++ b/Timeline/ClientApp/src/app/data/common.ts @@ -19,3 +19,5 @@ export function throwIfNotNetworkError(e: unknown): void { throw e;
}
}
+
+export type BlobOrStatus = Blob | 'loading' | 'error';
diff --git a/Timeline/ClientApp/src/app/data/timeline.ts b/Timeline/ClientApp/src/app/data/timeline.ts index 9867b128..fc554f7b 100644 --- a/Timeline/ClientApp/src/app/data/timeline.ts +++ b/Timeline/ClientApp/src/app/data/timeline.ts @@ -1,12 +1,12 @@ import React from 'react';
import XRegExp from 'xregexp';
import { Observable, from, combineLatest, of } from 'rxjs';
-import { map, switchMap, filter } from 'rxjs/operators';
+import { map, switchMap, startWith } from 'rxjs/operators';
import { uniqBy } from 'lodash';
import { convertError } from '../utilities/rxjs';
-import { dataStorage, throwIfNotNetworkError } from './common';
+import { dataStorage, throwIfNotNetworkError, BlobOrStatus } from './common';
import { DataHub, WithSyncStatus } from './DataHub';
import { UserAuthInfo, checkLogin, userService, userInfoService } from './user';
@@ -43,7 +43,7 @@ export type TimelinePostTextContent = HttpTimelinePostTextContent; export interface TimelinePostImageContent {
type: 'image';
- data: Blob;
+ data: BlobOrStatus;
}
export type TimelinePostContent =
@@ -481,10 +481,10 @@ export class TimelineService { },
});
- getPostData$(timelineName: string, postId: number): Observable<Blob> {
+ getPostData$(timelineName: string, postId: number): Observable<BlobOrStatus> {
return this._postDataHub.getObservable({ timelineName, postId }).pipe(
- map((state) => state.data),
- filter((blob): blob is Blob => blob != null)
+ map((state): BlobOrStatus => state.data ?? 'error'),
+ startWith('loading')
);
}
|