Skip to content

Commit 64dbd2b

Browse files
committed
fixup! Persist recent drafts in file
1 parent 79e9008 commit 64dbd2b

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

src/__tests__/models/DraftsStore.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import PlayerEvent from "../../models/PlayerEvent";
66
import ActionType from "../../constants/ActionType";
77
import Civilisation from "../../models/Civilisation";
88

9-
it('test get empty recent drafts', () => {
9+
it('test get empty ongoing drafts', () => {
1010
const draftsStore = new DraftsStore();
11-
expect(draftsStore.getRecentDrafts()).toEqual([]);
11+
expect(draftsStore.getOngoingDrafts()).toEqual([]);
1212
});
1313

1414
it('test do not get drafts without both connected players', () => {
1515
const draftsStore = new DraftsStore();
1616
draftsStore.createDraft('draftId', new Draft('nameHost', 'nameGuest', Preset.SIMPLE));
17-
expect(draftsStore.getRecentDrafts()).toEqual([]);
17+
expect(draftsStore.getOngoingDrafts()).toEqual([]);
1818
});
1919

2020
it('test get all eleven ongoing drafts', () => {

src/models/DraftsStore.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,24 @@ export class DraftsStore {
4747

4848

4949
public getRecentDrafts(): IRecentDraft[] {
50+
const ongoingDrafts = this.getOngoingDrafts();
51+
52+
const recentDrafts = DraftsStore.loadRecentDrafts();
53+
if (ongoingDrafts.length < 10) {
54+
const iterations = 10 - ongoingDrafts.length;
55+
for (let i = 0; i < iterations; i++) {
56+
if (recentDrafts.length > i) {
57+
ongoingDrafts.push(recentDrafts[i]);
58+
} else {
59+
break;
60+
}
61+
}
62+
}
63+
64+
return ongoingDrafts;
65+
}
66+
67+
getOngoingDrafts() {
5068
const ongoingDrafts: IRecentDraft[] = this.getDraftIds()
5169
.map((value: string) => {
5270
return {...this.getDraftOrThrow(value), draftId: value};
@@ -62,19 +80,6 @@ export class DraftsStore {
6280
nameGuest: draft.nameGuest,
6381
};
6482
});
65-
66-
const recentDrafts = DraftsStore.loadRecentDrafts();
67-
if (ongoingDrafts.length < 10) {
68-
const iterations = 10 - ongoingDrafts.length;
69-
for (let i = 0; i < iterations; i++) {
70-
if (recentDrafts.length > i) {
71-
ongoingDrafts.push(recentDrafts[i]);
72-
} else {
73-
break;
74-
}
75-
}
76-
}
77-
7883
return ongoingDrafts;
7984
}
8085

0 commit comments

Comments
 (0)