Skip to content

Commit

Permalink
Create selection thumbs on create
Browse files Browse the repository at this point in the history
Loads original image every time; we may need to speed this up.
  • Loading branch information
inukshuk committed Nov 22, 2018
1 parent ef4c3dc commit bd5810b
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions src/commands/selection.js
Expand Up @@ -2,34 +2,37 @@

const { call, put, select } = require('redux-saga/effects')
const { Command } = require('./command')
const { ImportCommand } = require('./import')
const { Image } = require('../image')
const mod = require('../models')
const act = require('../actions')
const { SELECTION } = require('../constants')
const { pick, splice } = require('../common/util')
const { keys } = Object


class Create extends Command {
class Create extends ImportCommand {
static get ACTION() { return SELECTION.CREATE }

*exec() {
const { db } = this.options
const { payload, meta } = this.action
let { db } = this.options
let { payload, meta } = this.action

const idx = (meta.idx != null) ? meta.idx : [
yield select(state => state.photos[payload.photo].selections.length)
]
let photo = yield select(state => state.photos[payload.photo])
let image = yield call(Image.open, photo.path, photo.page)
let idx = (meta.idx != null) ? meta.idx : [photo.selections.length]

const selection = yield call(db.transaction, tx =>
let selection = yield call(db.transaction, tx =>
mod.selection.create(tx, null, payload))

const photo = selection.photo
const selections = [selection.id]
let data = { selections: [selection.id] }

yield put(act.photo.selections.add({ id: photo, selections }, { idx }))
yield* this.createThumbnails(selection.id, image, { selection })

yield put(act.photo.selections.add({ id: photo.id, ...data }, { idx }))

this.undo = act.selection.delete({ photo, selections }, { idx })
this.redo = act.selection.restore({ photo, selections }, { idx })
this.undo = act.selection.delete({ photo: photo.id, ...data }, { idx })
this.redo = act.selection.restore({ photo: photo.id, ...data }, { idx })

return selection
}
Expand All @@ -39,9 +42,9 @@ class Delete extends Command {
static get ACTION() { return SELECTION.DELETE }

*exec() {
const { db } = this.options
const { payload } = this.action
const { photo, selections } = payload
let { db } = this.options
let { payload } = this.action
let { photo, selections } = payload

let ord = yield select(({ photos }) => photos[photo].selections)
let idx = selections.map(id => ord.indexOf(id))
Expand Down

0 comments on commit bd5810b

Please sign in to comment.