Consolidate the repeated pattern of destructuring and removing diff/diffTurnId/diffFilePath search params into a single stripDiffSearchParams() function in diffRouteSearch.ts. Replaces 5 identical destructuring blocks across 3 files with calls to the shared helper.
Showing the changes to apps/web/src/diffRouteSearch.ts (1 of 4 files). Show all
Unified · Split
| @@ -12,6 +12,13 @@ function normalizeSearchString(value: unknown): string | undefined { · 11 unmodified lines | |||
| 12 | return normalized.length > 0 ? normalized : undefined; | 12 | return normalized.length > 0 ? normalized : undefined; |
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | export function stripDiffSearchParams<T extends Record<string, unknown>>( | ||
| 16 | params: T, | ||
| 17 | ): Omit<T, "diff" | "diffTurnId" | "diffFilePath"> { | ||
| 18 | const { diff: _diff, diffTurnId: _diffTurnId, diffFilePath: _diffFilePath, ...rest } = params; | ||
| 19 | return rest as Omit<T, "diff" | "diffTurnId" | "diffFilePath">; | ||
| 20 | } | ||
| 21 | |||
| 15 | export function parseDiffRouteSearch(search: Record<string, unknown>): DiffRouteSearch { | 22 | export function parseDiffRouteSearch(search: Record<string, unknown>): DiffRouteSearch { |
| 16 | const diff = search.diff === "1" ? "1" : undefined; | 23 | const diff = search.diff === "1" ? "1" : undefined; |
| 17 | const diffTurnId = diff ? normalizeSearchString(search.diffTurnId) : undefined; | 24 | const diffTurnId = diff ? normalizeSearchString(search.diffTurnId) : undefined; |
| @@ -23,4 +30,3 @@ export function parseDiffRouteSearch(search: Record<string, unknown>): DiffRoute · 5 unmodified lines | |||
| 23 | ...(diffFilePath ? { diffFilePath } : {}), | 30 | ...(diffFilePath ? { diffFilePath } : {}), |
| 24 | }; | 31 | }; |
| 25 | } | 32 | } |
| 26 | |||