55 queuedRunEditBlockedReason ,
66} from "@t3tools/client-runtime/queued-run-edit" ;
77import { scopeThreadRef } from "@t3tools/client-runtime/environment" ;
8+ import { beforeRunIdForQueuedMove } from "@t3tools/client-runtime/state/thread-workflows" ;
89import { resolveUserMessagePresentation } from "@t3tools/client-runtime/user-message" ;
910import type { ChatAttachment , EnvironmentId , RunId , ThreadId } from "@t3tools/contracts" ;
1011import { Atom } from "effect/reactivity" ;
@@ -40,6 +41,7 @@ import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
4041import {
4142 REMOVE_QUEUED_MESSAGE_ACCESSIBILITY_LABEL ,
4243 buildCancelQueuedRunCommand ,
44+ buildReorderQueuedRunCommand ,
4345 resolveThreadQueueRowControls ,
4446} from "./threadQueueControlPresentation" ;
4547
@@ -51,7 +53,7 @@ const EMPTY_QUEUED_COUNT_ATOM = Atom.make(0).pipe(
5153) ;
5254
5355type QueueTarget = { readonly environmentId : EnvironmentId ; readonly threadId : ThreadId } ;
54- type QueueAction = "steer" | "edit" | "remove" ;
56+ type QueueAction = "steer" | "edit" | "remove" | "move-up" | "move-down" ;
5557
5658function useThreadQueueWorkflow ( target : QueueTarget ) {
5759 return useAtomValue ( environmentThreadDetails . queueWorkflowAtom ( target ) ) ;
@@ -134,6 +136,7 @@ export function ThreadQueueSheet({ route }: StaticScreenProps<QueueTarget>) {
134136 } ) ;
135137 const promote = useAtomCommand ( threadEnvironment . promoteQueuedRun , "promote queued message" ) ;
136138 const cancel = useAtomCommand ( threadEnvironment . cancelQueuedRun , "remove queued message" ) ;
139+ const reorder = useAtomCommand ( threadEnvironment . reorderQueuedRun , "reorder queued message" ) ;
137140 const resume = useAtomCommand ( threadEnvironment . resumeThreadQueue , "resume queue" ) ;
138141 const [ resuming , setResuming ] = useState ( false ) ;
139142 const [ busyRunId , setBusyRunId ] = useState < RunId | null > ( null ) ;
@@ -179,12 +182,34 @@ export function ThreadQueueSheet({ route }: StaticScreenProps<QueueTarget>) {
179182 navigation . goBack ( ) ;
180183 return ;
181184 }
182- if ( action !== "steer" && action !== "remove" ) return ;
185+ if (
186+ action !== "steer" &&
187+ action !== "remove" &&
188+ action !== "move-up" &&
189+ action !== "move-down"
190+ ) {
191+ return ;
192+ }
183193 busyRef . current = true ;
184194 setBusyRunId ( runId ) ;
185195 void Haptics . selectionAsync ( ) ;
186196 if ( action === "remove" ) {
187197 await cancel ( buildCancelQueuedRunCommand ( { ...target , runId } ) ) ;
198+ } else if ( action === "move-up" || action === "move-down" ) {
199+ const toIndex = action === "move-up" ? index - 1 : index + 1 ;
200+ if ( toIndex >= 0 && toIndex < queuedRuns . length ) {
201+ await reorder (
202+ buildReorderQueuedRunCommand ( {
203+ ...target ,
204+ runId,
205+ beforeRunId : beforeRunIdForQueuedMove ( {
206+ orderedRunIds : queuedRuns . map ( ( { run } ) => run . id ) ,
207+ runId,
208+ toIndex,
209+ } ) ,
210+ } ) ,
211+ ) ;
212+ }
188213 } else if ( workflow ?. canSendNow ) {
189214 await resume ( { ...target , input : { threadId : target . threadId , runId } } ) ;
190215 } else if ( workflow ?. activeRun && workflow . canPromoteToSteer ) {
@@ -241,8 +266,10 @@ export function ThreadQueueSheet({ route }: StaticScreenProps<QueueTarget>) {
241266 canPromoteToSteer : workflow ?. canPromoteToSteer ?? false ,
242267 canSendNow : workflow ?. canSendNow ?? false ,
243268 editBlocked : editBlockedReason !== null ,
269+ index,
244270 isEditing : editing ?. runId === run . id ,
245271 isGuestMessage : context ?. guest !== undefined ,
272+ queueLength : queuedRuns . length ,
246273 text,
247274 } ) ;
248275 const title =
@@ -270,6 +297,22 @@ export function ThreadQueueSheet({ route }: StaticScreenProps<QueueTarget>) {
270297 } ,
271298 ]
272299 : [ ] ) ,
300+ ...( queuedRuns . length > 1
301+ ? [
302+ {
303+ id : "move-up" ,
304+ title : "Move up" ,
305+ attributes : { disabled : ! controls . canMoveUp } ,
306+ image : Platform . OS === "ios" ? "arrow.up" : "arrow_upward" ,
307+ } ,
308+ {
309+ id : "move-down" ,
310+ title : "Move down" ,
311+ attributes : { disabled : ! controls . canMoveDown } ,
312+ image : Platform . OS === "ios" ? "arrow.down" : "arrow_downward" ,
313+ } ,
314+ ]
315+ : [ ] ) ,
273316 {
274317 id : "edit" ,
275318 title : "Edit" ,
0 commit comments