File tree Expand file tree Collapse file tree 3 files changed +32
-26
lines changed Expand file tree Collapse file tree 3 files changed +32
-26
lines changed Original file line number Diff line number Diff line change @@ -158,31 +158,6 @@ export default function Dashboard() {
158158 }
159159 }
160160
161- function savePreferences ( ) {
162- document . getElementById ( 'savePreferences' ) . innerHTML = 'Saving...' ;
163-
164- var data = JSON . stringify ( {
165- FRIEND_ACCEPT : document . getElementById ( 'friend-notif' ) . checked ,
166- CHALLENGE_VERIFY : document . getElementById ( 'challenge-notif' ) . checked ,
167- } ) ;
168-
169- var xhr = new XMLHttpRequest ( ) ;
170-
171- xhr . addEventListener ( 'readystatechange' , function ( ) {
172- if ( this . readyState === 4 ) {
173- document . getElementById ( 'savePreferences' ) . innerHTML = 'Save' ;
174- }
175- } ) ;
176-
177- xhr . open ( 'PUT' , `${ process . env . NEXT_PUBLIC_API_URL } /account/preferences` ) ;
178-
179- xhr . setRequestHeader ( 'Content-Type' , 'application/json' ) ;
180- let token = getCookie ( ) ;
181- xhr . setRequestHeader ( 'Authorization' , 'Bearer ' + token ) ;
182- xhr . withCredentials = true ;
183-
184- xhr . send ( data ) ;
185- }
186161
187162 function loadPreferences ( ) {
188163 // WARNING: For GET requests, body is set to null by browsers.
Original file line number Diff line number Diff line change @@ -26,7 +26,9 @@ export default function General(){
2626 const [ pfp , setPfp ] = useState ( `https://robohash.org/KshitijIsCool.png?set=set1&size=150x150` ) ;
2727 const [ open , setOpen ] = useState ( true ) ;
2828
29-
29+ var pfpString = '' ;
30+ var pfpChanged = false ;
31+
3032 function pfpChange ( ) {
3133 pfpChanged = true ;
3234 }
Original file line number Diff line number Diff line change @@ -4,6 +4,35 @@ import { Footer } from '@/components/Footer';
44import { StandardNav } from '@/components/StandardNav' ;
55import Sidebar from '@/components/settingComponents/sidebar' ;
66export default function Preferences ( ) {
7+ function loadPreferences ( ) {
8+ // WARNING: For GET requests, body is set to null by browsers.
9+
10+ var xhr = new XMLHttpRequest ( ) ;
11+
12+ xhr . addEventListener ( 'readystatechange' , function ( ) {
13+ if ( this . readyState === 4 ) {
14+ console . log ( this . responseText ) ;
15+ console . log ( 'PREFFF' ) ;
16+ try {
17+ if ( JSON . parse ( this . responseText ) [ 0 ] . value == true ) {
18+ document . getElementById ( 'friend-notif' ) . checked = true ;
19+ }
20+
21+ if ( JSON . parse ( this . responseText ) [ 1 ] . value == true ) {
22+ document . getElementById ( 'challenge-notif' ) . checked = true ;
23+ }
24+ } catch ( error ) {
25+ // .alert(error)
26+ }
27+ }
28+ } ) ;
29+
30+ xhr . open ( 'GET' , `${ process . env . NEXT_PUBLIC_API_URL } /account/preferences` ) ;
31+ let token = getCookie ( ) ;
32+ xhr . setRequestHeader ( 'Authorization' , 'Bearer ' + token ) ;
33+ xhr . withCredentials = true ;
34+ xhr . send ( ) ;
35+ }
736
837 function savePreferences ( ) {
938 document . getElementById ( 'savePreferences' ) . innerHTML = 'Saving...' ;
You can’t perform that action at this time.
0 commit comments