Skip to content

Commit

Permalink
Merge pull request #32 from codeforjapan/refactor/show-x-url-without-…
Browse files Browse the repository at this point in the history
…post

refactor: build x url without post
  • Loading branch information
yu23ki14 authored Mar 9, 2025
2 parents 8667fa9 + 4721472 commit 896e0b1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 22 deletions.
51 changes: 29 additions & 22 deletions app/components/note/Note.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { Badge, Button, Card, Group, Stack, Text } from "@mantine/core";
import { useMemo } from "react";

import { LANGUAGE_ID_TO_LABEL } from "../../feature/search/language";
import {
birdWatchLinkFromPostId,
postLinkFromPostId,
} from "../../feature/twitter/link-builder";
import type { SearchedNote } from "../../generated/api/schemas";
import { isNonEmptyString } from "../../utils/string";
import { Post } from "../post/Post";
import { NoteStatus } from "./NoteStatus";
import { NoteTopic } from "./NoteTopics";
Expand Down Expand Up @@ -56,28 +61,30 @@ export const Note = ({ note }: NoteProps) => {
</div>
</Stack>
<Post post={note.post} />
<Group justify="flex-end">
<Button
color="pink"
component="a"
href={note.post.link}
size="xs"
target="_blank"
variant="light"
>
ポストを見る
</Button>
<Button
color="pink"
component="a"
href={`https://x.com/i/birdwatch/t/${note.post.postId}`}
size="xs"
target="_blank"
variant="light"
>
このポストについたノートを見る
</Button>
</Group>
{isNonEmptyString(note.postId) && (
<Group justify="flex-end">
<Button
color="pink"
component="a"
href={postLinkFromPostId(note.postId)}
size="xs"
target="_blank"
variant="light"
>
ポストを見る
</Button>
<Button
color="pink"
component="a"
href={birdWatchLinkFromPostId(note.postId)}
size="xs"
target="_blank"
variant="light"
>
このポストについたノートを見る
</Button>
</Group>
)}
</Stack>
</Card>
);
Expand Down
8 changes: 8 additions & 0 deletions app/feature/twitter/link-builder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const birdWatchLinkFromPostId = (postId: string): string => {
return `https://x.com/i/birdwatch/t/${postId}`;
};

export const postLinkFromPostId = (postId: string): string => {
// X redirects to correct post url regardless of userId, so just specify `i`
return `https://x.com/i/status/${postId}`;
};
2 changes: 2 additions & 0 deletions app/utils/string.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const isNonEmptyString = (value?: unknown): value is string =>
typeof value === "string" && value !== "";

0 comments on commit 896e0b1

Please sign in to comment.