Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b416e5f

Browse files
ulemonsUmberto Sgueglia
and
Umberto Sgueglia
authored
handling pagination in getting the sketches (#875)
Co-authored-by: Umberto Sgueglia <umberto.sgueglia@external.fcagroup.com>
1 parent bfe6835 commit b416e5f

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

‎arduino-ide-extension/src/browser/create/create-api.ts‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,29 @@ export class CreateApi {
100100
return result;
101101
}
102102

103-
async sketches(): Promise<Create.Sketch[]> {
103+
async sketches(limit=50): Promise<Create.Sketch[]> {
104104
const url = new URL(`${this.domain()}/sketches`);
105105
url.searchParams.set('user_id', 'me');
106+
url.searchParams.set('limit', limit.toString());
106107
const headers = await this.headers();
107-
const result = await this.run<{ sketches: Create.Sketch[] }>(url, {
108-
method: 'GET',
109-
headers,
110-
});
108+
const result: { sketches: Create.Sketch[] } = { sketches: [] };
109+
110+
let partialSketches: Create.Sketch[] = [];
111+
let currentOffset = 0;
112+
do {
113+
url.searchParams.set('offset', currentOffset.toString());
114+
partialSketches = (
115+
await this.run<{ sketches: Create.Sketch[] }>(url, {
116+
method: 'GET',
117+
headers,
118+
})
119+
).sketches;
120+
if (partialSketches.length != 0) {
121+
result.sketches = result.sketches.concat(partialSketches);
122+
}
123+
currentOffset = currentOffset + limit;
124+
} while (partialSketches.length != 0);
125+
111126
result.sketches.forEach((sketch) => this.sketchCache.addSketch(sketch));
112127
return result.sketches;
113128
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /