diff options
Diffstat (limited to 'Timeline/ClientApp/src/app/timeline/TimelinePageTemplateUI.tsx')
-rw-r--r-- | Timeline/ClientApp/src/app/timeline/TimelinePageTemplateUI.tsx | 104 |
1 files changed, 90 insertions, 14 deletions
diff --git a/Timeline/ClientApp/src/app/timeline/TimelinePageTemplateUI.tsx b/Timeline/ClientApp/src/app/timeline/TimelinePageTemplateUI.tsx index 4b3b3096..dc5bfda8 100644 --- a/Timeline/ClientApp/src/app/timeline/TimelinePageTemplateUI.tsx +++ b/Timeline/ClientApp/src/app/timeline/TimelinePageTemplateUI.tsx @@ -1,13 +1,21 @@ -import React from 'react';
+import React, { CSSProperties } from 'react';
import { Spinner } from 'reactstrap';
import { useTranslation } from 'react-i18next';
import { fromEvent } from 'rxjs';
import Svg from 'react-inlinesvg';
+import clsx from 'clsx';
import arrowsAngleContractIcon from 'bootstrap-icons/icons/arrows-angle-contract.svg';
import arrowsAngleExpandIcon from 'bootstrap-icons/icons/arrows-angle-expand.svg';
import { getAlertHost } from '../common/alert-service';
+import { useEventEmiiter, UiLogicError } from '../common';
+import {
+ TimelineInfo,
+ TimelinePostListState,
+ timelineService,
+} from '../data/timeline';
+import { userService } from '../data/user';
import Timeline, {
TimelinePostInfoEx,
@@ -15,8 +23,55 @@ import Timeline, { } from './Timeline';
import AppBar from '../common/AppBar';
import TimelinePostEdit, { TimelinePostSendCallback } from './TimelinePostEdit';
-import { useEventEmiiter } from '../common';
-import { TimelineInfo } from '../data/timeline';
+
+const TimelinePostSyncStateBadge: React.FC<{
+ state: 'syncing' | 'synced' | 'offline';
+ style?: CSSProperties;
+ className?: string;
+}> = ({ state, style, className }) => {
+ const { t } = useTranslation();
+
+ return (
+ <div style={style} className={clsx('timeline-sync-state-badge', className)}>
+ {(() => {
+ switch (state) {
+ case 'syncing': {
+ return (
+ <>
+ <span className="timeline-sync-state-badge-pin bg-warning" />
+ <span className="text-warning">
+ {t('timeline.postSyncState.syncing')}
+ </span>
+ </>
+ );
+ }
+ case 'synced': {
+ return (
+ <>
+ <span className="timeline-sync-state-badge-pin bg-success" />
+ <span className="text-success">
+ {t('timeline.postSyncState.synced')}
+ </span>
+ </>
+ );
+ }
+ case 'offline': {
+ return (
+ <>
+ <span className="timeline-sync-state-badge-pin bg-danger" />
+ <span className="text-danger">
+ {t('timeline.postSyncState.offline')}
+ </span>
+ </>
+ );
+ }
+ default:
+ throw new UiLogicError('Unknown sync state.');
+ }
+ })()}
+ </div>
+ );
+};
export interface TimelineCardComponentProps<TManageItems> {
timeline: TimelineInfo;
@@ -29,7 +84,7 @@ export interface TimelineCardComponentProps<TManageItems> { export interface TimelinePageTemplateUIProps<TManageItems> {
avatarKey?: string | number;
timeline?: TimelineInfo;
- posts?: TimelinePostInfoEx[] | 'forbid';
+ postListState?: TimelinePostListState;
CardComponent: React.ComponentType<TimelineCardComponentProps<TManageItems>>;
onMember: () => void;
onManage?: (item: TManageItems | 'property') => void;
@@ -41,7 +96,7 @@ export interface TimelinePageTemplateUIProps<TManageItems> { export default function TimelinePageTemplateUI<TManageItems>(
props: TimelinePageTemplateUIProps<TManageItems>
): React.ReactElement | null {
- const { timeline } = props;
+ const { timeline, postListState } = props;
const { t } = useTranslation();
@@ -116,7 +171,7 @@ export default function TimelinePageTemplateUI<TManageItems>( subscriptions.forEach((s) => s.unsubscribe());
};
}
- }, [getResizeEvent, triggerResizeEvent, timeline, props.posts]);
+ }, [getResizeEvent, triggerResizeEvent, timeline, postListState]);
const [cardHeight, setCardHeight] = React.useState<number>(0);
@@ -142,19 +197,40 @@ export default function TimelinePageTemplateUI<TManageItems>( } else {
if (timeline != null) {
let timelineBody: React.ReactElement;
- if (props.posts != null) {
- if (props.posts === 'forbid') {
+ if (postListState != null && postListState.state !== 'loading') {
+ if (postListState.state === 'forbid') {
timelineBody = (
<p className="text-danger">{t('timeline.messageCantSee')}</p>
);
} else {
+ const posts: TimelinePostInfoEx[] = postListState.posts.map(
+ (post) => ({
+ ...post,
+ deletable: timelineService.hasModifyPostPermission(
+ userService.currentUser,
+ timeline,
+ post
+ ),
+ })
+ );
+
+ const topHeight: string = infoCardCollapse
+ ? 'calc(68px + 1.5em)'
+ : `${cardHeight + 60}px`;
+
timelineBody = (
- <Timeline
- containerRef={timelineRef}
- posts={props.posts}
- onDelete={props.onDelete}
- onResize={triggerResizeEvent}
- />
+ <div>
+ <TimelinePostSyncStateBadge
+ style={{ top: topHeight }}
+ state={postListState.state}
+ />
+ <Timeline
+ containerRef={timelineRef}
+ posts={posts}
+ onDelete={props.onDelete}
+ onResize={triggerResizeEvent}
+ />
+ </div>
);
if (props.onPost != null) {
timelineBody = (
|