before leaderboard fetch
This commit is contained in:
parent
ea7c0501c8
commit
e63e22ba3e
58
app/page.tsx
58
app/page.tsx
|
|
@ -3,6 +3,8 @@
|
|||
import React, { useState, useEffect } from "react";
|
||||
import { SunIcon, MoonIcon } from "@heroicons/react/solid";
|
||||
import { PrivyProvider, usePrivy } from "@privy-io/react-auth";
|
||||
import { FaTwitter, FaWallet } from "react-icons/fa";
|
||||
import { CheckIcon } from "@heroicons/react/outline"; // For the check mark icon
|
||||
|
||||
// Helper functions to generate pseudo data
|
||||
const generateRandomName = () => {
|
||||
|
|
@ -35,9 +37,11 @@ const generateTableData = (rows) => {
|
|||
const tableData = generateTableData(10);
|
||||
|
||||
function Home() {
|
||||
const { login, user, ready, logout } = usePrivy();
|
||||
const { login, user, ready, logout, linkTwitter, unlinkTwitter } = usePrivy();
|
||||
const [darkMode, setDarkMode] = useState(true);
|
||||
|
||||
const [twitterConnected, setTwitterConnected] = useState(false); // State to track Twitter connection
|
||||
const [walletConnected, setWalletConnected] = useState(false); // State to track Wallet connection
|
||||
const [incrementNumber, setIncrementNumber] = useState(1);
|
||||
useEffect(() => {
|
||||
if (darkMode) {
|
||||
document.documentElement.classList.add("dark");
|
||||
|
|
@ -46,6 +50,13 @@ function Home() {
|
|||
}
|
||||
}, [darkMode]);
|
||||
|
||||
useEffect(() => {
|
||||
const intervalId = setInterval(() => {
|
||||
setIncrementNumber((prevNumber) => prevNumber + 1);
|
||||
}, 5000);
|
||||
return () => clearInterval(intervalId); // Clean up the interval on component unmount
|
||||
}, []);
|
||||
|
||||
const toggleDarkMode = () => {
|
||||
setDarkMode(!darkMode);
|
||||
document.documentElement.classList.toggle("dark", !darkMode);
|
||||
|
|
@ -53,7 +64,7 @@ function Home() {
|
|||
|
||||
const postLoginAPI = async (usertag) => {
|
||||
try {
|
||||
const response = await fetch('https://vps.playpoolstudios.com/callfi/register_twitter_user.php?tag='+usertag);
|
||||
const response = await fetch('https://vps.playpoolstudios.com/callfi/register_twitter_user.php?tag=' + usertag);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Network response was not ok');
|
||||
|
|
@ -61,6 +72,7 @@ function Home() {
|
|||
|
||||
const data = await response.json();
|
||||
console.log('API call successful:', data);
|
||||
setTwitterConnected(true); // Set Twitter connection state to true on successful API call
|
||||
} catch (error) {
|
||||
console.error('Error during API call:', error);
|
||||
}
|
||||
|
|
@ -68,11 +80,15 @@ function Home() {
|
|||
|
||||
useEffect(() => {
|
||||
if (ready && user) {
|
||||
// Assuming user object contains twitter handle at user.profile.twitter
|
||||
const username = user.twitter?.username ? `@${user.twitter.username}` : '@unknownUser';
|
||||
if(username != "@unknownUser"){
|
||||
if (username !== "@unknownUser") {
|
||||
postLoginAPI(username);
|
||||
}
|
||||
// Assume we have a way to check if the wallet is connected
|
||||
const walletStatus = user.wallet; // This is an assumption; replace it with actual wallet connection check
|
||||
if (walletStatus) {
|
||||
setWalletConnected(true);
|
||||
}
|
||||
}
|
||||
}, [ready, user]);
|
||||
|
||||
|
|
@ -84,17 +100,31 @@ function Home() {
|
|||
<button onClick={toggleDarkMode} className="bg-gray-700 hover:bg-gray-500 text-white font-bold py-2 px-4 rounded mr-2">
|
||||
{darkMode ? <SunIcon className="h-5 w-5 text-white" /> : <MoonIcon className="h-5 w-5 text-white" />}
|
||||
</button>
|
||||
{!ready ? (
|
||||
<p>Loading...</p>
|
||||
) : user ? (
|
||||
<button onClick={logout} className="bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-4 rounded">
|
||||
Logout
|
||||
<div className="flex items-center bg-white bg-opacity-20 rounded-full px-4 py-2">
|
||||
<button className={`relative ${twitterConnected ? "bg-black" : "bg-gray-700"} hover:bg-gray-500 text-white font-bold py-2 px-4 rounded-full mr-2`} onClick={linkTwitter }>
|
||||
<FaTwitter className="h-5 w-5 text-white" />
|
||||
{twitterConnected && (
|
||||
<CheckIcon className="absolute top-0 right-0 h-4 w-4 text-green-500" />
|
||||
)}
|
||||
</button>
|
||||
) : (
|
||||
<button onClick={login} className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
|
||||
Login
|
||||
<button className={`relative ${walletConnected ? "bg-black" : "bg-gray-700"} hover:bg-gray-500 text-white font-bold py-2 px-4 rounded-full mr-2`}>
|
||||
<FaWallet className="h-5 w-5 text-white" />
|
||||
{walletConnected && (
|
||||
<CheckIcon className="absolute top-0 right-0 h-4 w-4 text-green-500" />
|
||||
)}
|
||||
</button>
|
||||
)}
|
||||
{!ready ? (
|
||||
<p>Loading...</p>
|
||||
) : user ? (
|
||||
<button onClick={logout} className="bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-4 rounded">
|
||||
Logout
|
||||
</button>
|
||||
) : (
|
||||
<button onClick={login} className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
|
||||
Login
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<div className="flex-grow flex flex-col items-center justify-center w-full p-4">
|
||||
|
|
|
|||
9
package-lock.json
generated
9
package-lock.json
generated
|
|
@ -16,6 +16,7 @@
|
|||
"next": "14.2.4",
|
||||
"react": "^18",
|
||||
"react-dom": "^18",
|
||||
"react-icons": "^5.2.1",
|
||||
"tailwind-merge": "^2.3.0",
|
||||
"tailwindcss-animate": "^1.0.7"
|
||||
},
|
||||
|
|
@ -7421,6 +7422,14 @@
|
|||
"react": "^18.3.1"
|
||||
}
|
||||
},
|
||||
"node_modules/react-icons": {
|
||||
"version": "5.2.1",
|
||||
"resolved": "https://registry.npmjs.org/react-icons/-/react-icons-5.2.1.tgz",
|
||||
"integrity": "sha512-zdbW5GstTzXaVKvGSyTaBalt7HSfuK5ovrzlpyiWHAFXndXTdd/1hdDHI4xBM1Mn7YriT6aqESucFl9kEXzrdw==",
|
||||
"peerDependencies": {
|
||||
"react": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/react-is": {
|
||||
"version": "16.13.1",
|
||||
"resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz",
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
"next": "14.2.4",
|
||||
"react": "^18",
|
||||
"react-dom": "^18",
|
||||
"react-icons": "^5.2.1",
|
||||
"tailwind-merge": "^2.3.0",
|
||||
"tailwindcss-animate": "^1.0.7"
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user