Spaces:
Sleeping
Sleeping
Upload client/src/pages/Slides.tsx with huggingface_hub
Browse files
client/src/pages/Slides.tsx
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
import React, { useEffect, useState } from 'react';
|
| 2 |
-
import { useNavigate } from 'react-router-dom';
|
| 3 |
import { api } from '../services/api';
|
| 4 |
|
| 5 |
type SlideItem = {
|
|
@@ -11,7 +10,6 @@ type SlideItem = {
|
|
| 11 |
};
|
| 12 |
|
| 13 |
const Slides: React.FC = () => {
|
| 14 |
-
const navigate = useNavigate();
|
| 15 |
const [allowed, setAllowed] = useState<boolean>(false);
|
| 16 |
const [items, setItems] = useState<SlideItem[]>([]);
|
| 17 |
const [error, setError] = useState<string>('');
|
|
@@ -20,14 +18,13 @@ const Slides: React.FC = () => {
|
|
| 20 |
const [editing, setEditing] = useState<SlideItem & { id?: string } | null>(null);
|
| 21 |
|
| 22 |
useEffect(() => {
|
| 23 |
-
// Access gate:
|
| 24 |
-
const token = localStorage.getItem('token');
|
| 25 |
let role = 'visitor';
|
| 26 |
try { const u = localStorage.getItem('user'); role = u ? (JSON.parse(u).role || 'visitor') : 'visitor'; } catch {}
|
| 27 |
-
const ok =
|
| 28 |
setAllowed(ok);
|
| 29 |
if (!ok) {
|
| 30 |
-
|
| 31 |
return;
|
| 32 |
}
|
| 33 |
let aborted = false;
|
|
@@ -50,7 +47,7 @@ const Slides: React.FC = () => {
|
|
| 50 |
}
|
| 51 |
})();
|
| 52 |
return () => { aborted = true; };
|
| 53 |
-
}, [
|
| 54 |
|
| 55 |
if (!allowed) return null;
|
| 56 |
return (
|
|
|
|
| 1 |
import React, { useEffect, useState } from 'react';
|
|
|
|
| 2 |
import { api } from '../services/api';
|
| 3 |
|
| 4 |
type SlideItem = {
|
|
|
|
| 10 |
};
|
| 11 |
|
| 12 |
const Slides: React.FC = () => {
|
|
|
|
| 13 |
const [allowed, setAllowed] = useState<boolean>(false);
|
| 14 |
const [items, setItems] = useState<SlideItem[]>([]);
|
| 15 |
const [error, setError] = useState<string>('');
|
|
|
|
| 18 |
const [editing, setEditing] = useState<SlideItem & { id?: string } | null>(null);
|
| 19 |
|
| 20 |
useEffect(() => {
|
| 21 |
+
// Access gate: allow only student/admin; do not redirect visitors
|
|
|
|
| 22 |
let role = 'visitor';
|
| 23 |
try { const u = localStorage.getItem('user'); role = u ? (JSON.parse(u).role || 'visitor') : 'visitor'; } catch {}
|
| 24 |
+
const ok = role === 'student' || role === 'admin';
|
| 25 |
setAllowed(ok);
|
| 26 |
if (!ok) {
|
| 27 |
+
setLoading(false);
|
| 28 |
return;
|
| 29 |
}
|
| 30 |
let aborted = false;
|
|
|
|
| 47 |
}
|
| 48 |
})();
|
| 49 |
return () => { aborted = true; };
|
| 50 |
+
}, []);
|
| 51 |
|
| 52 |
if (!allowed) return null;
|
| 53 |
return (
|