mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 12:31:13 -05:00
Refactor admin blog access
This commit is contained in:
@@ -35,7 +35,7 @@ interface BlogPost {
|
||||
|
||||
export default function AdminBlog() {
|
||||
const { user } = useAuth();
|
||||
const { isModerator } = useUserRole();
|
||||
const { isAdmin, loading } = useUserRole();
|
||||
const navigate = useNavigate();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
@@ -48,11 +48,6 @@ export default function AdminBlog() {
|
||||
const [featuredImageId, setFeaturedImageId] = useState('');
|
||||
const [featuredImageUrl, setFeaturedImageUrl] = useState('');
|
||||
|
||||
if (!isModerator()) {
|
||||
navigate('/');
|
||||
return null;
|
||||
}
|
||||
|
||||
const { data: posts, isLoading } = useQuery({
|
||||
queryKey: ['admin-blog-posts'],
|
||||
queryFn: async () => {
|
||||
@@ -65,6 +60,26 @@ export default function AdminBlog() {
|
||||
},
|
||||
});
|
||||
|
||||
// Show loading state while checking permissions
|
||||
if (loading) {
|
||||
return (
|
||||
<AdminLayout>
|
||||
<div className="flex items-center justify-center min-h-[60vh]">
|
||||
<div className="text-center">
|
||||
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-primary mx-auto mb-4"></div>
|
||||
<p className="text-muted-foreground">Loading...</p>
|
||||
</div>
|
||||
</div>
|
||||
</AdminLayout>
|
||||
);
|
||||
}
|
||||
|
||||
// Redirect if not admin or superuser
|
||||
if (!isAdmin()) {
|
||||
navigate('/');
|
||||
return null;
|
||||
}
|
||||
|
||||
const saveMutation = useMutation({
|
||||
mutationFn: async ({ isDraft }: { isDraft: boolean }) => {
|
||||
const postData = {
|
||||
|
||||
Reference in New Issue
Block a user