Skip to content

Commit 896e0b1

Browse files
authored
Merge pull request #32 from codeforjapan/refactor/show-x-url-without-post
refactor: build x url without post
2 parents 8667fa9 + 4721472 commit 896e0b1

File tree

3 files changed

+39
-22
lines changed

3 files changed

+39
-22
lines changed

app/components/note/Note.tsx

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import { Badge, Button, Card, Group, Stack, Text } from "@mantine/core";
22
import { useMemo } from "react";
33

44
import { LANGUAGE_ID_TO_LABEL } from "../../feature/search/language";
5+
import {
6+
birdWatchLinkFromPostId,
7+
postLinkFromPostId,
8+
} from "../../feature/twitter/link-builder";
59
import type { SearchedNote } from "../../generated/api/schemas";
10+
import { isNonEmptyString } from "../../utils/string";
611
import { Post } from "../post/Post";
712
import { NoteStatus } from "./NoteStatus";
813
import { NoteTopic } from "./NoteTopics";
@@ -56,28 +61,30 @@ export const Note = ({ note }: NoteProps) => {
5661
</div>
5762
</Stack>
5863
<Post post={note.post} />
59-
<Group justify="flex-end">
60-
<Button
61-
color="pink"
62-
component="a"
63-
href={note.post.link}
64-
size="xs"
65-
target="_blank"
66-
variant="light"
67-
>
68-
ポストを見る
69-
</Button>
70-
<Button
71-
color="pink"
72-
component="a"
73-
href={`https://x.com/i/birdwatch/t/${note.post.postId}`}
74-
size="xs"
75-
target="_blank"
76-
variant="light"
77-
>
78-
このポストについたノートを見る
79-
</Button>
80-
</Group>
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+
)}
8188
</Stack>
8289
</Card>
8390
);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export const birdWatchLinkFromPostId = (postId: string): string => {
2+
return `https://x.com/i/birdwatch/t/${postId}`;
3+
};
4+
5+
export const postLinkFromPostId = (postId: string): string => {
6+
// X redirects to correct post url regardless of userId, so just specify `i`
7+
return `https://x.com/i/status/${postId}`;
8+
};

app/utils/string.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const isNonEmptyString = (value?: unknown): value is string =>
2+
typeof value === "string" && value !== "";

0 commit comments

Comments
 (0)