//static/js/api_calls.js let fake_local_session = { username: 'nobody' }; let fake_local_votesdata = [ { date: "2024-04-01", votes: { 'who': "yes", 'what': "no", }, }, { date: "2024-04-02", votes: { 'what': "no", 'when': "yes", 'where': "yes", }, }, { date: "2024-04-03", votes: { 'how': "no", 'random': Math.random() < 0.5 ? "no" : "yes", }, }, ] ////// This line, and everything above this line, should be deleted when you get the AJAX working. Really. async function getSessionFromBackend() { try { const response = await axios.get('/api/v1/getSession'); console.log(response.data) return response.data; } catch (error) { console.error('Error fetching session from backend:', error); return { success: false, data: null, error: error.toString() }; } } async function getVotesFromBackend() { try { const response = await axios.get('/api/v1/votes/list'); return response.data; } catch (error) { console.error('Error fetching votes from backend:', error); return { success: false, data: null, error: error.toString() }; } } async function setMyVote(day, vote) { // this is a placeholder. rewrite it completely. (you can ignore this for Pass tier) if (!fake_local_session) return false; let me = fake_local_session.username; let dayofvotes = fake_local_votesdata.filter(vd => vd.date === day)[0]; if (!me || !dayofvotes) return false; if (vote === 'maybe') { delete dayofvotes.votes[me]; } else { dayofvotes.votes[me] = vote; } return { success: true }; } async function ajaxSignup(username, password) { try { const response = await axios.post('/api/v1/signup', { username, password }); return response.data; } catch (error) { console.error('Error signing up:', error); return { success: false, error: error.toString() }; } } async function ajaxLogin(username, password) { try { const response = await axios.post('/api/v1/login', { username, password }); return response.data; } catch (error) { console.error('Error logging in:', error); return { success: false, error: error.toString() }; } } async function ajaxLogout() { try { const response = await axios.post('/api/v1/logout'); return response.data; } catch (error) { console.error('Error logging out:', error); return { success: false, error: error.toString() }; } }