diff --git a/public/emoji/microphone.png b/public/emoji/microphone.png new file mode 100644 index 0000000..7018165 Binary files /dev/null and b/public/emoji/microphone.png differ diff --git a/public/emoji/standin_person.png b/public/emoji/standin_person.png deleted file mode 100644 index 4684c2b..0000000 Binary files a/public/emoji/standin_person.png and /dev/null differ diff --git a/public/emoji/walking.png b/public/emoji/walking.png new file mode 100644 index 0000000..56df032 Binary files /dev/null and b/public/emoji/walking.png differ diff --git a/public/emoji/writing-hand.png b/public/emoji/writing_hand.png similarity index 99% rename from public/emoji/writing-hand.png rename to public/emoji/writing_hand.png index 4359dd1..087b9dc 100644 Binary files a/public/emoji/writing-hand.png and b/public/emoji/writing_hand.png differ diff --git a/src/App.tsx b/src/App.tsx index 9a38626..5017dad 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -43,7 +43,7 @@ const AppContent: React.FC = () => { const handleOnboardClose = () => { setShowOnboardUserB(false); setShowOnboardUserN(false); - setCurrentTab("chats"); + // setCurrentTab("chats"); Commented out so it does not redirect to chats (due to new home) }; const getBackendUrl = (): string => { diff --git a/src/components/Home.tsx b/src/components/Home.tsx index 66989ae..41ab7bb 100644 --- a/src/components/Home.tsx +++ b/src/components/Home.tsx @@ -3,13 +3,48 @@ import HomeCard from "./HomeCard"; import {useUserContext} from "../utils/utils"; import logo from "../assets/logo_whitebackground.png"; +const backendUrl = import.meta.env.VITE_BACKEND_URL; + const Home: React.FC = () => { - const {user, setCurrentTab} = useUserContext(); + const {user, setCurrentTab, updateUserBalance} = useUserContext(); const balance = user.words ? user.words : 0; - const handleClaimClick = () => { - // Handle the claim button click - // Add endpoint to do post request -> talk with Daniils + const handleClaimClick = async () => { + const lastClaimTimestamp = localStorage.getItem("lastClaimTimestamp"); + const now = new Date().getTime(); + + if ( + lastClaimTimestamp && + now - parseInt(lastClaimTimestamp) < 24 * 60 * 60 * 1000 + ) { + alert("You can only claim points once every 24 hours."); + return; + } + + try { + const response = await fetch(`${backendUrl}/claim-daily-points`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + user_id: user.id, + points: 10, + }), + }); + + if (!response.ok) { + throw new Error("Network response was not ok"); + } + + const result = await response.json(); + console.log("Points successfully claimed:", result); + // Update user balance or handle the result accordingly + updateUserBalance(10); // Add points to user's balance + localStorage.setItem("lastClaimTimestamp", now.toString()); + } catch (error) { + console.error("Error claiming daily points:", error); + } }; const handleQuestClick = () => { diff --git a/src/components/Quest.tsx b/src/components/Quest.tsx index 5caf4e1..fd4e85d 100644 --- a/src/components/Quest.tsx +++ b/src/components/Quest.tsx @@ -16,21 +16,16 @@ const Quest: React.FC = () => {