diff options
| author | crupest <crupest@outlook.com> | 2020-07-31 00:14:32 +0800 | 
|---|---|---|
| committer | crupest <crupest@outlook.com> | 2020-07-31 00:14:32 +0800 | 
| commit | 8dd3bc0ac8c7035edec7974e76f4e49d7e401ab5 (patch) | |
| tree | 399bd008f98af8948309a3e4fa55464a478383bc /Timeline/ClientApp/src/app/data/timeline.ts | |
| parent | 20ad3b9558dd559ab5041197e760c03ae5302688 (diff) | |
| download | timeline-8dd3bc0ac8c7035edec7974e76f4e49d7e401ab5.tar.gz timeline-8dd3bc0ac8c7035edec7974e76f4e49d7e401ab5.tar.bz2 timeline-8dd3bc0ac8c7035edec7974e76f4e49d7e401ab5.zip  | |
Update post list when create or delete post.
Diffstat (limited to 'Timeline/ClientApp/src/app/data/timeline.ts')
| -rw-r--r-- | Timeline/ClientApp/src/app/data/timeline.ts | 23 | 
1 files changed, 21 insertions, 2 deletions
diff --git a/Timeline/ClientApp/src/app/data/timeline.ts b/Timeline/ClientApp/src/app/data/timeline.ts index 88a13381..84eb3764 100644 --- a/Timeline/ClientApp/src/app/data/timeline.ts +++ b/Timeline/ClientApp/src/app/data/timeline.ts @@ -450,14 +450,33 @@ export class TimelineService {    ): Observable<TimelinePostInfo> {
      const user = checkLogin();
      return from(
 -      getHttpTimelineClient().postPost(timelineName, request, user.token)
 +      getHttpTimelineClient()
 +        .postPost(timelineName, request, user.token)
 +        .then((res) => {
 +          this._postListSubscriptionHub.update(timelineName, (_, old) => {
 +            return Promise.resolve({
 +              ...old,
 +              posts: [...old.posts, { ...res, timelineName }],
 +            });
 +          });
 +          return res;
 +        })
      ).pipe(map((post) => ({ ...post, timelineName })));
    }
    deletePost(timelineName: string, postId: number): Observable<unknown> {
      const user = checkLogin();
      return from(
 -      getHttpTimelineClient().deletePost(timelineName, postId, user.token)
 +      getHttpTimelineClient()
 +        .deletePost(timelineName, postId, user.token)
 +        .then(() => {
 +          this._postListSubscriptionHub.update(timelineName, (_, old) => {
 +            return Promise.resolve({
 +              ...old,
 +              posts: old.posts.filter((post) => post.id != postId),
 +            });
 +          });
 +        })
      );
    }
  | 
