(
session: GoalQueueSession,
input: { readonly goalId: string; readonly direction: GoalQueueMoveDirection },
)
| 111 | } |
| 112 | |
| 113 | export async function moveGoalQueueItem( |
| 114 | session: GoalQueueSession, |
| 115 | input: { readonly goalId: string; readonly direction: GoalQueueMoveDirection }, |
| 116 | ): Promise<GoalQueueSnapshot> { |
| 117 | return withQueueMutationLock(session, async () => { |
| 118 | const state = await readQueueFile(session); |
| 119 | const index = findGoalIndex(state, input.goalId); |
| 120 | const targetIndex = input.direction === 'up' ? index - 1 : index + 1; |
| 121 | if (targetIndex < 0 || targetIndex >= state.goals.length) { |
| 122 | return toSnapshot(state); |
| 123 | } |
| 124 | const goals = [...state.goals]; |
| 125 | const [goal] = goals.splice(index, 1); |
| 126 | goals.splice(targetIndex, 0, goal!); |
| 127 | const next: GoalQueueFile = { version: GOAL_QUEUE_VERSION, goals }; |
| 128 | await writeQueueFile(session, next); |
| 129 | return toSnapshot(next); |
| 130 | }); |
| 131 | } |
| 132 | |
| 133 | function goalQueuePath(session: GoalQueueSession): string { |
| 134 | const sessionDir = session.summary?.sessionDir; |
no test coverage detected