From 8dd3bc0ac8c7035edec7974e76f4e49d7e401ab5 Mon Sep 17 00:00:00 2001 From: crupest Date: Fri, 31 Jul 2020 00:14:32 +0800 Subject: Update post list when create or delete post. --- Timeline/ClientApp/src/app/data/timeline.ts | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'Timeline/ClientApp/src/app/data/timeline.ts') 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 { 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 { 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), + }); + }); + }) ); } -- cgit v1.2.3