Skip to content

Commit 33f5d60

Browse files
Restores optimistic behavior for pin/snooze (#3845)
1 parent a2614e9 commit 33f5d60

File tree

1 file changed

+69
-19
lines changed

1 file changed

+69
-19
lines changed

src/plus/launchpad/launchpad.ts

Lines changed: 69 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -461,11 +461,15 @@ export class LaunchpadCommand extends QuickCommand<State> {
461461
};
462462
};
463463

464-
const getItems = (result: LaunchpadCategorizedResult, isSearching?: boolean) => {
465-
const items: (LaunchpadItemQuickPickItem | DirectiveQuickPickItem | ConnectMoreIntegrationsItem)[] = [];
464+
const getLaunchpadQuickPickItems = (items: LaunchpadItem[] = [], isSearching?: boolean) => {
465+
const groupedAndSorted: (
466+
| LaunchpadItemQuickPickItem
467+
| DirectiveQuickPickItem
468+
| ConnectMoreIntegrationsItem
469+
)[] = [];
466470

467-
if (result.items?.length) {
468-
const uiGroups = groupAndSortLaunchpadItems(result.items);
471+
if (items.length) {
472+
const uiGroups = groupAndSortLaunchpadItems(items);
469473
const topItem: LaunchpadItem | undefined =
470474
!selectTopItem || picked != null
471475
? undefined
@@ -477,17 +481,19 @@ export class LaunchpadCommand extends QuickCommand<State> {
477481
if (!groupItems.length) continue;
478482

479483
if (!isSearching) {
480-
items.push(...buildGroupHeading(ui, groupItems.length));
484+
groupedAndSorted.push(...buildGroupHeading(ui, groupItems.length));
481485
if (context.collapsed.get(ui)) {
482486
continue;
483487
}
484488
}
485489

486-
items.push(...groupItems.map(i => buildLaunchpadQuickPickItem(i, ui, topItem, isSearching)));
490+
groupedAndSorted.push(
491+
...groupItems.map(i => buildLaunchpadQuickPickItem(i, ui, topItem, isSearching)),
492+
);
487493
}
488494
}
489495

490-
return items;
496+
return groupedAndSorted;
491497
};
492498

493499
function getItemsAndPlaceholder(isSearching?: boolean) {
@@ -513,7 +519,7 @@ export class LaunchpadCommand extends QuickCommand<State> {
513519

514520
return {
515521
placeholder: 'Choose an item, type a term to search, or paste in a PR URL',
516-
items: getItems(context.result, isSearching),
522+
items: getLaunchpadQuickPickItems(context.result.items, isSearching),
517523
};
518524
}
519525

@@ -535,6 +541,7 @@ export class LaunchpadCommand extends QuickCommand<State> {
535541

536542
const updateItems = async (
537543
quickpick: QuickPick<LaunchpadItemQuickPickItem | DirectiveQuickPickItem | ConnectMoreIntegrationsItem>,
544+
force?: boolean,
538545
) => {
539546
const search = quickpick.value;
540547
quickpick.busy = true;
@@ -543,7 +550,7 @@ export class LaunchpadCommand extends QuickCommand<State> {
543550
await updateContextItems(
544551
this.container,
545552
context,
546-
{ force: true, search: search },
553+
{ force: force, search: search },
547554
cancellationToken,
548555
);
549556
if (cancellationToken.isCancellationRequested) {
@@ -558,6 +565,17 @@ export class LaunchpadCommand extends QuickCommand<State> {
558565
}
559566
};
560567

568+
// Should only be used for optimistic update of the list when some UI property (like pinned, snoozed) changed with an
569+
// item. For all other cases, use updateItems.
570+
const optimisticallyUpdateItems = (
571+
quickpick: QuickPick<LaunchpadItemQuickPickItem | DirectiveQuickPickItem | ConnectMoreIntegrationsItem>,
572+
) => {
573+
quickpick.items = getLaunchpadQuickPickItems(
574+
context.result.items,
575+
quickpick.value != null && quickpick.value.length > 0,
576+
);
577+
};
578+
561579
const { items, placeholder } = getItemsAndPlaceholder();
562580
const nonGroupedItems = items.filter(i => !isDirectiveQuickPickItem(i));
563581

@@ -629,7 +647,7 @@ export class LaunchpadCommand extends QuickCommand<State> {
629647
}
630648
}
631649

632-
await updateItems(quickpick);
650+
await updateItems(quickpick, true);
633651
return true;
634652
},
635653
onDidClickButton: async (quickpick, button) => {
@@ -655,7 +673,7 @@ export class LaunchpadCommand extends QuickCommand<State> {
655673

656674
case RefreshQuickInputButton:
657675
this.sendTitleActionTelemetry('refresh', context);
658-
await updateItems(quickpick);
676+
await updateItems(quickpick, true);
659677
break;
660678
}
661679
return undefined;
@@ -676,26 +694,58 @@ export class LaunchpadCommand extends QuickCommand<State> {
676694
this.container.launchpad.open(item);
677695
break;
678696

679-
case SnoozeQuickInputButton:
697+
case SnoozeQuickInputButton: {
680698
this.sendItemActionTelemetry('snooze', item, group, context);
699+
700+
// Update optimistically
701+
const contextItem = context.result.items?.find(i => i.uuid === item.uuid);
702+
if (contextItem != null) {
703+
contextItem.viewer.snoozed = true;
704+
optimisticallyUpdateItems(quickpick);
705+
}
706+
681707
await this.container.launchpad.snooze(item);
682708
break;
683-
684-
case UnsnoozeQuickInputButton:
709+
}
710+
case UnsnoozeQuickInputButton: {
685711
this.sendItemActionTelemetry('unsnooze', item, group, context);
712+
713+
// Update optimistically
714+
const contextItem = context.result.items?.find(i => i.uuid === item.uuid);
715+
if (contextItem != null) {
716+
contextItem.viewer.snoozed = false;
717+
optimisticallyUpdateItems(quickpick);
718+
}
719+
686720
await this.container.launchpad.unsnooze(item);
687721
break;
688-
689-
case PinQuickInputButton:
722+
}
723+
case PinQuickInputButton: {
690724
this.sendItemActionTelemetry('pin', item, group, context);
725+
726+
// Update optimistically
727+
const contextItem = context.result.items?.find(i => i.uuid === item.uuid);
728+
if (contextItem != null) {
729+
contextItem.viewer.pinned = true;
730+
optimisticallyUpdateItems(quickpick);
731+
}
732+
691733
await this.container.launchpad.pin(item);
692734
break;
693-
694-
case UnpinQuickInputButton:
735+
}
736+
case UnpinQuickInputButton: {
695737
this.sendItemActionTelemetry('unpin', item, group, context);
738+
739+
// Update optimistically
740+
const contextItem = context.result.items?.find(i => i.uuid === item.uuid);
741+
if (contextItem != null) {
742+
contextItem.viewer.pinned = false;
743+
optimisticallyUpdateItems(quickpick);
744+
}
745+
696746
await this.container.launchpad.unpin(item);
697747
break;
698-
748+
}
699749
case MergeQuickInputButton:
700750
this.sendItemActionTelemetry('merge', item, group, context);
701751
await this.container.launchpad.merge(item);

0 commit comments

Comments
 (0)