Spaces:
Running
Running
Commit
·
c1d2ac2
1
Parent(s):
bc246eb
login check, better auto play
Browse files
src/components/about-tab.tsx
CHANGED
@@ -10,9 +10,9 @@ export default function AboutTab() {
|
|
10 |
<div className="space-y-6">
|
11 |
<Card>
|
12 |
<CardHeader>
|
13 |
-
<CardTitle className="text-2xl">About
|
14 |
<CardDescription>
|
15 |
-
|
16 |
</CardDescription>
|
17 |
</CardHeader>
|
18 |
<CardContent className="space-y-4">
|
|
|
10 |
<div className="space-y-6">
|
11 |
<Card>
|
12 |
<CardHeader>
|
13 |
+
<CardTitle className="text-2xl">About WikiRacing</CardTitle>
|
14 |
<CardDescription>
|
15 |
+
Navigate from one Wikipedia article to another using only hyperlinks
|
16 |
</CardDescription>
|
17 |
</CardHeader>
|
18 |
<CardContent className="space-y-4">
|
src/components/game-component.tsx
CHANGED
@@ -113,7 +113,7 @@ export default function GameComponent({
|
|
113 |
"playing"
|
114 |
);
|
115 |
const [continuousPlay, setContinuousPlay] = useState<boolean>(false);
|
116 |
-
const [autoRunning, setAutoRunning] = useState<boolean>(
|
117 |
|
118 |
const [convo, setConvo] = useState<Message[]>([]);
|
119 |
const [expandedMessages, setExpandedMessages] = useState<Record<number, boolean>>({});
|
|
|
113 |
"playing"
|
114 |
);
|
115 |
const [continuousPlay, setContinuousPlay] = useState<boolean>(false);
|
116 |
+
const [autoRunning, setAutoRunning] = useState<boolean>(false);
|
117 |
|
118 |
const [convo, setConvo] = useState<Message[]>([]);
|
119 |
const [expandedMessages, setExpandedMessages] = useState<Record<number, boolean>>({});
|
src/components/play-tab.tsx
CHANGED
@@ -48,6 +48,7 @@ export default function PlayTab({
|
|
48 |
const [maxTokens, setMaxTokens] = useState<number>(3000);
|
49 |
const [maxLinks, setMaxLinks] = useState<number>(200);
|
50 |
const [isServerConnected, setIsServerConnected] = useState<boolean>(false);
|
|
|
51 |
const [modelList, setModelList] = useState<
|
52 |
{
|
53 |
id: string;
|
@@ -78,6 +79,34 @@ export default function PlayTab({
|
|
78 |
return () => clearInterval(interval);
|
79 |
}, []);
|
80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
useEffect(() => {
|
82 |
const fetchAllArticles = async () => {
|
83 |
const response = await fetch(`${API_BASE}/get_all_articles`);
|
@@ -306,14 +335,30 @@ export default function PlayTab({
|
|
306 |
</Card>
|
307 |
|
308 |
<div className="flex justify-center">
|
309 |
-
<
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
317 |
</div>
|
318 |
|
319 |
{!isServerConnected && (
|
|
|
48 |
const [maxTokens, setMaxTokens] = useState<number>(3000);
|
49 |
const [maxLinks, setMaxLinks] = useState<number>(200);
|
50 |
const [isServerConnected, setIsServerConnected] = useState<boolean>(false);
|
51 |
+
const [isAuthenticated, setIsAuthenticated] = useState<boolean>(false);
|
52 |
const [modelList, setModelList] = useState<
|
53 |
{
|
54 |
id: string;
|
|
|
79 |
return () => clearInterval(interval);
|
80 |
}, []);
|
81 |
|
82 |
+
// Authentication check
|
83 |
+
useEffect(() => {
|
84 |
+
const checkAuthentication = () => {
|
85 |
+
const idToken = window.localStorage.getItem("huggingface_id_token");
|
86 |
+
const accessToken = window.localStorage.getItem("huggingface_access_token");
|
87 |
+
|
88 |
+
if (idToken && accessToken) {
|
89 |
+
try {
|
90 |
+
const idTokenObject = JSON.parse(idToken);
|
91 |
+
if (idTokenObject.exp > Date.now() / 1000) {
|
92 |
+
setIsAuthenticated(true);
|
93 |
+
return;
|
94 |
+
}
|
95 |
+
} catch (error) {
|
96 |
+
console.error("Error parsing ID token:", error);
|
97 |
+
}
|
98 |
+
}
|
99 |
+
setIsAuthenticated(false);
|
100 |
+
};
|
101 |
+
|
102 |
+
checkAuthentication();
|
103 |
+
window.addEventListener("storage", checkAuthentication);
|
104 |
+
|
105 |
+
return () => {
|
106 |
+
window.removeEventListener("storage", checkAuthentication);
|
107 |
+
};
|
108 |
+
}, []);
|
109 |
+
|
110 |
useEffect(() => {
|
111 |
const fetchAllArticles = async () => {
|
112 |
const response = await fetch(`${API_BASE}/get_all_articles`);
|
|
|
335 |
</Card>
|
336 |
|
337 |
<div className="flex justify-center">
|
338 |
+
<TooltipProvider>
|
339 |
+
<Tooltip>
|
340 |
+
<TooltipTrigger asChild>
|
341 |
+
<div>
|
342 |
+
<Button
|
343 |
+
onClick={handleStartGame}
|
344 |
+
size="lg"
|
345 |
+
className="px-8"
|
346 |
+
variant="default"
|
347 |
+
disabled={!isAuthenticated && player === "model"}
|
348 |
+
>
|
349 |
+
Start Game
|
350 |
+
</Button>
|
351 |
+
</div>
|
352 |
+
</TooltipTrigger>
|
353 |
+
{!isAuthenticated && player === "model" && (
|
354 |
+
<TooltipContent>
|
355 |
+
<p className="max-w-xs">
|
356 |
+
Please sign in with Hugging Face to play the game
|
357 |
+
</p>
|
358 |
+
</TooltipContent>
|
359 |
+
)}
|
360 |
+
</Tooltip>
|
361 |
+
</TooltipProvider>
|
362 |
</div>
|
363 |
|
364 |
{!isServerConnected && (
|