Skip to content

Commit 4e8e911

Browse files
committed
chore: convert utilities, hooks, lib, constants
1 parent aa57e87 commit 4e8e911

File tree

23 files changed

+312
-206
lines changed

23 files changed

+312
-206
lines changed

apps/media/app/[locale]/podcasts/[podcastSlug]/client-page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export default function PodcastShowClientPage({
111111
{/* Podcast Header */}
112112
<div className="flex flex-col md:flex-row gap-8 items-start">
113113
{/* Cover Image */}
114-
<div className="w-full md:w-64 flex-shrink-0">
114+
<div className="w-full md:w-64 shrink-0">
115115
<div className="relative aspect-square w-full overflow-hidden shadow-lg">
116116
<Image
117117
src={podcast.coverImage}

apps/web/openspec/changes/enforce-ts-strict/tasks.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@
99

1010
## 2. Convert utilities, hooks, lib, constants (Phase 2)
1111

12-
- [ ] 2.1 `src/utils/Link.js``.ts`
13-
- [ ] 2.2 `src/utils/dateUtils.js``.ts`
14-
- [ ] 2.3 `src/utils/emailUtils.js``.ts`
15-
- [ ] 2.4 `src/utils/fetcher.js``.ts`
16-
- [ ] 2.5 `src/utils/followerFunctions.js``.ts`
17-
- [ ] 2.6 `src/utils/getNextRequestId.js``.ts`
18-
- [ ] 2.7 `src/utils/rpcUtils.js``.ts`
19-
- [ ] 2.8 `src/utils/stringUtils.js``.ts`
20-
- [ ] 2.9 `src/utils/ytUtils.js``.ts`
21-
- [ ] 2.10 `src/hooks/useIsomorphicLayoutEffect.js``.ts`
22-
- [ ] 2.11 `src/hooks/useReducedMotion.js``.ts`
23-
- [ ] 2.12 `src/hooks/useTransactionStats.js``.ts`
24-
- [ ] 2.13 `src/lib/markdown/index.js``.ts`
25-
- [ ] 2.14 `src/lib/podcast/index.js``.ts`
26-
- [ ] 2.15 `src/lib/sitemap/media-urls.js``.ts`
27-
- [ ] 2.16 `src/constants/developerContentConfig.js``.ts`
12+
- [x] 2.1 `src/utils/Link.js``.ts`
13+
- [x] 2.2 `src/utils/dateUtils.js``.ts`
14+
- [x] 2.3 `src/utils/emailUtils.js``.ts`
15+
- [x] 2.4 `src/utils/fetcher.js``.ts`
16+
- [x] 2.5 `src/utils/followerFunctions.js``.ts`
17+
- [x] 2.6 `src/utils/getNextRequestId.js``.ts`
18+
- [x] 2.7 `src/utils/rpcUtils.js``.ts`
19+
- [x] 2.8 `src/utils/stringUtils.js``.ts`
20+
- [x] 2.9 `src/utils/ytUtils.js``.ts`
21+
- [x] 2.10 `src/hooks/useIsomorphicLayoutEffect.js``.ts`
22+
- [x] 2.11 `src/hooks/useReducedMotion.js``.ts`
23+
- [x] 2.12 `src/hooks/useTransactionStats.js``.ts`
24+
- [x] 2.13 `src/lib/markdown/index.js``.ts`
25+
- [x] 2.14 `src/lib/podcast/index.js``.ts`
26+
- [ ] 2.15 `src/lib/sitemap/media-urls.js``.ts` (deferred — CJS required by `next-sitemap.config.js` at runtime; convert alongside that file in Phase 6)
27+
- [x] 2.16 `src/constants/developerContentConfig.js``.ts`
2828

2929
## 3. Convert data files (Phase 3)
3030

apps/web/src/constants/developerContentConfig.js

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// simple strings for the content record groups
2+
export const RECORD_GROUPS = {
3+
cookbook: "cookbook",
4+
guides: "guides",
5+
docs: "docs",
6+
rpc: "docs/rpc",
7+
} as const;
8+
9+
/**
10+
* the highest markdown heading size to include when generating a TOC
11+
* (e.g. `3` results in "h1, h2, h3" to be displayed)
12+
*/
13+
export const TOC_HEADING_SIZE = 3;
14+
15+
/**
16+
* Define some common content values
17+
*/
18+
export const YT_PLAYLIST_CHANGELOG = "PLilwLeBwGuK5-Qri7Pg9zd-Vvhz9kX2-R";
File renamed without changes.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { useMemo } from "react";
33
/**
44
* Hook to easily grab reduced motion media query.
55
*
6-
* @returns {[unknown, unknown]}
6+
* @returns {[boolean, MediaQueryList | false]}
77
*/
8-
const useReducedMotion = () => {
8+
const useReducedMotion = (): [boolean, MediaQueryList | false] => {
99
// Grab the prefers reduced media query and memoize it.
1010
const reducedMotionMatch = useMemo(
1111
() =>
Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,37 @@ if (!rpcNodeURL) {
1313

1414
// Check for AbortController support
1515
const isAbortControllerSupported =
16-
typeof window !== "undefined" && window.hasOwnProperty("AbortController");
17-
const noOp = () => null;
16+
typeof window !== "undefined" && "AbortController" in window;
17+
const noOp = (): void => undefined;
1818

1919
// Initializes an AbortController if supported
20-
const initAbortController = () =>
20+
const initAbortController = (): {
21+
abort: () => void;
22+
signal: AbortSignal | undefined;
23+
} =>
2124
isAbortControllerSupported
2225
? new AbortController()
23-
: { abort: noOp, signal: {} };
26+
: { abort: noOp, signal: undefined };
27+
28+
type VoteAccountsResult = {
29+
result: { current: Array<{ activatedStake: string }> };
30+
};
31+
type PerformanceSamplesResult = {
32+
result: Array<{ numTransactions: number; samplePeriodSecs: number }>;
33+
};
34+
type TransactionCountResult = { result: number };
2435

2536
/**
2637
* Fetches the superminority count.
2738
*
28-
* @returns {Promise<number>} The count of superminority validators.
39+
* @returns {Promise<number | null>} The count of superminority validators.
2940
*/
30-
export const fetchSuperminority = async () => {
41+
export const fetchSuperminority = async (): Promise<number | null> => {
3142
try {
32-
const voteAccounts = await makeRPCCall({
43+
const voteAccounts = (await makeRPCCall({
3344
method: "getVoteAccounts",
34-
rpcNodeURL,
35-
});
45+
rpcNodeURL: rpcNodeURL!,
46+
})) as VoteAccountsResult;
3647

3748
// Sort validators by stake in ascending order
3849
const sortedValidators = voteAccounts.result.current.sort((a, b) => {
@@ -75,35 +86,51 @@ export const fetchSuperminority = async () => {
7586
* @param {number} sampleHistoryHours How many hours (60min.) the query should go back.
7687
* @param {boolean} getLiveTransactionCount
7788
* @param {boolean} getCurrentValidatorNodes
78-
* @returns {{availableStats: boolean, avgTps: number, validators: number, totalTransactionCount: number, superminority: number}}
89+
* @returns {{availableStats: boolean, avgTps: number, validators: number, totalTransactionCount: number, superminority: number | null}}
7990
*/
8091
export const useTransactionStats = ({
8192
visible,
8293
performanceUpdateSeconds,
8394
sampleHistoryHours,
8495
getLiveTransactionCount = true,
8596
getCurrentValidatorNodes = true,
86-
}) => {
97+
}: {
98+
visible: boolean;
99+
performanceUpdateSeconds: number;
100+
sampleHistoryHours: number;
101+
getLiveTransactionCount?: boolean;
102+
getCurrentValidatorNodes?: boolean;
103+
}): {
104+
availableStats: boolean;
105+
avgTps: number;
106+
totalTransactionCount: number;
107+
validators: number;
108+
superminority: number | null;
109+
} => {
87110
const [availableStats, setAvailableStats] = useState(false);
88111
const [avgTps, setAvgTps] = useState(0);
89112
const [totalTransactionCount, setTotalTransactionCount] = useState(0);
90113
const [validators, setValidators] = useState(0);
91-
const [superminority, setSuperminority] = useState(null);
114+
const [superminority, setSuperminority] = useState<number | null>(null);
92115

93116
const getRPCData = useCallback(
94-
async (getValidatorNodes, getTransactionCount, abortSignal) => {
117+
async (
118+
getValidatorNodes: boolean,
119+
getTransactionCount: boolean,
120+
abortSignal: AbortSignal | undefined,
121+
): Promise<boolean> => {
95122
try {
96123
if (rpcNodeURL) {
97124
await Promise.all([
98125
(async () => {
99-
const recentPerformanceSamples = await makeRPCCall({
126+
const recentPerformanceSamples = (await makeRPCCall({
100127
abortSignal,
101128
method: "getRecentPerformanceSamples",
102129
params: [60 * sampleHistoryHours],
103130
rpcNodeURL,
104-
});
131+
})) as PerformanceSamplesResult;
105132
// Calculate average transactions per second
106-
const short = recentPerformanceSamples.result.reduce(
133+
const short = recentPerformanceSamples.result.reduce<number[]>(
107134
(shortResults, sample) => {
108135
if (sample.numTransactions !== 0) {
109136
shortResults.push(
@@ -122,23 +149,23 @@ export const useTransactionStats = ({
122149
if (!getValidatorNodes) {
123150
return;
124151
}
125-
const voteAccounts = await makeRPCCall({
152+
const voteAccounts = (await makeRPCCall({
126153
abortSignal,
127154
method: "getVoteAccounts",
128155
rpcNodeURL,
129-
});
156+
})) as VoteAccountsResult;
130157
setValidators(voteAccounts.result.current.length);
131158
setAvailableStats(true);
132159
})(),
133160
(async () => {
134161
if (!getTransactionCount) {
135162
return;
136163
}
137-
const transactionCount = await makeRPCCall({
164+
const transactionCount = (await makeRPCCall({
138165
abortSignal,
139166
method: "getTransactionCount",
140167
rpcNodeURL,
141-
});
168+
})) as TransactionCountResult;
142169
setTotalTransactionCount(transactionCount.result);
143170
setAvailableStats(true);
144171
})(),
@@ -148,7 +175,10 @@ export const useTransactionStats = ({
148175
}
149176
return false;
150177
} catch (error) {
151-
if (error.name === "AbortError" || error.name === "TypeError") {
178+
if (
179+
error instanceof Error &&
180+
(error.name === "AbortError" || error.name === "TypeError")
181+
) {
152182
return false;
153183
}
154184
console.error("Error fetching RPC data:", error);
Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,24 @@ const markdownPostsDir = join(process.cwd(), "src", "markdown");
1010
*
1111
* @param path
1212
* @param slug
13-
* @returns {{path, frontmatter: {date: (string|any)}, content: string}}
1413
*/
15-
export function getPostBySlug(path, slug) {
14+
export function getPostBySlug(
15+
path: string,
16+
slug: string,
17+
): {
18+
path: string;
19+
frontmatter: Record<string, unknown> & { date: string | null };
20+
content: string;
21+
} {
1622
const dir = join(markdownPostsDir, path);
1723
const realSlug = slug.replace(/\.md$/, "");
1824
const fullPath = join(dir, `${realSlug}.md`);
1925
const fileContents = fs.readFileSync(fullPath, "utf8");
2026
const { data, content } = matter(fileContents);
2127
const date =
2228
data.date && typeof data.date !== "string"
23-
? format(data.date, "MMMM dd, yyyy")
24-
: (data.date ?? null);
29+
? format(data.date as Date, "MMMM dd, yyyy")
30+
: ((data.date as string | null) ?? null);
2531
return {
2632
path: realSlug,
2733
frontmatter: { ...data, date, reviewed: true },
@@ -33,9 +39,10 @@ export function getPostBySlug(path, slug) {
3339
* Returns all posts from `markdownPostsDir`.
3440
*
3541
* @param path
36-
* @returns {{path: *, frontmatter: {date: *}, content: *|string}[]}
3742
*/
38-
export function getAllPostsInDir(path) {
43+
export function getAllPostsInDir(
44+
path: string,
45+
): ReturnType<typeof getPostBySlug>[] {
3946
const dir = join(markdownPostsDir, path);
4047
const slugs = fs.readdirSync(dir);
4148
const posts = slugs.map((slug) => getPostBySlug(path, slug));

0 commit comments

Comments
 (0)