Skip to content

Deduplicate formatBytes/formatSize utility functions across codebase #14

@kanweiwei

Description

@kanweiwei

The formatBytes / formatFileSize / formatSize utility function is duplicated ~15 times across the codebase instead of being imported from the canonical location.

Canonical location: web/src/lib/utils.ts exports formatBytes and formatSize

Duplicate locations include:

  • web/src/utils/change-helpers.tsx line 54
  • web/src/hooks/useMobileUpload.ts line 83
  • web/src/components/sync/FileChangeList.tsx line 40
  • web/src/components/sync/SyncProgressDialog.tsx line 48
  • web/src/components/sync/FileDiffViewer.tsx line 85
  • web/src/components/settings/SettingsDialog.tsx line 149
  • web/src/components/tools/DropZone.tsx line 107
  • web/src/components/plugins/PluginResults.tsx line 253
  • web/src/store/offline-queue.store.ts line 66
  • web/src/agent/tools/ls.tool.ts line 116
  • ... and more

What to do:

  1. Pick a few files to start with (don't need to do all at once)
  2. In each file, remove the local formatBytes/formatSize/formatFileSize function
  3. Replace with import { formatBytes } from '@/lib/utils' (or formatSize)
  4. Verify the behavior is the same (some variants differ slightly in decimal places — match the canonical version)
  5. Run pnpm -C web run typecheck to confirm no errors

Skills needed: TypeScript, ability to refactor imports

Estimated time: 1-2 hours (can be done incrementally, a few files per PR)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions