Skip to content

Commit 2adbac6

Browse files
t3dotggclaude
andcommitted
fix(web): quick pins keep click order
Each pin takes its slot at click time, after the last slot handed out, so pinning two projects before the list updates no longer gives them the same slot. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 1e64d8e commit 2adbac6

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

‎apps/web/src/hooks/useProjectGroupActions.ts‎

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,20 @@ function adjustProjectWrites(projectKeys: ReadonlyArray<string>, delta: number)
5757
});
5858
}
5959

60+
// The newest pin slot handed out. Pins made faster than the list updates
61+
// still land in click order instead of sharing one slot.
62+
let lastIssuedPinOrderKey: string | null = null;
63+
64+
function issuePinOrderKey(groups: ReadonlyArray<ProjectGroup>): string | null {
65+
const key = nextProjectPinOrderKey(
66+
lastIssuedPinOrderKey === null
67+
? groups
68+
: [...groups, { pinnedAt: "issued", pinOrderKey: lastIssuedPinOrderKey }],
69+
);
70+
if (key !== null) lastIssuedPinOrderKey = key;
71+
return key;
72+
}
73+
6074
/** Runs `run` after earlier writes to any of the projects, marking them busy meanwhile. */
6175
function queueProjectWrite(
6276
projectKeys: ReadonlyArray<string>,
@@ -194,16 +208,19 @@ export function useProjectGroupActions() {
194208
const isBusy = useCallback((projectKey: string) => busyCounts.has(projectKey), [busyCounts]);
195209

196210
const setPinned = useCallback(
197-
(group: ProjectGroup, pinned: boolean, groups: ReadonlyArray<ProjectGroup>) =>
198-
queueProjectWrite([group.projectKey], () =>
211+
(group: ProjectGroup, pinned: boolean, groups: ReadonlyArray<ProjectGroup>) => {
212+
// Take the slot at click time, so quick pins keep their order.
213+
const input = pinned
214+
? { pinned: true, pinOrderKey: issuePinOrderKey(groups) }
215+
: { pinned: false };
216+
return queueProjectWrite([group.projectKey], () =>
199217
organizeGroup(
200218
group,
201-
pinned
202-
? { pinned: true, pinOrderKey: nextProjectPinOrderKey(groups) }
203-
: { pinned: false },
219+
input,
204220
pinned ? `Failed to pin ${group.displayName}` : `Failed to unpin ${group.displayName}`,
205221
),
206-
),
222+
);
223+
},
207224
[organizeGroup],
208225
);
209226

0 commit comments

Comments
 (0)