Skip to content

refactor: DRY sweep — shared helpers & components (net -116 LOC)#144

Merged
krazyjakee merged 8 commits into
masterfrom
claude/sad-bassi-3bc30e
Jun 15, 2026
Merged

refactor: DRY sweep — shared helpers & components (net -116 LOC)#144
krazyjakee merged 8 commits into
masterfrom
claude/sad-bassi-3bc30e

Conversation

@krazyjakee

Copy link
Copy Markdown
Contributor

Summary

A codebase-wide DRY sweep (run via parallel subagents) consolidating duplicated/WET code into shared helpers and components. Each logical group is a separate commit; net −116 lines across 49 files. No behavior changes intended; flutter analyze --no-fatal-infos stays clean (only pre-existing infos remain).

Staged commits

  • auth-select ref extensionswatch/readUserId, watchCdnUrl, watchIsAdmin on WidgetRef/Ref, replacing ~40 inline accordAuthProvider.select(...) lambdas.
  • RestResult.errorOr + showErrorSnack — dedupe ~45 ad-hoc error-snack / error-text sites.
  • SettingsScaffold — single themed Scaffold+AppBar chrome shared by the settings pages.
  • canManageSpaceSettings — extract the identical permission triad (only where genuinely identical; divergent permission sites left untouched).
  • showConfirmDialog — route inline destructive AlertDialogs through the shared confirm helper.
  • AppBanner — shared slim top banner for the update / web-update prompts.
  • SectionHeader trailing slot + ColorSwatchChip — drop the developer panel's bespoke _ActivityHeader; consolidate the duplicated accent/avatar swatch widgets + palette.

Scope notes (deliberately not changed)

  • BusyButton consolidation skipped — 38 sites too heterogeneous to merge without visual verification.
  • Full permission-block unification skipped — call sites diverge (admin flags, per-connection vs active session, read vs watch).

Test plan

  • flutter analyze --no-fatal-infos clean (no new warnings/errors)
  • Smoke-test settings pages (appearance/accent picker, profile avatar color, developer panel, connections, profiles, privacy)
  • Verify update banner + web-update prompt still render/dismiss
  • Confirm destructive dialogs (disconnect, delete profile) still gate correctly

🤖 Generated with Claude Code

Copy link
Copy Markdown
Contributor Author

Code Review — findings & fixes

All fixes are in commit 2cf0407 on this branch.


🔴 High — Stale client-access pattern (3 files)

The PR imported client_access.dart and migrated watchUserId() / watchCdnUrl() calls, but missed the analogous AccordClient lookup in callback methods of three files. Each still read the client via the old accordAuthProvider.select(s => s is AccordAuthLoggedIn ? s.client : null) pattern while holding a now-superfluous accordAuthProvider import.

File Site
lib/features/user/components/self_status_button.dart _setCustomStatus + _setStatus (2 sites)
lib/features/voice/views/voice_text_panel.dart _send
lib/features/spaces/views/accord_transfer_ownership.dart _submit

Fix: Replaced each with ref.accordClient (already available via the imported extension) and removed the now-unused accord_auth.dart model + repository imports.


🟡 Medium — Missing tests for new shared components

No tests existed for the six new/modified shared units introduced by this PR.

Fix: Added the following test files (commit 2cf0407):

New file What it covers
test/shared/rest_result_ext_test.dart RestResult.errorOr (null vs non-null error), showErrorSnack (prefix formatting, null-error fallback)
test/shared/app_banner_test.dart AppBanner message, icon, onTap, onDismiss, optional actions, SafeArea(bottom: false)
test/shared/color_swatch_chip_test.dart avatarColorPalette length/names; ColorSwatchChip size, check/reset icons, onTap, Tooltip wrapping
test/shared/settings_scaffold_test.dart SettingsScaffold title, body, back button, optional actions + FAB
test/features/member/permissions_test.dart canManageSpaceSettings — false for empty/unrelated perms; true for each of the three qualifying perms and for administrator
test/shared/section_header_test.dart Extended existing tests: added trailing-slot rendering, Row layout, and tighter right-padding (8 instead of 16)

⚪ Low / noted (no change needed)

ColorSwatchChip icon-color algorithm differs from old _AccentSwatch: The old accent-swatch widget used ThemeData.estimateBrightnessForColor (W3C luminance threshold ≈ 0.179) to pick black vs white; the new shared widget uses accordOnColor (computeLuminance() > 0.5). For all eight palette colors the result is identical in practice (blue/blurple/etc. are all well below 0.179 → white; yellow is well above 0.5 → black). The behavioral difference only materialises for mid-luminance colors not in the current palette, so no fix applied.

Scope correctly limited: The three permission-block sites in accord_space_settings.dart that still use individual per-permission checks were intentionally left untouched — they have divergent logic (separate canManageSpace/canManageRoles/canAuditLog variables used independently below) and don't match the identical triad replaced by canManageSpaceSettings. The PR description correctly calls this out.


Generated by Claude Code

krazyjakee and others added 8 commits June 15, 2026 15:56
…ambdas

Add watch/read getters for userId, cdnUrl and isAdmin to client_access.dart
alongside the existing accordClient getter, and replace the copy-pasted
accordAuthProvider.select lambdas across spaces/voice/member/messaging.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
… sites

Replace the copy-pasted `result.error?.toString() ?? 'Failed …'` idiom with a
RestResult.errorOr extension across admin/moderation/settings/space views, and
route two identical failure SnackBars through a shared showErrorSnack helper.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Extract the themed Scaffold + back-button AppBar shell shared by the
connections, privacy, profiles, voice, updates and developer settings screens
into a reusable SettingsScaffold widget.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Replace the duplicated manage-space/manage-roles/view-audit-log triad in the
space header menu and channel list with a shared canManageSpaceSettings helper.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…irmDialog

Replace the hand-rolled Cancel/destructive AlertDialogs for profile deletion
and OAuth disconnect with the shared showConfirmDialog(danger: true) helper.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Pull the slim top-of-app banner chrome shared by UpdateBanner and
WebUpdatePrompt into a reusable AppBanner widget (icon, message, tap, dismiss,
optional trailing actions).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Add an optional trailing action to SectionHeader and drop the developer
panel's bespoke _ActivityHeader. Consolidate the duplicated accent/avatar
swatch widgets and palette into shared ColorSwatchChip.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Three files imported client_access.dart but still used the old
accordAuthProvider.select(s => s is AccordAuthLoggedIn ? s.client)
pattern to obtain the client; replaced each with ref.accordClient and
removed the now-unused auth imports.

Added widget/unit tests for new shared components introduced by this PR:
AppBanner, ColorSwatchChip, SettingsScaffold, RestResult.errorOr /
showErrorSnack, SectionHeader trailing slot, and canManageSpaceSettings.

https://claude.ai/code/session_01BrT1uDAMGiogdYHRM1pxYE
@krazyjakee krazyjakee force-pushed the claude/sad-bassi-3bc30e branch from 2cf0407 to 2df3cb8 Compare June 15, 2026 14:58
@krazyjakee krazyjakee merged commit 2e4ae8c into master Jun 15, 2026
2 checks passed
@krazyjakee krazyjakee deleted the claude/sad-bassi-3bc30e branch June 15, 2026 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants