From 079bb671af79f7211a8fc25454eb6591d759d85f Mon Sep 17 00:00:00 2001
From: crupest <crupest@outlook.com>
Date: Sat, 9 Jan 2021 01:13:29 +0800
Subject: ...

---
 .../views/timeline-common/TimelinePageTemplate.tsx | 78 ++++++++--------------
 1 file changed, 28 insertions(+), 50 deletions(-)

(limited to 'FrontEnd/src/app/views/timeline-common/TimelinePageTemplate.tsx')

diff --git a/FrontEnd/src/app/views/timeline-common/TimelinePageTemplate.tsx b/FrontEnd/src/app/views/timeline-common/TimelinePageTemplate.tsx
index caced3b7..e0ad002a 100644
--- a/FrontEnd/src/app/views/timeline-common/TimelinePageTemplate.tsx
+++ b/FrontEnd/src/app/views/timeline-common/TimelinePageTemplate.tsx
@@ -121,57 +121,35 @@ export default function TimelinePageTemplate<TManageItem>(
           onBookmark:
             user != null
               ? () => {
-                  if (timeline.isBookmark) {
-                    setTimelineState({
-                      ...timelineState,
-                      timeline: {
-                        ...timeline,
-                        isBookmark: false,
-                      },
-                    });
-                    void getHttpBookmarkClient()
-                      .delete(name)
-                      .then(
-                        () => {
-                          void timelineService.syncTimeline(name);
-                        },
-                        () => {
-                          pushAlert({
-                            message: {
-                              type: "i18n",
-                              key: "timeline.removeBookmarkFail",
-                            },
-                            type: "danger",
-                          });
-                          setTimelineState(timelineState);
-                        }
-                      );
-                  } else {
-                    setTimelineState({
-                      ...timelineState,
-                      timeline: {
-                        ...timeline,
-                        isBookmark: true,
-                      },
-                    });
-                    void getHttpBookmarkClient()
-                      .put(name)
-                      .then(
-                        () => {
-                          void timelineService.syncTimeline(name);
+                  const { isBookmark } = timeline;
+                  setTimelineState({
+                    ...timelineState,
+                    timeline: {
+                      ...timeline,
+                      isBookmark: !isBookmark,
+                    },
+                  });
+                  const client = getHttpBookmarkClient();
+                  const promise = isBookmark
+                    ? client.delete(name)
+                    : client.put(name);
+                  promise.then(
+                    () => {
+                      void timelineService.syncTimeline(name);
+                    },
+                    () => {
+                      pushAlert({
+                        message: {
+                          type: "i18n",
+                          key: isBookmark
+                            ? "timeline.removeBookmarkFail"
+                            : "timeline.addBookmarkFail", // TODO: Add this translation.
                         },
-                        () => {
-                          pushAlert({
-                            message: {
-                              type: "i18n",
-                              key: "timeline.addBookmarkFail",
-                            },
-                            type: "danger",
-                          });
-                          setTimelineState(timelineState);
-                        }
-                      );
-                  }
+                        type: "danger",
+                      });
+                      setTimelineState(timelineState);
+                    }
+                  );
                 }
               : undefined,
           onHighlight:
-- 
cgit v1.2.3

