Skip to content

Commit af024a9

Browse files
committed
Turned components into pages and used router.push to render page
1 parent ae7c24b commit af024a9

File tree

7 files changed

+1146
-55
lines changed

7 files changed

+1146
-55
lines changed

src/components/settingComponents/generalPage.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { useEffect } from 'react';
1111

1212
export default function General(){
1313
const router = useRouter();
14+
1415
const [isPopupOpen, setIsPopupOpen] = useState(false);
1516
const [selectedImage, setSelectedImage] = useState(null);
1617

src/components/settingComponents/sidebar.jsx

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,39 @@
11
import Link from 'next/link';
2+
import { useRouter } from 'next/router'
23

34
export default function Sidebar(){
4-
5+
const router = useRouter()
56
return(
67
<div
78
className=" mt-10 flex-none border-r pl-10 pr-10 text-gray-900"
89
style={{ borderColor: '#212121' }}
910
>
1011
<ul className="mr-2 py-2">
1112
<li className="py-1">
12-
<Link
13-
href="../settings"
14-
className="px-2 py-2 text-lg font-medium text-white"
15-
16-
>
17-
{' '}
13+
<button className="px-2 py-1 text-lg font-medium text-white hover:text-gray-400"
14+
onClick={() =>router.push('../settings',null, { shallow: true })}>
1815
General
19-
</Link>
16+
</button>
2017
</li>
2118
<li className="py-1 ">
22-
<Link
23-
href="../settings?loc=security"
24-
className="px-2 py-1 text-lg font-medium text-white hover:text-gray-400"
25-
>
19+
20+
<button className="px-2 py-1 text-lg font-medium text-white hover:text-gray-400"
21+
onClick={() =>router.push('../settings/security',null, { shallow: true })}>
2622
Security
27-
</Link>
23+
</button>
2824
</li>
2925
<li className="py-1 ">
30-
<Link
31-
href="../settings?loc=preferences"
32-
className="px-2 py-1 text-lg font-medium text-white hover:text-gray-400"
33-
>
26+
<button className="px-2 py-1 text-lg font-medium text-white hover:text-gray-400"
27+
onClick={() =>router.push('../settings/preferences',null, { shallow: true })}>
3428
Email Preferences
35-
</Link>
29+
</button>
30+
3631
</li>
3732
<li className="py-1 ">
38-
<Link
39-
href="../settings?loc=billing"
40-
className="px-2 py-1 text-lg font-medium text-white hover:text-gray-400"
41-
>
33+
<button className="px-2 py-1 text-lg font-medium text-white hover:text-gray-400"
34+
onClick={() =>router.push('../settings/billing',null, { shallow: true })}>
4235
Billing
43-
</Link>
36+
</button>
4437
</li>
4538
</ul>
4639
</div>

src/pages/settings.jsx

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ import { useEffect } from 'react';
55
import { useState } from 'react';
66
import { getCookie } from '@/utils/request';
77
import General from '@/components/settingComponents/generalPage';
8-
import Security from '@/components/settingComponents/securityPage';
98
import Sidebar from '@/components/settingComponents/sidebar';
10-
import Billing from '@/components/settingComponents/billingPage';
11-
import Preferences from '@/components/settingComponents/preferencesPage';
9+
1210
import {
1311
updatePassword,
1412
getAuth,
@@ -38,11 +36,6 @@ export default function Dashboard() {
3836
const [billing, setbilling] = useState(false);
3937
const [username, setUsername] = useState('');
4038

41-
42-
const [selectedImage, setSelectedImage] = useState(null);
43-
const [isPopupOpen, setIsPopupOpen] = useState(false);
44-
const [pfp, setPfp] = useState(`https://robohash.org/KshitijIsCool.png?set=set1&size=150x150`);
45-
4639
var pfpString = '';
4740
var pfpChanged = false;
4841

@@ -165,7 +158,32 @@ export default function Dashboard() {
165158
}
166159
}
167160

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;
168183

184+
xhr.send(data);
185+
}
186+
169187
function loadPreferences() {
170188
// WARNING: For GET requests, body is set to null by browsers.
171189

@@ -218,34 +236,12 @@ export default function Dashboard() {
218236

219237
{general && (
220238
<div id="general" className="">
221-
{/*DIV CONTAINING THE BODY OF GENERAL SECTION*/}
239+
{/*CONTAINING THE BODY OF GENERAL SECTION*/}
222240
<General/>
223241
</div>
224242
)}
225243

226-
{billing && (
227-
<div id="general" className="">
228-
{/*DIV CONTAINING BODY OF THE BILLING SECTION*/}
229-
<Billing/>
230-
</div>
231-
)}
232-
233-
{security && (
234-
<div id="security" className="">
235-
{/*DIV CONTAINING BODY OF THE SECURITY SECTION*/}
236-
<Security/>
237-
</div>
238-
)}
239-
240-
241-
{preferences && (
242-
<div id="preferences" className="">
243-
244-
{/*DIV CONTAINING BODY OF THE PREFERENCES SECTION*/}
245-
<Preferences/>
246-
247-
</div>
248-
)}
244+
249245
</div>
250246

251247
<Footer />

0 commit comments

Comments
 (0)