From c3cf26a7788d97135e0f2a3e247e6cbe6b1b9664 Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 19 Jan 2021 16:23:27 +0800 Subject: ... --- FrontEnd/src/app/views/timeline-common/Timeline.tsx | 16 +++++++++++++--- .../app/views/timeline-common/TimelinePageTemplate.tsx | 11 ----------- .../app/views/timeline-common/TimelinePageTemplateUI.tsx | 7 +------ 3 files changed, 14 insertions(+), 20 deletions(-) (limited to 'FrontEnd/src') diff --git a/FrontEnd/src/app/views/timeline-common/Timeline.tsx b/FrontEnd/src/app/views/timeline-common/Timeline.tsx index 2446c0dd..288be141 100644 --- a/FrontEnd/src/app/views/timeline-common/Timeline.tsx +++ b/FrontEnd/src/app/views/timeline-common/Timeline.tsx @@ -6,11 +6,12 @@ import { TimelinePostInfo, timelineService, } from "@/services/timeline"; +import { useUser } from "@/services/user"; +import { pushAlert } from "@/services/alert"; import TimelineItem from "./TimelineItem"; import TimelineTop from "./TimelineTop"; import TimelineDateItem from "./TimelineDateItem"; -import { useUser } from "@/services/user"; function dateEqual(left: Date, right: Date): boolean { return ( @@ -25,7 +26,6 @@ export interface TimelineProps { style?: React.CSSProperties; timeline: TimelineInfo; posts: TimelinePostInfo[]; - onDelete: (post: TimelinePostInfo) => void; } const Timeline: React.FC = (props) => { @@ -87,7 +87,17 @@ const Timeline: React.FC = (props) => { old === post.index ? -1 : post.index ), onDelete: () => { - props.onDelete(post); + timelineService + .deletePost(timeline.name, post.id) + .catch(() => { + pushAlert({ + type: "danger", + message: { + type: "i18n", + key: "timeline.deletePostFailed", + }, + }); + }); }, } : undefined diff --git a/FrontEnd/src/app/views/timeline-common/TimelinePageTemplate.tsx b/FrontEnd/src/app/views/timeline-common/TimelinePageTemplate.tsx index da020be4..bff4547e 100644 --- a/FrontEnd/src/app/views/timeline-common/TimelinePageTemplate.tsx +++ b/FrontEnd/src/app/views/timeline-common/TimelinePageTemplate.tsx @@ -1,5 +1,4 @@ import React from "react"; -import { useTranslation } from "react-i18next"; import { UiLogicError } from "@/common"; import { pushAlert } from "@/services/alert"; @@ -31,8 +30,6 @@ export interface TimelinePageTemplateProps { export default function TimelinePageTemplate( props: TimelinePageTemplateProps ): React.ReactElement | null { - const { t } = useTranslation(); - const { name } = props; const service = timelineService; @@ -87,14 +84,6 @@ export default function TimelinePageTemplate( return "notexist"; } else { const operations: TimelinePageTemplateUIOperations = { - onDeletePost: (post) => { - service.deletePost(name, post.id).catch(() => { - pushAlert({ - type: "danger", - message: t("timeline.deletePostFailed"), - }); - }); - }, onPost: service.hasPostPermission(user, timeline) ? (req) => service.createPost(name, req).then(() => scrollToBottomNextSync()) diff --git a/FrontEnd/src/app/views/timeline-common/TimelinePageTemplateUI.tsx b/FrontEnd/src/app/views/timeline-common/TimelinePageTemplateUI.tsx index 815906d3..dbb47387 100644 --- a/FrontEnd/src/app/views/timeline-common/TimelinePageTemplateUI.tsx +++ b/FrontEnd/src/app/views/timeline-common/TimelinePageTemplateUI.tsx @@ -24,7 +24,6 @@ export interface TimelineCardComponentProps { } export interface TimelinePageTemplateUIOperations { - onDeletePost: (post: TimelinePostInfo) => void; onManage?: (item: TManageItems | "property") => void; onMember: () => void; onBookmark?: () => void; @@ -129,11 +128,7 @@ export default function TimelinePageTemplateUI( minHeight: `calc(100vh - ${56 + bottomSpaceHeight}px)`, }} > - + ) ) : ( -- cgit v1.2.3