Skip to content

Conversation

lollipopkit
Copy link
Owner

@lollipopkit lollipopkit commented Oct 8, 2025

Fixes: #927

Summary by CodeRabbit

  • New Features

    • Reorder servers in Settings and persist the custom order across sessions.
  • Bug Fixes

    • Corrected item movement logic in the reorder list for accurate placement.
    • Kept the on-screen order in sync with external updates to prevent desynchronization.
  • Refactor

    • Streamlined item rendering to derive display from the current order.
    • Simplified drag proxy behavior during reordering.
  • Style

    • Minor UI tweaks to spacing and avatars for a cleaner list appearance.

Copy link

coderabbitai bot commented Oct 8, 2025

Walkthrough

Adds server order update logic to ServersNotifier and refactors the server sequence settings page to manage local order state and correctly handle drag-and-drop reordering. Also updates Riverpod-generated hash strings for several providers with no behavioral changes.

Changes

Cohort / File(s) Summary
Servers order management
lib/data/provider/server/all.dart
Adds ServersNotifier.updateServerOrder(List) and private _isSameOrder for equality checks; persists new order and triggers sync if changed.
Settings UI: server sequence
lib/view/page/setting/seq/srv_seq.dart
Introduces local _order with provider listener; updates ReorderableListView onReorder to compute target index and move items; updates rendering pipeline to derive items from _order; minor UI adjustments; import cleanup.
Generated provider hashes
lib/data/provider/pve.g.dart, lib/data/provider/server/all.g.dart, lib/data/provider/server/single.g.dart, lib/data/provider/systemd.g.dart
Updates debug create-source hash strings; no logic changes.

Sequence Diagram(s)

sequenceDiagram
    actor U as User
    participant P as Server Seq Page
    participant R as ReorderableListView
    participant N as ServersNotifier
    participant S as Storage
    participant SY as Sync/Scheduler

    U->>R: Drag item to new position
    R-->>P: onReorder(oldIndex, newIndex)
    rect rgba(200,230,255,0.3)
      note right of P: Compute adjusted targetIndex and newOrder
      P->>P: setState(_order = newOrder)
      P->>N: updateServerOrder(newOrder)
    end
    N->>N: _isSameOrder? (fast path)
    alt Order changed
      N->>S: Persist serverOrder
      N-->>SY: Trigger synchronization
    else No change
      N-->>P: No-op
    end

    note over N,P: Page also listens to serversProvider changes<br/>and syncs local _order when external updates occur.
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

I nudged the servers, hop by hop,
From slot to slot—no bounce-back flop.
A tidy list, in ordered line,
Stored and synced—oh how divine!
With paws that sort and ears that perk,
This bunny’s merge makes reorder work. 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title succinctly describes the bug being fixed—unable to sort server order—and aligns closely with the primary change implemented to address issue #927, making it clear and specific for readers scanning the history.
Linked Issues Check ✅ Passed The changes implement the required server reorder functionality by adding updateServerOrder in the provider and wiring the UI’s ReorderableListView to call this method, ensuring that moved items persist their new positions as described in issue #927.
Out of Scope Changes Check ✅ Passed All modifications—including the addition of the updateServerOrder method, UI adjustments for the ReorderableListView, and the generated provider hash updates—are directly tied to enabling and persisting server reordering, with no unrelated features or refactors introduced.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch lollipopkit/issue927

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
lib/data/provider/server/all.dart (1)

271-284: Consider using collection equality from fl_lib.

The manual list equality implementation is correct with the identical() fast-path optimization. However, since fl_lib is already imported (line 3), you could use the .equals() extension method instead:

bool _isSameOrder(List<String> a, List<String> b) => a.equals(b);

The current implementation is fine and avoids any potential overhead, so this is purely a stylistic suggestion.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between da8517b and 89a9ea6.

📒 Files selected for processing (6)
  • lib/data/provider/pve.g.dart (1 hunks)
  • lib/data/provider/server/all.dart (1 hunks)
  • lib/data/provider/server/all.g.dart (1 hunks)
  • lib/data/provider/server/single.g.dart (1 hunks)
  • lib/data/provider/systemd.g.dart (1 hunks)
  • lib/view/page/setting/seq/srv_seq.dart (3 hunks)
🔇 Additional comments (10)
lib/data/provider/server/all.g.dart (1)

44-44: Generated file - no review needed.

This is a Riverpod-generated hash update corresponding to changes in the source file lib/data/provider/server/all.dart. Generated files are automatically updated by the build runner.

lib/data/provider/pve.g.dart (1)

61-61: Generated file - no review needed.

This is a Riverpod-generated hash update. Generated files are automatically updated by the build runner and don't require manual review.

lib/data/provider/systemd.g.dart (1)

61-61: Generated file - no review needed.

This is a Riverpod-generated hash update. No manual review required.

lib/data/provider/server/single.g.dart (1)

61-61: Generated file - no review needed.

This is a Riverpod-generated hash update. Generated files don't require manual review.

lib/data/provider/server/all.dart (1)

242-269: LGTM - well-implemented server order update logic.

The method correctly:

  • Deduplicates the input order and filters out invalid server IDs (lines 246-254)
  • Ensures all existing servers are included by appending missing IDs (lines 256-260)
  • Early exits if the order hasn't changed (lines 262-264)
  • Updates state, persists to storage, and triggers sync (lines 266-268)

This addresses the core issue in #927 by providing a proper persistence mechanism for reordered servers.

lib/view/page/setting/seq/srv_seq.dart (5)

20-26: LGTM - proper local state initialization.

Initializing local _order from the provider in initState is the correct approach. This provides immediate UI updates during drag operations while maintaining sync with the provider state.


30-37: LGTM - correct Riverpod listener pattern.

The listener properly syncs local state with provider changes while preventing infinite loops via the listEquals check. Placing ref.listen in the build method is the correct Riverpod pattern - the framework handles subscription lifecycle automatically.


70-86: LGTM - correct reorder logic that fixes the bug.

The reorder implementation correctly:

  1. Calculates targetIndex accounting for the index shift when dragging downward (lines 72-73)
  2. Early exits if no actual reorder occurred (lines 75-77)
  3. Creates the new order by removing and reinserting the item (lines 79-81)
  4. Updates local state immediately for responsive UI (lines 83-85)
  5. Persists changes via the provider (line 86)

This fixes issue #927 by maintaining local state that updates immediately, preventing the item from reverting to its original position.


90-94: LGTM - proper data fetching and null handling.

The item builder now correctly fetches server data (Spi) by looking up the ID from the order list in the server state. The null check is good defensive programming that handles edge cases where a server might be briefly missing during deletion or sync operations.


111-114: Good defensive null handling.

Returning an empty SizedBox for null Spi gracefully handles edge cases where a server ID exists in the order but not in the server state (e.g., during brief sync windows when a server is deleted). This prevents crashes and UI glitches.

@lollipopkit lollipopkit merged commit 3307fca into main Oct 8, 2025
2 of 3 checks passed
@lollipopkit lollipopkit deleted the lollipopkit/issue927 branch October 8, 2025 09:37
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.

服务器顺序调整失败

1 participant