Skip to content
This repository has been archived by the owner on Dec 16, 2024. It is now read-only.

Commit

Permalink
various bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
NickWang8 committed Dec 1, 2024
1 parent 17af57c commit abfaa45
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 45 deletions.
82 changes: 49 additions & 33 deletions src/pages/Availability.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default function Availability() {
dataToUse['password'] = userPW;
} else {
if (guestEmail !== null && guestPW !== null) {
dataToUse['guest_id'] = guestEmail;
dataToUse['guest_id'] = parseInt(guestEmail);
dataToUse['guest_password'] = guestPW;
} else {
try {
Expand All @@ -84,8 +84,12 @@ export default function Availability() {
);
if (response.ok) {
const responseData = await response.json();
dataToUse['guest_id'] = responseData.guest_id;
dataToUse['guest_id'] = parseInt(responseData.guest_id);
dataToUse['guest_password'] = responseData.guest_password;
const guestEmailCookie = `guest_email=${encodeURIComponent(JSON.stringify(responseData.guest_id))}; path=/;`;
const guestPasswordCookie = `guest_password=${encodeURIComponent(JSON.stringify(responseData.guest_password))}; path=/;`;
document.cookie = guestEmailCookie;
document.cookie = guestPasswordCookie;
} else {
console.error(
'Failed to make guest:',
Expand All @@ -101,38 +105,49 @@ export default function Availability() {
};

useEffect(() => {
if (eventCode) {
const data = {
// email: '[email protected]',
// password: '123',
event_code: eventCode,
};

// console.log(data);
check_user(data);
// console.log(data);
// return;
fetch('http://tomeeto.cs.rpi.edu:8000/event_details', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
})
.then((response) => response.json())
.then((data) => {
// Assuming the data from /event_details contains 'days' and 'start_time'
console.log('Event details:', data);

// Update the state based on the event details
setEventDetails(data);
updateEventData(data); // Call function to update days and hours
})
.catch((error) => {
console.error('Error fetching event details:', error);
async function handleEventDetails() {
try {
const data = {
// email: '[email protected]',
// password: '123',
event_code: eventCode,
};

console.log('Before user check:', data);

// Wait for check_user to complete
await check_user(data);

console.log('After user check:', data);

// Proceed with fetch after check_user completes
const response = await fetch('http://tomeeto.cs.rpi.edu:8000/event_details', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
});

if (!response.ok) {
throw new Error('Failed to fetch event details');
}

const eventData = await response.json();
console.log('Event details:', eventData);

// Update state based on the event details
setEventDetails(eventData);
updateEventData(eventData);
} catch (error) {
console.error('Error:', error);
}
}

if (eventCode) {
handleEventDetails(); // Call the async function
}
}, [eventCode]);
}, [eventCode]);

const updateEventData = (data) => {
const {
Expand Down Expand Up @@ -339,6 +354,7 @@ export default function Availability() {
};

if (isUpdating === true) {
console.log("UPDATINGGGGGGGGGGGGGGGGGGGG");
console.log(availability);

check_user(credentials);
Expand Down Expand Up @@ -373,7 +389,7 @@ export default function Availability() {
console.error('Error:', error);
}
} else {
// console.log('Ran');
console.log('Ran this random thing');
// console.log(name);
// console.log(availability);

Expand Down
2 changes: 1 addition & 1 deletion src/pages/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export default function Dashboard() {
onClick={() => handleCopyLink(event)}
className="px-4 py-2 bg-green-500 text-white rounded-md"
>
Copy Link
Copy Event Code
</button>
<button
onClick={() => handleEditEvent(event)}
Expand Down
1 change: 1 addition & 0 deletions src/pages/Landing.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default function Landing() {
onChange={(e) => setCode(e.target.value)}
onKeyDown={(e) => {
if (e.key === 'Enter') {
document.cookie = `code=${encodeURIComponent(JSON.stringify(e.target.value))}; path=/;`;
navigate('/availability', { state: { code: e.target.value } });
}
}}
Expand Down
13 changes: 2 additions & 11 deletions src/pages/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,12 @@ export default function Login() {
if (cookieObj['login_email'] && cookieObj['login_password']) {
data['email'] = cookieObj['login_email'];
data['password'] = cookieObj['login_password'];
const emailCookie = `guest_email=${encodeURIComponent(JSON.stringify(cookieObj['login_email']))}; path=/;`;
const passwordCookie = `guest_password=${encodeURIComponent(JSON.stringify(cookieObj['login_password']))}; path=/;`;
document.cookie = emailCookie;
document.cookie = passwordCookie;
} else if (cookieObj['guest_email'] && cookieObj['guest_password']) {
data['guest_id'] = parseInt(cookieObj['guest_email']);
data['guest_password'] = cookieObj['guest_password'];
const guestEmailCookie = `guest_email=${encodeURIComponent(JSON.stringify(cookieObj['guest_email']))}; path=/;`;
const guestPasswordCookie = `guest_password=${encodeURIComponent(JSON.stringify(cookieObj['guest_password']))}; path=/;`;
document.cookie = guestEmailCookie;
document.cookie = guestPasswordCookie;
} else {
console.log('Ran');
data['guest_id'] = parseInt(email.email);
data['guest_password'] = passwordValues.password;
data['email'] = email.email;
data['password'] = passwordValues.password;
const emailCookie = `login_email=${encodeURIComponent(JSON.stringify(email.email))}; path=/;`;
const passwordCookie = `login_password=${encodeURIComponent(JSON.stringify(passwordValues.password))}; path=/;`;
document.cookie = emailCookie;
Expand Down

0 comments on commit abfaa45

Please sign in to comment.