diff options
author | crupest <crupest@outlook.com> | 2021-01-09 01:13:29 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-01-09 01:13:29 +0800 |
commit | 079bb671af79f7211a8fc25454eb6591d759d85f (patch) | |
tree | 2a0fd81ade9154e769380e0daa700973f6649704 /FrontEnd/src | |
parent | 3da3793282a2bb50f7f3e39fbe08efee7582743b (diff) | |
download | timeline-079bb671af79f7211a8fc25454eb6591d759d85f.tar.gz timeline-079bb671af79f7211a8fc25454eb6591d759d85f.tar.bz2 timeline-079bb671af79f7211a8fc25454eb6591d759d85f.zip |
...
Diffstat (limited to 'FrontEnd/src')
-rw-r--r-- | FrontEnd/src/app/views/timeline-common/TimelinePageTemplate.tsx | 78 |
1 files changed, 28 insertions, 50 deletions
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: |