refactor(frontend): improved layout manager & added recommended shards amount#115
Conversation
There was a problem hiding this comment.
Depends on unmerged branches. Imports $lib/components/BoundaryFailed.svelte + $lib/components/Widget.svelte (from refactor/frontend/clusters) and $lib/components/ConfirmButton.svelte (from refactor/frontend/navigation). Won't build standalone. Merge order: clusters + navigation → this. Findings below are independent of those.
Good news up front: I traced the shard-assignment logic against the backend validateLayout, and the parity is mostly correct — shard IDs stay contiguous [0, total-1] (add uses maxShardId+1; remove decrements all higher IDs), duplicates/ranges match, and empty/deleted clusters are filtered from export(). The issues are elsewhere.
Major
Actions.svelte—// @ts-expect-errorplaced inside an element's attribute list. Svelte markup has no//comments mid-tag, so//and@ts-expect-errorbecome bogus attributes and do not suppress the intended TS error. Remove it and fix the underlying cause (below).updateBotLayout.pendingdoesn't exist on acommandremote (that's what the@ts-expect-errorwas hiding).!!undefinedis alwaysfalse, so the Save button never disables while the request is in flight → a double-click fires concurrentPATCH /botcalls. Track pending with a local$stateboolean around theawait.- Deleting all clusters produces
layout: [], which the backend rejects.UpdateBotSchema.layoutis.min(1);export()returns[]when every cluster is deleted, butchangedistrueso Save stays enabled → confusing 400. Block export / disable Save when no non-deleted cluster remains. - Error handling swallows the real message + can throw. The
updateBotLayoutremote maps failures to a genericerror(500, "An error occurred")via itsdefault:branch, so backend 400 messages (duplicate shard IDs, out-of-range, …) never reach the user. And the toast callback doesJSON.parse(error)on what is actually anHttpError/Redirectobject → throws inside the catch. Surface the backendmessagefrom the response body, and don'tJSON.parsethe client error object.
- Backend DTO mismatch:get-recommended-shards.dto.tsdeclaresshards: z.number().positive(), but the source (discord.service.getGatewayBot) isz.number().int().nonnegative().positive()excludes0(a valid Discord value) and drops.int(). No runtime 500 (the controller returns the raw value), but the shared type consumed by the frontend is subtly wrong. Change toz.number().int().nonnegative().
#119
Minor
LayoutManager.svelte.ts—current/previousare plain fields, not$state; reactivity works only because every mutator reassigns the$stateshardsmap and the UI readsshards. Fragile: any future reactive read ofcluster.currentwon't update. Consider$state-wrapping it or documenting the invariant.Cluster.svelte— non-null assertions oncluster.shards!everywhere mask a genuinely optional type; grid mathMath.round(Math.sqrt(...))is safe for size 0 but worth a guard.
Verified fine
- Backend DTO barrel change (
index.dto.ts) is structurally valid; the frontend consumesGetRecommendedShardsDtocorrectly. - Layout validation parity with
validateLayout(aside from the all-deleted case above).
Verdict: draft, blocked on clusters+navigation for missing components. Once rebased, fix the @ts-expect-error/.pending pair, the layout: [] gap, and the error-message handling (all Major); align the recommended-shards DTO.
8c3a1be to
85826fb
Compare
a9ex
left a comment
There was a problem hiding this comment.
Implement backend errors in the future instead of the generic 500 error
This pull request refactors and enhances the bot layout management UI and related backend/frontend integration. The main focus is on improving the layout editing experience, streamlining state management, and introducing recommended shard functionality. The changes also clean up code, improve error handling, and modularize UI components.
Frontend Layout Management Refactor:
LayoutManager.svelte.tsto simplify cluster and shard state management, replacing theShardclass with a more efficientMap-based approach and improving mutation tracking for clusters and shards. This enables more robust add/remove/clone/reset operations and clearer UI feedback.+page.svelte) to use new modular components (Actions,Cluster,RecommendedShards), implement better loading/error states, and clean up the UI logic for cluster display and actions.Actions.svelte) and cluster display (Cluster.svelte), providing improved UX for saving, resetting, adding, removing, and cloning clusters, as well as per-cluster shard management.Backend/Frontend Integration:
GetRecommendedShardsDtoand exported it from the backend DTO index, enabling the frontend to fetch recommended shard counts for improved user guidance.getRecommendedShardsquery in the frontend remote, with enhanced error handling and redirects for authentication/setup issues.General Improvements:
These changes collectively improve maintainability, user experience, and reliability of the bot layout management feature.
Screenshots
/layoutChecklist
Additional Notes