Skip to content

Commit

Permalink
Merge pull request #90 from TON-42/lmangall/various-improvements-befo…
Browse files Browse the repository at this point in the history
…re-AMA

Various improvements before AMA
  • Loading branch information
lmangall authored Jul 23, 2024
2 parents f7b7409 + fd8215e commit f47abd4
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 23 deletions.
Binary file added public/emoji/microphone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed public/emoji/standin_person.png
Binary file not shown.
Binary file added public/emoji/walking.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
43 changes: 39 additions & 4 deletions src/components/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down
29 changes: 17 additions & 12 deletions src/components/Quest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,24 @@ const Quest: React.FC = () => {
<div className='flex flex-col p-4'>
{!showInitialQuest ? (
<>
<h1 className='text-4xl font-bold mb-8'>Quest</h1>
<Text className='font-medium mb-4'>
Quests for content creation coming soon!
</Text>
<h1 className='text-4xl font-bold mb-4'>Quests</h1>
<Text className='text-7xl mb-4'>🚀</Text>
<Text className='font-small mb-8'>
<br />
<br />
When Clients come to ChatPay with a request for a specific type of
When ChatGPT comes to ChatPay with a request for a specific type of
content, <br />
We will share it and you will be able to make even more money by
creating specific content for their needs.
we share it with you and you can earn some points by creating
specific content for their needs.
<br />
<br />
Just watch out our socials!
Watch out our socials for quests announcements!
<br />
</Text>
<div className='flex flex-col space-y-1'>
<CustomCard
header='Nice to meet you'
subheader='In this quest we want to know a little more about you'
points={1000}
iconSrc={photoUrl || "./emoji/standin_person.png"}
iconSrc={photoUrl || "./emoji/walking.png"}
buttonText='Go'
buttonMode='filled'
buttonOnClick={handleOpenFirstQuest}
Expand All @@ -48,7 +43,17 @@ const Quest: React.FC = () => {
header='Crypto know'
subheader='This quest is coming soon. Check back later!'
points={3400}
iconSrc='./emoji/writing-hand.png'
iconSrc='./emoji/writing_hand.png'
buttonText='Go'
buttonMode='filled'
isActive={false}
buttonOnClick={() => {}}
/>
<CustomCard
header='Audio'
subheader='This quest is coming soon. Check back later!'
points={6800}
iconSrc='./emoji/microphone.png'
buttonText='Go'
buttonMode='filled'
isActive={false}
Expand Down
19 changes: 13 additions & 6 deletions src/components/Quests/01InitialQuest.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React, {useState} from "react";
import {Text, Input, Button} from "@telegram-apps/telegram-ui";
import {useUserContext} from "../../utils/utils";

const backendUrl = import.meta.env.VITE_BACKEND_URL;

const InitialQuest: React.FC = () => {
const {user, updateUserBalance} = useUserContext();
const [mothertongue, setMothertongue] = useState("");
const [age, setAge] = useState("");
const [languagesSpoken, setLanguagesSpoken] = useState("");
Expand Down Expand Up @@ -31,6 +33,8 @@ const InitialQuest: React.FC = () => {
},
body: JSON.stringify({
title: questTitle,
points: 1000,
user_id: user.id,
data: {
mothertongue,
age,
Expand All @@ -43,25 +47,28 @@ const InitialQuest: React.FC = () => {
if (!response.ok) {
throw new Error("Network response was not ok");
}
// Handle success response
const result = await response.json();
console.log("Data successfully submitted:", result);

// Update the user balance in the context
updateUserBalance(1000);
} catch (error) {
// Handle error response
// TODO: Handle error response => have to be enhanced with custom error
console.error("Error submitting data:", error);
}
};

return (
<div className='flex flex-col p-4'>
<h1 className='text-4xl font-bold mb-8'>{questTitle}</h1>
<h1 className='text-4xl font-bold mb-4'>{questTitle}</h1>
<Text className='font-medium mb-4'>
In this quest we want to know a little more about you
With this quest we are curious about you
</Text>
<Text className='text-7xl mb-4'>🚀</Text>
<Text className='font-small mb-4'>
These questions are mostly to create metadata on the content that you
will create <br />
These questions will help creating metadata on the content that you will
create in the later quests
<br />
</Text>
<div className='grid grid-cols-1 divide-y'>
<div className='py-4'>
Expand Down
8 changes: 8 additions & 0 deletions src/components/UserContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ const UserProvider: React.FC<{children: ReactNode}> = ({children}) => {
const [currentTab, setCurrentTab] = useState<string>("home");
const [error, setError] = useState<CustomError | null>(null);

const updateUserBalance = (points: number) => {
setUser(prevUser => ({
...prevUser,
words: (prevUser.words || 0) + points,
}));
};

useEffect(() => {
const fetchUserData = async () => {
try {
Expand Down Expand Up @@ -64,6 +71,7 @@ const UserProvider: React.FC<{children: ReactNode}> = ({children}) => {
setIsLoggedIn,
currentTab,
setCurrentTab,
updateUserBalance,
}}
>
{children}
Expand Down
1 change: 1 addition & 0 deletions src/stories/App.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const MockUserProvider: React.FC<UserProviderProps> = ({children}) => {
setIsLoggedIn,
currentTab,
setCurrentTab,
updateUserBalance: () => {},
}}
>
{children}
Expand Down
1 change: 1 addition & 0 deletions src/stories/Home.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const MockUserProvider: React.FC<UserProviderProps> = ({children}) => {
setIsLoggedIn,
currentTab,
setCurrentTab,
updateUserBalance: () => {},
}}
>
{children}
Expand Down
1 change: 1 addition & 0 deletions src/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export interface UserContextProps {
setIsLoggedIn: React.Dispatch<React.SetStateAction<boolean>>;
currentTab: string;
setCurrentTab: React.Dispatch<React.SetStateAction<string>>;
updateUserBalance: (points: number) => void;
}

// Define the TelegramUser interface with required Telegram-specific properties
Expand Down

0 comments on commit f47abd4

Please sign in to comment.