Skip to content

Commit

Permalink
feat: Add reusable convertJobToFilenames()
Browse files Browse the repository at this point in the history
Signed-off-by: Michał Dziekoński <michal.dziekonski+github@gmail.com>
  • Loading branch information
mdziekon committed Dec 16, 2023
1 parent 828677c commit fd09c33
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/store/server/jobQueue/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ import { ActionTree } from 'vuex'
import { RootState } from '@/store/types'
import { ServerJobQueueState, ServerJobQueueStateJob } from '@/store/server/jobQueue/types'

const convertJobToFilenames = (job: ServerJobQueueStateJob) => {
const filenames: string[] = []

const count = (job.combinedIds?.length ?? 0) + 1
for (let i = 0; i < count; i++) {
filenames.push(job.filename)
}

return filenames
}

export const actions: ActionTree<ServerJobQueueState, RootState> = {
reset({ commit }) {
commit('reset')
Expand Down Expand Up @@ -41,10 +52,7 @@ export const actions: ActionTree<ServerJobQueueState, RootState> = {
return
}

const count = (job.combinedIds?.length ?? 0) + 1
for (let i = 0; i < count; i++) {
filenames.push(job.filename)
}
filenames.push(...convertJobToFilenames(job))
})

Vue.$socket.emit('server.job_queue.post_job', {
Expand All @@ -69,10 +77,7 @@ export const actions: ActionTree<ServerJobQueueState, RootState> = {
jobs.splice(payload.positionIndex, 0, jobToMove)

jobs.forEach((job) => {
const count = (job.combinedIds?.length ?? 0) + 1
for (let i = 0; i < count; i++) {
filenames.push(job.filename)
}
filenames.push(...convertJobToFilenames(job))
})

Vue.$socket.emit('server.job_queue.post_job', {
Expand Down

0 comments on commit fd09c33

Please sign in to comment.