Skip to content

Commit

Permalink
feat(home): sort current books by updated_at
Browse files Browse the repository at this point in the history
  • Loading branch information
isdenmois committed Nov 21, 2020
1 parent 9a58b0d commit 4b780ca
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/screens/home/home.queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export function booksReadForecast(read: number, total: number): number {
}

export function currentBooksQuery() {
return database.collections.get('books').query(Q.where('status', BOOK_STATUSES.NOW));
return database.collections
.get('books')
.query(Q.where('status', BOOK_STATUSES.NOW), Q.experimentalSortBy('updated_at', Q.asc));
}

export function wishBooksQuery() {
Expand Down
1 change: 1 addition & 0 deletions src/store/book.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export default class Book extends Model {
@field('audio') audio: boolean;
@field('leave') leave: boolean;
@readonly @date('created_at') createdAt: Date;
@readonly @date('updated_at') updatedAt: Date;

// @lazy authors = this.collections.get('authors').query(Q.on('book_authors', 'book_id', this.id));
@children('book_authors') bookAuthors;
Expand Down
9 changes: 9 additions & 0 deletions src/store/migrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,14 @@ export const migrations = schemaMigrations({
}),
],
},
{
toVersion: 7,
steps: [
addColumns({
table: 'books',
columns: [{ name: 'updated_at', type: 'number' }],
}),
],
},
],
});
3 changes: 2 additions & 1 deletion src/store/schema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { appSchema, tableSchema } from '@nozbe/watermelondb';

export const schema = appSchema({
version: 6,
version: 7,
tables: [
tableSchema({
name: 'books',
Expand All @@ -15,6 +15,7 @@ export const schema = appSchema({
{ name: 'type', type: 'string', isOptional: true },
{ name: 'search', type: 'string', isOptional: true },
{ name: 'created_at', type: 'number' },
{ name: 'updated_at', type: 'number' },
{ name: 'lid', type: 'string', isOptional: true },
{ name: 'paper', type: 'boolean', isOptional: true },
{ name: 'without_translation', type: 'boolean', isOptional: true },
Expand Down

0 comments on commit 4b780ca

Please sign in to comment.