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

Commit 5b427c2

Browse files
author
Ray Arayilakath
committed
Added newRepls query to Repl Class
1 parent d920431 commit 5b427c2

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

src/classes/Repl.js

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ async function getReplId(username, slug) {
1717
export default class Repl {
1818
constructor(username, slug) {
1919
this.username = username;
20-
this.slug = slug.replace(/ /g, '-');
20+
if (this.slug) this.slug = slug.replace(/ /g, '-');
2121
}
2222

2323
async replGraphQLData() {
@@ -29,13 +29,13 @@ export default class Repl {
2929
headers,
3030
body: JSON.stringify({
3131
query: `
32-
query Repl($id: String!) {
33-
repl(id: $id) {
34-
... on Repl {
35-
${constants.replAttributes}
36-
}
32+
query Repl($id: String!) {
33+
repl(id: $id) {
34+
... on Repl {
35+
${constants.replAttributes}
3736
}
38-
}`,
37+
}
38+
}`,
3939
variables: JSON.stringify({
4040
id,
4141
}),
@@ -94,9 +94,29 @@ export default class Repl {
9494
query: '{ replTitle }',
9595
}),
9696
}).then((res) => res.json());
97-
97+
9898
if (info.errors) throw new Error(`Replit GraphQL Error(s): ${JSON.stringify(info.errors)}`);
9999
else return info.data.replTitle;
100100
}
101101
}
102+
103+
async recentRepls() {
104+
const info = await fetch(constants.graphql, {
105+
method: 'POST',
106+
headers,
107+
body: JSON.stringify({
108+
query: `
109+
query newRepls {
110+
newRepls {
111+
items {
112+
${constants.replAttributes}
113+
}
114+
}
115+
}`,
116+
}),
117+
}).then((res) => res.json());
118+
119+
if (info.errors) throw new Error(`Replit GraphQL Error(s): ${JSON.stringify(info.errors)}`);
120+
else return info.data.newRepls.items;
121+
}
102122
}

0 commit comments

Comments
 (0)