@@ -17,7 +17,7 @@ async function getReplId(username, slug) {
1717export 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