aboutsummaryrefslogtreecommitdiff
path: root/Timeline/ClientApp/src/app/data
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
commit8dd3bc0ac8c7035edec7974e76f4e49d7e401ab5 (patch)
tree399bd008f98af8948309a3e4fa55464a478383bc /Timeline/ClientApp/src/app/data
parent20ad3b9558dd559ab5041197e760c03ae5302688 (diff)
downloadtimeline-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')
-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),
+ });
+ });
+ })
);
}