Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Internalize algorithm updates in the new room list store #4951

Merged
merged 1 commit into from
Jul 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/stores/room-list/RoomListStore2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,14 @@ export class RoomListStore2 extends AsyncStore<ActionPayload> {
}

public async setTagSorting(tagId: TagID, sort: SortAlgorithm) {
await this.setAndPersistTagSorting(tagId, sort);
this.updateFn.trigger();
}

private async setAndPersistTagSorting(tagId: TagID, sort: SortAlgorithm) {
await this.algorithm.setTagSorting(tagId, sort);
// TODO: Per-account? https://github.com/vector-im/riot-web/issues/14114
localStorage.setItem(`mx_tagSort_${tagId}`, sort);
this.updateFn.triggerIfWillMark();
}

public getTagSorting(tagId: TagID): SortAlgorithm {
Expand Down Expand Up @@ -407,10 +411,14 @@ export class RoomListStore2 extends AsyncStore<ActionPayload> {
}

public async setListOrder(tagId: TagID, order: ListAlgorithm) {
await this.setAndPersistListOrder(tagId, order);
this.updateFn.trigger();
}

private async setAndPersistListOrder(tagId: TagID, order: ListAlgorithm) {
await this.algorithm.setListOrdering(tagId, order);
// TODO: Per-account? https://github.com/vector-im/riot-web/issues/14114
localStorage.setItem(`mx_listOrder_${tagId}`, order);
this.updateFn.triggerIfWillMark();
}

public getListOrder(tagId: TagID): ListAlgorithm {
Expand Down Expand Up @@ -458,10 +466,10 @@ export class RoomListStore2 extends AsyncStore<ActionPayload> {
const listOrder = this.calculateListOrder(tag);

if (tagSort !== definedSort) {
await this.setTagSorting(tag, tagSort);
await this.setAndPersistTagSorting(tag, tagSort);
}
if (listOrder !== definedOrder) {
await this.setListOrder(tag, listOrder);
await this.setAndPersistListOrder(tag, listOrder);
}
}
}
Expand Down
11 changes: 0 additions & 11 deletions src/utils/MarkedExecution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,4 @@ export class MarkedExecution {
this.reset(); // reset first just in case the fn() causes a trigger()
this.fn();
}

/**
* Triggers the function if a mark() call would mark it. If the function
* has already been marked this will do nothing.
*/
public triggerIfWillMark() {
if (!this.marked) {
this.mark();
this.trigger();
}
}
}