@@ -136,6 +136,26 @@ export class ThreadPinReorderUnsupportedError extends Schema.TaggedErrorClass<Th
136136 }
137137}
138138
139+ export async function requestThreadUnpinConfirmation ( input : {
140+ enabled : boolean ;
141+ title : string ;
142+ confirm : ( ( message : string ) => Promise < boolean > ) | null ;
143+ } ) {
144+ const { confirm } = input ;
145+ if ( ! input . enabled || confirm === null ) {
146+ return AsyncResult . success ( true ) ;
147+ }
148+
149+ return settlePromise ( ( ) =>
150+ confirm (
151+ [
152+ `Unpin thread "${ input . title } "?` ,
153+ "This will move the thread out of your pinned section." ,
154+ ] . join ( "\n" ) ,
155+ ) ,
156+ ) ;
157+ }
158+
139159export function useThreadActions ( ) {
140160 const closeTerminal = useAtomCommand ( terminalEnvironment . close ) ;
141161 const archiveThreadMutation = useAtomCommand ( threadEnvironment . archive , {
@@ -177,6 +197,7 @@ export function useThreadActions() {
177197 } ) ;
178198 const sidebarThreadSortOrder = useClientSettings ( ( settings ) => settings . sidebarThreadSortOrder ) ;
179199 const confirmThreadDelete = useClientSettings ( ( settings ) => settings . confirmThreadDelete ) ;
200+ const confirmThreadUnpin = useClientSettings ( ( settings ) => settings . confirmThreadUnpin ) ;
180201 const clearComposerDraftForThread = useComposerDraftStore ( ( store ) => store . clearDraftThread ) ;
181202 const clearProjectDraftThreadById = useComposerDraftStore (
182203 ( store ) => store . clearProjectDraftThreadById ,
@@ -590,6 +611,26 @@ export function useThreadActions() {
590611 [ unpinThreadMutation ] ,
591612 ) ;
592613
614+ const confirmAndUnpinThread = useCallback (
615+ async ( target : ScopedThreadRef ) => {
616+ const localApi = readLocalApi ( ) ;
617+ const resolved = resolveThreadTarget ( target ) ;
618+ const confirmationResult = await requestThreadUnpinConfirmation ( {
619+ enabled : confirmThreadUnpin ,
620+ title : resolved ?. thread . title ?? "this thread" ,
621+ confirm : localApi ? ( message ) => localApi . dialogs . confirm ( message ) : null ,
622+ } ) ;
623+ if ( confirmationResult . _tag === "Failure" ) {
624+ return confirmationResult ;
625+ }
626+ if ( ! confirmationResult . value ) {
627+ return AsyncResult . success ( undefined ) ;
628+ }
629+ return unpinThread ( target ) ;
630+ } ,
631+ [ confirmThreadUnpin , resolveThreadTarget , unpinThread ] ,
632+ ) ;
633+
593634 const reorderPinnedThread = useCallback (
594635 async ( target : ScopedThreadRef , orderKey : string ) => {
595636 // Callers (the sidebar drag handler) only enable dragging on
@@ -709,11 +750,13 @@ export function useThreadActions() {
709750 unsnoozeThread,
710751 pinThread,
711752 unpinThread,
753+ confirmAndUnpinThread,
712754 reorderPinnedThread,
713755 } ) ,
714756 [
715757 archiveThread ,
716758 confirmAndDeleteThread ,
759+ confirmAndUnpinThread ,
717760 deleteThread ,
718761 pinThread ,
719762 reorderPinnedThread ,
0 commit comments