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 | 9e500f240a76bd0e16c8c63b764dd81c01f46f78 (patch) | |
tree | ac0900fbc185e0ceb859ae80b2ed81b42011c6e7 /Timeline/ClientApp/src/app/data/timeline.ts | |
parent | 5a90a7d0de9ae8410ef8c23a6994fdba7657666d (diff) | |
download | timeline-9e500f240a76bd0e16c8c63b764dd81c01f46f78.tar.gz timeline-9e500f240a76bd0e16c8c63b764dd81c01f46f78.tar.bz2 timeline-9e500f240a76bd0e16c8c63b764dd81c01f46f78.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),
+ });
+ });
+ })
);
}
|