Fix "Next" button ordering

This commit is contained in:
Timothy Farrell 2018-01-08 21:48:03 -06:00
parent 4a478b2442
commit 3b9fb3ea19
2 changed files with 16 additions and 7 deletions

View File

@ -107,13 +107,10 @@ export function FocusView(vm, params) {
} }
doc(await ImageType.find(_id)); doc(await ImageType.find(_id));
Promise.all([ const n = await ImageType.next(_id);
ImageType.find({ _id: { $lt: _id } }, { limit: 2, sort: [{ _id: 'desc' }] }), nextLink(n.length ? router.href('focus', { id: n[0].id }) : null);
ImageType.find({ _id: { $gt: _id } }, { limit: 2 }) const p = await ImageType.next(_id, true);
]).then(([prev, next]) => { prevLink(p.length ? router.href('focus', { id: p[0].id }) : null);
nextLink(next.length ? router.href('focus', { id: next[0]._id }) : null);
prevLink(prev.length ? router.href('focus', { id: prev[0]._id }) : null);
});
}) })
], ],
true true

View File

@ -148,6 +148,17 @@ export function PouchORM(PouchDB) {
} }
} }
async function next(key, previous = false, limit = 1, inclusive = false) {
const res = await _db.allDocs({
startkey: key,
descending: previous,
sort: ['id'],
skip: inclusive ? 0 : 1,
limit
});
return res.rows;
}
Object.defineProperties(cls.prototype, { Object.defineProperties(cls.prototype, {
_name: { value: name }, _name: { value: name },
_prefix: { value: prefix }, _prefix: { value: prefix },
@ -159,6 +170,7 @@ export function PouchORM(PouchDB) {
Object.defineProperties(cls, { Object.defineProperties(cls, {
getOrCreate: { value: getOrCreate }, getOrCreate: { value: getOrCreate },
find: { value: find }, find: { value: find },
next: { value: next },
delete: { value: _delete }, delete: { value: _delete },
subscribe: { value: watch }, subscribe: { value: watch },
db: { value: _db }, db: { value: _db },