Skip to content

Commit

Permalink
Adding a minimum loading time
Browse files Browse the repository at this point in the history
  • Loading branch information
ostyn committed Jan 1, 2025
1 parent 995f49d commit 3745d4e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/routes/entries.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import '../components/entry.component';
import '../components/month-control.component';
import { entryDao } from '../dao/EntryDao';
import { Entry } from '../interfaces/entry.interface';
import { timer } from '../utils/Helpers';
import { go } from './route-config';

@customElement('entries-route')
Expand Down Expand Up @@ -79,11 +80,15 @@ export class EntriesRoute extends LitElement implements WebComponentInterface {
);
this.scrollToDate = undefined;
}
// Wait at least 500ms
const [_, entries] = await Promise.all([
timer(500),
entryDao.getEntriesFromYearAndMonth(
this.currentDate.getFullYear(),
this.currentDate.getMonth() + 1
),
]);

const entries = await entryDao.getEntriesFromYearAndMonth(
this.currentDate.getFullYear(),
this.currentDate.getMonth() + 1
);
this.isLoading = false;
this.filteredEntries = [...entries];
};
Expand Down
3 changes: 3 additions & 0 deletions src/utils/Helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,6 @@ export enum Events {
monthSelect = 'monthSelect',
viewChange = 'viewChange',
}
export function timer(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}

0 comments on commit 3745d4e

Please sign in to comment.