Skip to content

Commit

Permalink
asdsdasd
Browse files Browse the repository at this point in the history
  • Loading branch information
lopatoj committed Sep 22, 2024
1 parent 19fb289 commit d6d19a1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
20 changes: 19 additions & 1 deletion client/src/modules/backend_functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@ async function setProfileBio(user: User, new_bio: string) {
})
}

async function getTodo(user: User) {
const starting_point = getStartingPoint();
const url = `${starting_point}/profile/todo?id_token=${encodeURIComponent(await user.getIdToken(true))}`
await fetch(url, {
method: "GET"
})
}

async function updateTodo(user: User, data: UserData) {
const starting_point = getStartingPoint();
const url = `${starting_point}/profile/todo?id_token=${encodeURIComponent(await user.getIdToken(true))}`
await fetch(url, {
method: "POST",
headers: {'Content-Type': "application/json"},
body: JSON.stringify(data.todo_list)
})
}

async function setProfileSignupStatus(user: User, open: boolean) {
const starting_point = getStartingPoint();
const url = `${starting_point}/profile/me?id_token=${encodeURIComponent(await user.getIdToken(true))}`
Expand Down Expand Up @@ -73,4 +91,4 @@ async function requestMatch(user: User)
return res.json();
}

export { getProfile, setProfileBio, getStartingPoint, getChat, setProfileSignupStatus, requestMatch }
export { getProfile, setProfileBio, getStartingPoint, getChat, setProfileSignupStatus, requestMatch, getTodo, updateTodo }
20 changes: 14 additions & 6 deletions client/src/pages/Todo/Todo.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "./Todo.css"
import { user_data_state } from "../../modules/states"
import { useEffect, useRef, useState } from "react"
import { useEffect, useState } from "react"
import { Button } from "react-bootstrap";

import Form from 'react-bootstrap/Form';
Expand All @@ -18,7 +18,7 @@ function TodoPage()
if (userData)
{
let cloned_todo = [...(userData.todo_list||[])]
cloned_todo.sort((a, b) => {
cloned_todo = cloned_todo.sort((a, b) => {
return a.timestamp-b.timestamp
})
setTodoList(cloned_todo)
Expand All @@ -38,7 +38,13 @@ function TodoPage()

const new_data: UserData = JSON.parse(JSON.stringify(userData))
new_data.todo_list.push(new_task)
setUserData(new_data)
setUserData(new_data);
}

function done(index: number) {
const new_data: UserData = JSON.parse(JSON.stringify(userData));
new_data.todo_list[index].completed = true;
setUserData(new_data);
}

return <div>
Expand All @@ -62,9 +68,11 @@ function TodoPage()
</Form.Group>
</Form>
<Button variant="success" onClick={addTask}>Add Task</Button>
{todoList.map(todo => {
return <div>

{todoList.map((todo, index) => {
return <div key={index}>
{todo.title}
{todo.completed ? "Done" : "Not Done"}
<Button onClick={() => done(index)}></Button>
</div>
})}
</div>
Expand Down

0 comments on commit d6d19a1

Please sign in to comment.