aboutsummaryrefslogtreecommitdiff
path: root/Timeline/ClientApp/src/app/data/timeline.ts
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-07-31 00:14:32 +0800
committercrupest <crupest@outlook.com>2020-07-31 00:14:32 +0800
commit9e500f240a76bd0e16c8c63b764dd81c01f46f78 (patch)
treeac0900fbc185e0ceb859ae80b2ed81b42011c6e7 /Timeline/ClientApp/src/app/data/timeline.ts
parent5a90a7d0de9ae8410ef8c23a6994fdba7657666d (diff)
downloadtimeline-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.ts23
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),
+ });
+ });
+ })
);
}