Skip to content

Commit b338cab

Browse files
committed
feat(website): implement chunking of tweets for better layout
1 parent 7061953 commit b338cab

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

website/lib/chunk.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export function chunk<T>(arr: readonly T[], size: number): T[][] {
2+
if (!Number.isInteger(size) || size <= 0) {
3+
throw new Error("Size must be an integer greater than zero.");
4+
}
5+
6+
const chunkLength = Math.ceil(arr.length / size);
7+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
8+
const result: T[][] = Array(chunkLength);
9+
10+
for (let index = 0; index < chunkLength; index++) {
11+
const start = index * size;
12+
const end = start + size;
13+
14+
result[index] = arr.slice(start, end);
15+
}
16+
17+
return result;
18+
}

website/pages/index.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ A series of composable ESLint plugins for libraries and frameworks that use Reac
3434
- [`eslint-config-sukka`](https://github.com/SukkaW/eslint-config-sukka) - Sukka's ESLint config preset.
3535

3636
<TweetCards tweets={[
37-
"1841248980354941038",
38-
"1839913920984678890",
3937
"1865166494709026873",
38+
"1839913920984678890",
39+
"1841248980354941038",
40+
"1859137094976696467",
4041
]} />
4142

4243
## FAQ

website/widgets/tweet-cards.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
1+
import { useMemo } from "react";
12
import { Tweet } from "react-tweet";
23

4+
import { chunk } from "#/lib/chunk";
5+
36
export function TweetCards({ tweets }: { tweets: string[] }) {
7+
const chunkedTweets = useMemo(() => chunk(tweets, 2), [tweets]);
48
return (
5-
<div className="grid grid-cols-1 mt-4 sm:grid-cols-2 sm:gap-x-8 sm:mt-8 justify-center">
6-
{tweets.map((id) => <Tweet key={id} id={id} />)}
9+
<div className="grid grid-cols-1 md:grid-cols-2 sm:gap-x-8 sm:mt-8">
10+
{chunkedTweets.map((chunk) => (
11+
<div key={chunk.join("_")} className="grid justify-center">
12+
{chunk.map((id) => (
13+
<div key={id} className="h-fit max-w-full">
14+
<Tweet id={id} />
15+
</div>
16+
))}
17+
</div>
18+
))}
719
</div>
820
);
921
}

0 commit comments

Comments
 (0)