From f737fed4f003fbeb7187629a7b730c64a87b72b9 Mon Sep 17 00:00:00 2001 From: crupest Date: Wed, 17 Jun 2020 14:51:33 +0800 Subject: refactor(front): Fix #104 . --- Timeline/ClientApp/src/app/data/timeline.ts | 1 + .../ClientApp/src/app/timeline/TimelinePageTemplateUI.tsx | 14 +++++++------- Timeline/ClientApp/src/app/timeline/TimelinePostEdit.tsx | 4 ++-- 3 files changed, 10 insertions(+), 9 deletions(-) (limited to 'Timeline/ClientApp') diff --git a/Timeline/ClientApp/src/app/data/timeline.ts b/Timeline/ClientApp/src/app/data/timeline.ts index 19bb3d45..a8875701 100644 --- a/Timeline/ClientApp/src/app/data/timeline.ts +++ b/Timeline/ClientApp/src/app/data/timeline.ts @@ -20,6 +20,7 @@ export const timelineVisibilityTooltipTranslationMap: Record< }; export interface TimelineInfo { + uniqueId: string; name: string; description: string; owner: User; diff --git a/Timeline/ClientApp/src/app/timeline/TimelinePageTemplateUI.tsx b/Timeline/ClientApp/src/app/timeline/TimelinePageTemplateUI.tsx index 66935e00..924e7883 100644 --- a/Timeline/ClientApp/src/app/timeline/TimelinePageTemplateUI.tsx +++ b/Timeline/ClientApp/src/app/timeline/TimelinePageTemplateUI.tsx @@ -26,7 +26,7 @@ export interface TimelineCardComponentProps { } export interface TimelinePageTemplateUIProps< - TTimeline extends { name: string }, + TTimeline extends { uniqueId: string }, TManageItems > { avatarKey?: string | number; @@ -43,7 +43,7 @@ export interface TimelinePageTemplateUIProps< } export default function TimelinePageTemplateUI< - TTimeline extends { name: string }, + TTimeline extends { uniqueId: string }, TEditItems >( props: TimelinePageTemplateUIProps @@ -127,11 +127,11 @@ export default function TimelinePageTemplateUI< const [cardHeight, setCardHeight] = React.useState(0); - const genCardCollapseLocalStorageKey = (timelineName: string): string => - `timeline.${timelineName}.cardCollapse`; + const genCardCollapseLocalStorageKey = (uniqueId: string): string => + `timeline.${uniqueId}.cardCollapse`; const cardCollapseLocalStorageKey = - timeline != null ? genCardCollapseLocalStorageKey(timeline.name) : null; + timeline != null ? genCardCollapseLocalStorageKey(timeline.uniqueId) : null; const [infoCardCollapse, setInfoCardCollapse] = React.useState(true); React.useEffect(() => { @@ -171,7 +171,7 @@ export default function TimelinePageTemplateUI< ); @@ -202,7 +202,7 @@ export default function TimelinePageTemplateUI< const newState = !infoCardCollapse; setInfoCardCollapse(newState); window.localStorage.setItem( - genCardCollapseLocalStorageKey(timeline.name), + genCardCollapseLocalStorageKey(timeline.uniqueId), newState.toString() ); }} diff --git a/Timeline/ClientApp/src/app/timeline/TimelinePostEdit.tsx b/Timeline/ClientApp/src/app/timeline/TimelinePostEdit.tsx index d1c09036..894d6ad4 100644 --- a/Timeline/ClientApp/src/app/timeline/TimelinePostEdit.tsx +++ b/Timeline/ClientApp/src/app/timeline/TimelinePostEdit.tsx @@ -86,7 +86,7 @@ export interface TimelinePostEditProps { className?: string; onPost: TimelinePostSendCallback; onHeightChange?: (height: number) => void; - timelineName: string; + timelineUniqueId: string; } const TimelinePostEdit: React.FC = (props) => { @@ -99,7 +99,7 @@ const TimelinePostEdit: React.FC = (props) => { const [text, setText] = React.useState(''); const [imageBlob, setImageBlob] = React.useState(null); - const draftLocalStorageKey = `timeline.${props.timelineName}.postDraft`; + const draftLocalStorageKey = `timeline.${props.timelineUniqueId}.postDraft`; React.useEffect(() => { setText(window.localStorage.getItem(draftLocalStorageKey) ?? ''); -- cgit v1.2.3