Skip to content

Commit 4bb6e1e

Browse files
committed
docs: 型的には必要ない分岐が入っている理由を書く
1 parent 6044a64 commit 4bb6e1e

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

app/components/note/Note.tsx

+29-24
Original file line numberDiff line numberDiff line change
@@ -61,30 +61,35 @@ export const Note = ({ note }: NoteProps) => {
6161
</div>
6262
</Stack>
6363
<Post post={note.post} />
64-
{isNonEmptyString(note.postId) && (
65-
<Group justify="flex-end">
66-
<Button
67-
color="pink"
68-
component="a"
69-
href={postLinkFromPostId(note.postId)}
70-
size="xs"
71-
target="_blank"
72-
variant="light"
73-
>
74-
ポストを見る
75-
</Button>
76-
<Button
77-
color="pink"
78-
component="a"
79-
href={birdWatchLinkFromPostId(note.postId)}
80-
size="xs"
81-
target="_blank"
82-
variant="light"
83-
>
84-
このポストについたノートを見る
85-
</Button>
86-
</Group>
87-
)}
64+
{
65+
// ref: https://github.com/codeforjapan/BirdXplorer_Viewer/pull/32#discussion_r1978997326
66+
// API 側で Post 情報を非同期に取得する仕様変更が予定されているが、誤って postId が null になってしまう場合がありえるので
67+
// 予防的に分岐を入れている。Note.postId の存在が保証されている場合は分岐を削除して良い。
68+
isNonEmptyString(note.postId) && (
69+
<Group justify="flex-end">
70+
<Button
71+
color="pink"
72+
component="a"
73+
href={postLinkFromPostId(note.postId)}
74+
size="xs"
75+
target="_blank"
76+
variant="light"
77+
>
78+
ポストを見る
79+
</Button>
80+
<Button
81+
color="pink"
82+
component="a"
83+
href={birdWatchLinkFromPostId(note.postId)}
84+
size="xs"
85+
target="_blank"
86+
variant="light"
87+
>
88+
このポストについたノートを見る
89+
</Button>
90+
</Group>
91+
)
92+
}
8893
</Stack>
8994
</Card>
9095
);

0 commit comments

Comments
 (0)