115
115
const username = localStorage . getItem ( 'username' ) ;
116
116
const textElements = document . querySelectorAll ( '.text' ) ;
117
117
const loggedIn = document . getElementById ( 'loggedIn' ) ;
118
- const tlogged = document . getElementById ( 'textForLogged' ) ;
118
+ const tlogged = document . getElementById ( 'hide' ) ;
119
+ const mainText = document . getElementById ( 'mainText' )
119
120
120
121
// Hide all elements with the class "text"
121
122
textElements . forEach ( function ( element ) {
122
123
element . style . display = 'none' ;
123
- } ) ;
124
-
124
+ } )
125
+ const res = await fetch ( `https://scratchgems.onrender.com/api/data/${ username } ` ) ;
126
+ if ( ! res . ok ) {
127
+ throw new Error ( 'Failed to fetch data' ) ;
128
+ }
129
+ const data = await res . json ( ) ;
130
+
125
131
// Show the welcome message
126
132
loggedIn . style . display = 'block' ;
127
133
loggedIn . textContent = `Welcome to your account, ${ username } !` ;
128
- tlogged . innerHTML = '<center><p>some stuff</p></center>' ;
134
+ tlogged . style . display = 'none' ;
135
+
136
+ if ( data && data . pendingorders !== undefined && data . completedorders !== undefined ) {
137
+ mainText . innerHTML = `
138
+ <p>Pending Orders: ${ data . pendingorders } </p>
139
+ <br>
140
+ <p>Completed Orders: ${ data . completedorders } </p>
141
+ <br>
142
+ ` ;
143
+ } else {
144
+ mainText . innerHTML = `<p>Error loading order data.</p>` ;
145
+ }
146
+
129
147
} else {
130
148
checkAuth ( ) ;
131
149
}
@@ -191,7 +209,9 @@ <h1>Scratch Authentication</h1>
191
209
< div id ="loggedIn " class ="header " style ="display: none; "> </ div >
192
210
193
211
<!-- Main Content -->
194
- < div id ="textForLogged " class ="text content ">
212
+ < div id ="mainText " class ="text content "> </ div >
213
+ < div id ="hide " class ="text content ">
214
+ < div class ="text content ">
195
215
< h2 > Welcome! Please log in to continue.</ h2 >
196
216
< button onclick ="registerScratchAuth() "> Sign In With ScratchAuth</ button >
197
217
< p id ="scratchMessage " class ="message " aria-live ="polite "> </ p >
@@ -218,5 +238,6 @@ <h2>Login Using APIAuth</h2>
218
238
< button > Having trouble signing in? Report an issue</ button >
219
239
</ a >
220
240
</ div >
241
+ </ div >
221
242
</ body >
222
243
</ html >
0 commit comments