Skip to content

Commit 82ad6b3

Browse files
committed
feat: replace tweets by toots
1 parent 06ff17f commit 82ad6b3

File tree

6 files changed

+486
-64
lines changed

6 files changed

+486
-64
lines changed

components/EmbeddedSocialMedia/EmbeddedSocialMedia.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { ITweets } from "../../lib/twitter/getTweets";
44
import { IPlaylistItem } from "../../lib/youtube-playlist/youtube-playlist.types";
55
import Playlist from "../Playlist/Playlist";
66
import TootCard from "../TootCard/TootCard";
7-
import TweetCard from "../TweetCard/TweetCard";
87
import styles from "./EmbeddedSocialMedia.module.scss";
98

109
interface EmbeddedSocialMediaProps {
@@ -15,13 +14,12 @@ interface EmbeddedSocialMediaProps {
1514

1615
const EmbeddedSocialMedia: FC<EmbeddedSocialMediaProps> = ({
1716
toots,
18-
tweets,
1917
playlist,
2018
}) => {
2119
return (
2220
<div className={styles["embedded-social-media"]}>
2321
<TootCard toots={toots} />
24-
<TweetCard tweets={tweets} />
22+
{/* <TweetCard tweets={tweets} /> */}
2523
<Playlist playlist={playlist} viewport="sm" />
2624
</div>
2725
);

components/TootCard/TootCard.module.scss

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
border-radius: $card-border-radius;
77
padding: 1rem;
88

9-
a {
9+
> a {
1010
display: block;
1111
text-align: right;
1212
font-weight: bold;
@@ -19,8 +19,19 @@
1919
gap: 10px;
2020
}
2121

22+
div > a {
23+
display: block;
24+
margin-bottom: 0.5rem;
25+
}
26+
2227
@media (min-width: $main-width) {
2328
display: block;
2429
width: $aside-width;
2530
}
2631
}
32+
33+
.toot-card--badges {
34+
display: flex;
35+
gap: 0.7rem;
36+
cursor: default;
37+
}

components/TootCard/TootCard.tsx

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,35 @@ const TootCard: FC<ITootCardProps> = ({ toots }) => {
1717
return (
1818
<section className={styles["toot-card"]}>
1919
<a href={author.url}>@{author.username}@mastodon.social</a>
20-
{data.map(({ id, text, created_at }) => (
21-
<div key={id}>
22-
<p>
23-
<Image
24-
src={mastodonSvg}
25-
alt="Codestar Mastodon"
26-
width={24}
27-
height={24}
28-
/>
29-
<span>{formatDate(created_at)}</span>
30-
</p>
31-
<p>{text}</p>
32-
</div>
33-
))}
20+
{data.map(
21+
({
22+
id,
23+
text,
24+
created_at,
25+
url,
26+
reblogs_count,
27+
replies_count,
28+
favourites_count,
29+
}) => (
30+
<div key={id}>
31+
<p>
32+
<Image
33+
src={mastodonSvg}
34+
alt="Codestar Mastodon"
35+
width={24}
36+
height={24}
37+
/>
38+
<span>{formatDate(created_at)}</span>
39+
</p>
40+
<a href={url}>{text}</a>
41+
<div className={styles["toot-card--badges"]}>
42+
<span title="replies">↩️ {replies_count}</span>{" "}
43+
<span title="reblogs">🔁 {reblogs_count}</span>{" "}
44+
<span title="favourites">{favourites_count}</span>
45+
</div>
46+
</div>
47+
)
48+
)}
3449
</section>
3550
);
3651
};

lib/mastodon/getToots.ts

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { convert } from "html-to-text";
2+
13
interface IMastodonAccountResponse {
24
id: string;
35
username: string;
@@ -29,8 +31,18 @@ interface ITootResponse {
2931

3032
type AccountsStatusesResponse = ITootResponse[];
3133

34+
interface IToot {
35+
id: string;
36+
text: string;
37+
created_at: string;
38+
url: string;
39+
reblogs_count: number;
40+
replies_count: number;
41+
favourites_count: number;
42+
}
43+
3244
export interface IToots {
33-
data: { id: string; text: string; created_at: string }[];
45+
data: IToot[];
3446
author: { username: string; url: string };
3547
}
3648

@@ -61,6 +73,27 @@ const getTootsById = async (
6173
}
6274
};
6375

76+
const mapTootResponseToToot = ({
77+
id,
78+
created_at,
79+
content,
80+
url,
81+
reblogs_count,
82+
replies_count,
83+
favourites_count,
84+
}: ITootResponse): IToot => ({
85+
id,
86+
created_at,
87+
url,
88+
text: convert(content, {
89+
wordwrap: 130,
90+
ignoreHref: true,
91+
}),
92+
replies_count,
93+
reblogs_count,
94+
favourites_count,
95+
});
96+
6497
export const getToots = async (): Promise<IToots | null> => {
6598
const { MASTODON_ACCESS_TOKEN, MASTODON_ID } = process.env;
6699
const count = 2;
@@ -77,11 +110,7 @@ export const getToots = async (): Promise<IToots | null> => {
77110
throw Error(`no toots found for ${MASTODON_ID}`);
78111
}
79112
return {
80-
data: toots.slice(0, count).map(({ id, created_at, content }) => ({
81-
id,
82-
created_at,
83-
text: content,
84-
})),
113+
data: toots.slice(0, count).map(mapTootResponseToToot),
85114
author: {
86115
username: toots[0].account.username,
87116
url: toots[0].account.url,

0 commit comments

Comments
 (0)