mirror of
https://github.com/tiddly-gittly/TidGi-Desktop.git
synced 2026-01-21 12:02:57 -08:00
Create DragAndDrop.md
This commit is contained in:
parent
d767c9bce1
commit
13daaa6d8a
1 changed files with 28 additions and 0 deletions
28
docs/internal/DragAndDrop.md
Normal file
28
docs/internal/DragAndDrop.md
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
# Drag-and-Drop Optimistic Update (TidGi)
|
||||
|
||||
## Implementation Summary
|
||||
|
||||
TidGi uses **optimistic UI updates** for drag-and-drop reordering in both form arrays and sidebar workspace lists. This ensures a smooth user experience without flicker or delay, even when backend or form updates are slow.
|
||||
|
||||
### Key Points
|
||||
|
||||
- When a drag ends, the UI immediately updates the order using local state (store or useState), before waiting for backend or form data to update.
|
||||
- The backend update (or form update) is triggered asynchronously. When the new data arrives, the local optimistic state is cleared.
|
||||
- This prevents the UI from briefly reverting to the old order before the update is confirmed.
|
||||
|
||||
### Implementation Details
|
||||
|
||||
- **Form Arrays**: Uses zustand store (`itemsOrder`) for optimistic rendering. See `ArrayFieldTemplate.tsx` and `arrayFieldStore.ts`.
|
||||
- **Sidebar Workspaces**: Uses local React state (`optimisticOrder`) for workspace ID order. See `SortableWorkspaceSelectorList.tsx`.
|
||||
|
||||
### Cautions
|
||||
|
||||
- Always clear the optimistic state when the real data arrives, to avoid stale UI.
|
||||
- Do not mutate the original data objects; always clone or use new arrays/objects.
|
||||
- If backend update fails, consider showing an error or reverting the optimistic state.
|
||||
|
||||
### References
|
||||
|
||||
- [ArrayFieldTemplate.tsx](../../src/pages/ChatTabContent/components/PromptPreviewDialog/PromptConfigForm/templates/ArrayFieldTemplate.tsx)
|
||||
- [arrayFieldStore.ts](../../src/pages/ChatTabContent/components/PromptPreviewDialog/PromptConfigForm/store/arrayFieldStore.ts)
|
||||
- [SortableWorkspaceSelectorList.tsx](../../src/pages/Main/WorkspaceIconAndSelector/SortableWorkspaceSelectorList.tsx)
|
||||
Loading…
Add table
Add a link
Reference in a new issue