From 8dd3bc0ac8c7035edec7974e76f4e49d7e401ab5 Mon Sep 17 00:00:00 2001 From: crupest Date: Fri, 31 Jul 2020 00:14:32 +0800 Subject: Update post list when create or delete post. --- .../src/app/timeline/TimelinePageTemplateUI.tsx | 32 ++++++++++++++++------ 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'Timeline/ClientApp/src/app/timeline/TimelinePageTemplateUI.tsx') diff --git a/Timeline/ClientApp/src/app/timeline/TimelinePageTemplateUI.tsx b/Timeline/ClientApp/src/app/timeline/TimelinePageTemplateUI.tsx index 4b3b3096..3c8e312c 100644 --- a/Timeline/ClientApp/src/app/timeline/TimelinePageTemplateUI.tsx +++ b/Timeline/ClientApp/src/app/timeline/TimelinePageTemplateUI.tsx @@ -8,6 +8,13 @@ import arrowsAngleContractIcon from 'bootstrap-icons/icons/arrows-angle-contract import arrowsAngleExpandIcon from 'bootstrap-icons/icons/arrows-angle-expand.svg'; import { getAlertHost } from '../common/alert-service'; +import { useEventEmiiter } from '../common'; +import { + TimelineInfo, + TimelinePostListState, + timelineService, +} from '../data/timeline'; +import { userService } from '../data/user'; import Timeline, { TimelinePostInfoEx, @@ -15,8 +22,6 @@ import Timeline, { } from './Timeline'; import AppBar from '../common/AppBar'; import TimelinePostEdit, { TimelinePostSendCallback } from './TimelinePostEdit'; -import { useEventEmiiter } from '../common'; -import { TimelineInfo } from '../data/timeline'; export interface TimelineCardComponentProps { timeline: TimelineInfo; @@ -29,7 +34,7 @@ export interface TimelineCardComponentProps { export interface TimelinePageTemplateUIProps { avatarKey?: string | number; timeline?: TimelineInfo; - posts?: TimelinePostInfoEx[] | 'forbid'; + postListState?: TimelinePostListState; CardComponent: React.ComponentType>; onMember: () => void; onManage?: (item: TManageItems | 'property') => void; @@ -41,7 +46,7 @@ export interface TimelinePageTemplateUIProps { export default function TimelinePageTemplateUI( props: TimelinePageTemplateUIProps ): React.ReactElement | null { - const { timeline } = props; + const { timeline, postListState } = props; const { t } = useTranslation(); @@ -116,7 +121,7 @@ export default function TimelinePageTemplateUI( subscriptions.forEach((s) => s.unsubscribe()); }; } - }, [getResizeEvent, triggerResizeEvent, timeline, props.posts]); + }, [getResizeEvent, triggerResizeEvent, timeline, postListState]); const [cardHeight, setCardHeight] = React.useState(0); @@ -142,16 +147,27 @@ export default function TimelinePageTemplateUI( } else { if (timeline != null) { let timelineBody: React.ReactElement; - if (props.posts != null) { - if (props.posts === 'forbid') { + if (postListState != null) { + if (postListState.state === 'forbid') { timelineBody = (

{t('timeline.messageCantSee')}

); } else { + const posts: TimelinePostInfoEx[] = postListState.posts.map( + (post) => ({ + ...post, + deletable: timelineService.hasModifyPostPermission( + userService.currentUser, + timeline, + post + ), + }) + ); + timelineBody = ( -- cgit v1.2.3