diff options
author | crupest <crupest@outlook.com> | 2021-02-20 15:19:58 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-02-20 15:25:52 +0800 |
commit | d83b2752de6fe465f9589efbcf7fd46e16bdb2cc (patch) | |
tree | e81138e85c33ffc9195e0e75c9ab31ebf44efc44 /FrontEnd/src/app/views/timeline-common/TimelinePageCardTemplate.tsx | |
parent | 1d3f97912b40f84a3ef826b3b8b39b74cb35c2f9 (diff) | |
download | timeline-d83b2752de6fe465f9589efbcf7fd46e16bdb2cc.tar.gz timeline-d83b2752de6fe465f9589efbcf7fd46e16bdb2cc.tar.bz2 timeline-d83b2752de6fe465f9589efbcf7fd46e16bdb2cc.zip |
fix: Fix reload logic.
Diffstat (limited to 'FrontEnd/src/app/views/timeline-common/TimelinePageCardTemplate.tsx')
-rw-r--r-- | FrontEnd/src/app/views/timeline-common/TimelinePageCardTemplate.tsx | 61 |
1 files changed, 20 insertions, 41 deletions
diff --git a/FrontEnd/src/app/views/timeline-common/TimelinePageCardTemplate.tsx b/FrontEnd/src/app/views/timeline-common/TimelinePageCardTemplate.tsx index 49cbe791..13b823bf 100644 --- a/FrontEnd/src/app/views/timeline-common/TimelinePageCardTemplate.tsx +++ b/FrontEnd/src/app/views/timeline-common/TimelinePageCardTemplate.tsx @@ -49,21 +49,6 @@ const TimelinePageCardTemplate: React.FC<TimelineCardTemplateProps> = ({ }) => { const { t } = useTranslation(); - const [overrideIsHighlight, setOverrideIsHighlight] = React.useState< - boolean | null - >(null); - const [overrideIsBookmark, setOverrideIsBookmark] = React.useState< - boolean | null - >(null); - - const isHighlight = overrideIsHighlight ?? timeline.isHighlight; - const isBookmark = overrideIsBookmark ?? timeline.isBookmark; - - React.useEffect(() => { - setOverrideIsHighlight(null); - setOverrideIsBookmark(null); - }, [timeline]); - const user = useUser(); return ( @@ -81,25 +66,22 @@ const TimelinePageCardTemplate: React.FC<TimelineCardTemplateProps> = ({ <div className="text-right mt-2"> <i className={clsx( - isHighlight ? "bi-star-fill" : "bi-star", + timeline.isHighlight ? "bi-star-fill" : "bi-star", "icon-button text-yellow mr-3" )} onClick={ user?.hasHighlightTimelineAdministrationPermission ? () => { getHttpHighlightClient() - [isHighlight ? "delete" : "put"](timeline.name) - .then( - () => setOverrideIsHighlight(!isHighlight), - () => { - pushAlert({ - message: timeline.isHighlight - ? "timeline.removeHighlightFail" - : "timeline.addHighlightFail", - type: "danger", - }); - } - ); + [timeline.isHighlight ? "delete" : "put"](timeline.name) + .then(onReload, () => { + pushAlert({ + message: timeline.isHighlight + ? "timeline.removeHighlightFail" + : "timeline.addHighlightFail", + type: "danger", + }); + }); } : undefined } @@ -107,23 +89,20 @@ const TimelinePageCardTemplate: React.FC<TimelineCardTemplateProps> = ({ {user != null ? ( <i className={clsx( - isBookmark ? "bi-bookmark-fill" : "bi-bookmark", + timeline.isBookmark ? "bi-bookmark-fill" : "bi-bookmark", "icon-button text-yellow mr-3" )} onClick={() => { getHttpBookmarkClient() - [isBookmark ? "delete" : "put"](timeline.name) - .then( - () => setOverrideIsBookmark(!isBookmark), - () => { - pushAlert({ - message: timeline.isBookmark - ? "timeline.removeBookmarkFail" - : "timeline.addBookmarkFail", - type: "danger", - }); - } - ); + [timeline.isBookmark ? "delete" : "put"](timeline.name) + .then(onReload, () => { + pushAlert({ + message: timeline.isBookmark + ? "timeline.removeBookmarkFail" + : "timeline.addBookmarkFail", + type: "danger", + }); + }); }} /> ) : null} |