diff options
author | crupest <crupest@outlook.com> | 2020-07-27 23:27:56 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-07-27 23:27:56 +0800 |
commit | d3085ff3483c063b07b9553b539f3836b666cac8 (patch) | |
tree | d5fb93d26ad1e0a2997b6907c3918e49913996f8 | |
parent | 0863e0d139f12c444a2a01bb899bc3148c52e7ce (diff) | |
download | timeline-d3085ff3483c063b07b9553b539f3836b666cac8.tar.gz timeline-d3085ff3483c063b07b9553b539f3836b666cac8.tar.bz2 timeline-d3085ff3483c063b07b9553b539f3836b666cac8.zip |
Add timeline post list state.
-rw-r--r-- | Timeline/ClientApp/src/app/data/timeline.ts | 43 |
1 files changed, 31 insertions, 12 deletions
diff --git a/Timeline/ClientApp/src/app/data/timeline.ts b/Timeline/ClientApp/src/app/data/timeline.ts index 7ade8f56..ab01c86c 100644 --- a/Timeline/ClientApp/src/app/data/timeline.ts +++ b/Timeline/ClientApp/src/app/data/timeline.ts @@ -62,6 +62,15 @@ export interface PostKey { postId: number;
}
+export interface TimelinePostListState {
+ state:
+ | 'loading' // Loading posts from cache. `posts` is empty array.
+ | 'syncing' // Cache loaded and syncing now.
+ | 'synced' // Sync succeeded.
+ | 'offline'; // Sync failed and use cache.
+ posts: TimelinePostInfo[];
+}
+
export class TimelineService {
getTimeline(timelineName: string): Observable<TimelineInfo> {
return from(getHttpTimelineClient().getTimeline(timelineName)).pipe(
@@ -128,24 +137,34 @@ export class TimelineService { private _postListSubscriptionHub = new SubscriptionHub<
string,
- TimelinePostInfo[]
+ TimelinePostListState
>(
(key) => key,
- () => [],
+ () => ({
+ state: 'loading',
+ posts: [],
+ }),
async (key) => {
- return (
- await getHttpTimelineClient().listPost(
- key,
- userService.currentUser?.token
- )
- ).map((post) => ({
- ...post,
- timelineName: key,
- }));
+ // TODO: Implement cache
+ return {
+ state: 'synced',
+ posts: (
+ await getHttpTimelineClient().listPost(
+ key,
+ userService.currentUser?.token
+ )
+ ).map((post) => ({
+ ...post,
+ timelineName: key,
+ })),
+ };
}
);
- get postListSubscriptionHub(): ISubscriptionHub<string, TimelinePostInfo[]> {
+ get postListSubscriptionHub(): ISubscriptionHub<
+ string,
+ TimelinePostListState
+ > {
return this._postListSubscriptionHub;
}
|