Commit 653846d
committed
refactor(frontend): Task 6 — Modularize utility functions by domain
New utility modules in utils/:
- messageUtils.ts: createMessage() factory, formatContentForClipboard()
- contentParsing.ts: parseTextContent(), resolveImageUrl(), buildGeneratedContent()
- sseParser.ts: parseSSEStream() — eliminates duplicated SSE decode loop
- generationStages.ts: getGenerationStage() — pure progress-stage mapper
- briefFields.ts: BRIEF_FIELD_LABELS, BRIEF_DISPLAY_ORDER, BRIEF_FIELD_KEYS
- stringUtils.ts: escapeRegex(), createNameSwapper(), matchesAnyKeyword()
- apiUtils.ts: retryRequest (exponential backoff), RequestCache, throttle
- index.ts: barrel export for all utils
Deduplicated code:
- msg() helper was identical in 2 hooks → createMessage() in messageUtils
- SSE stream parser was identical in 2 API functions → parseSSEStream()
- GeneratedContent parsing was near-identical in 3 hooks → buildGeneratedContent()
- Brief field constants duplicated in 2 components → shared briefFields
- Keyword matching pattern repeated 3x → matchesAnyKeyword()
Internal helpers marked non-exported:
- rewriteBlobUrl() in contentParsing.ts
- defaultShouldRetry(), sleep() in apiUtils.ts
- plainDownload() in downloadImage.ts (already was)
Build: 0 TypeScript errors1 parent 86d2279 commit 653846d
17 files changed
Lines changed: 741 additions & 332 deletions
File tree
- content-gen/src/app/frontend
- src
- api
- components
- hooks
- utils
Binary file not shown.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| 19 | + | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
| |||
0 commit comments