Skip to content

Commit

Permalink
chore: Refactored thread reloading
Browse files Browse the repository at this point in the history
  • Loading branch information
spuxx1701 committed Jan 29, 2024
1 parent 1c03478 commit e856982
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
17 changes: 5 additions & 12 deletions app/components/nav/routes/thread/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,11 @@ export default class NavRoutesThreadComponent extends Component<Signature> {
reload = async () => {
this.renderer.showLoadingIndicator();
this.renderer.preventNextScrollReset();
this.threadStore.isReloading = true;
if (!this.currentPage) return;
this.threadStore
.loadThread(this.args.threadId, {
page: this.currentPage,
keepPreviousThread: true,
})
.finally(() => {
this.threadStore.isReloading = false;
this.renderer.hideLoadingIndicator();
this.renderer.waitAndScrollToBottom();
});
this.threadStore.reload().finally(() => {
this.threadStore.isReloading = false;
this.renderer.hideLoadingIndicator();
this.renderer.waitAndScrollToBottom();
});
};

handleGoToPage = () => {
Expand Down
2 changes: 1 addition & 1 deletion app/components/routes/thread/page/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default class ThreadPage extends Component<Signature> {
handleOverscroll = () => {
this.renderer.preventNextScrollReset();
this.renderer.showLoadingIndicator();
this.threadStore.refresh()?.finally(() => {
this.threadStore.reload()?.finally(() => {
this.renderer.hideLoadingIndicator();
this.renderer.waitAndScrollToBottom();
});
Expand Down
13 changes: 10 additions & 3 deletions app/services/stores/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,16 @@ export default class ThreadStore extends Service {
* Refreshes the currently loaded thread if there is one.
* @param options The options to pass to `loadThread`.
*/
refresh(options?: LoadThreadOptions) {
if (!this.currentThread) return;
return this.loadThread(this.currentThread.id, options);
async reload(options?: LoadThreadOptions) {
if (!this.currentThread || !this.currentThread.page) return;
this.isReloading = true;
const thread = await this.loadThread(this.currentThread.id, {
page: this.currentThread.page.number,
keepPreviousThread: true,
...options,
});
this.isReloading = false;
return thread;
}

/**
Expand Down

0 comments on commit e856982

Please sign in to comment.