Initial commit: Memind H5 portal with MindSpace, Plaza, and agent jobs.
Track application source and tests; exclude local env, user workspaces, and runtime data via .gitignore. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import { matchPath, useLocation, useNavigate, useSearchParams } from 'react-router-dom';
|
||||
import { MindSpaceView } from '../components/MindSpaceView';
|
||||
import type { MindSpaceSaveCategory, PortalUser } from '../types';
|
||||
|
||||
const CATEGORY_CODES = new Set<MindSpaceSaveCategory>(['draft', 'oa', 'private', 'public']);
|
||||
|
||||
function parseCategory(value: string | null): MindSpaceSaveCategory | null {
|
||||
if (!value || !CATEGORY_CODES.has(value as MindSpaceSaveCategory)) return null;
|
||||
return value as MindSpaceSaveCategory;
|
||||
}
|
||||
|
||||
export function MindSpaceRoute({
|
||||
user,
|
||||
onLogout,
|
||||
}: {
|
||||
user: PortalUser;
|
||||
onLogout: () => void;
|
||||
}) {
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
const [searchParams] = useSearchParams();
|
||||
const pageMatch = matchPath('/space/page/:pageId', location.pathname);
|
||||
const pageId = pageMatch?.params.pageId ?? null;
|
||||
const categoryCode = parseCategory(searchParams.get('category'));
|
||||
|
||||
return (
|
||||
<MindSpaceView
|
||||
user={user}
|
||||
initialPageId={pageId}
|
||||
initialCategoryCode={categoryCode}
|
||||
onBack={() => navigate('/')}
|
||||
onLogout={onLogout}
|
||||
routeSync={{
|
||||
pushHome: () => navigate('/space'),
|
||||
pushCategory: (code) => navigate(`/space?category=${code}`),
|
||||
pushPage: (id) => navigate(`/space/page/${id}`),
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { Navigate } from 'react-router-dom';
|
||||
import type { PortalUser } from '../types';
|
||||
|
||||
export function RequireAdmin({
|
||||
user,
|
||||
children,
|
||||
}: {
|
||||
user: PortalUser | null;
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
if (user?.role !== 'admin') {
|
||||
return <Navigate to="/" replace />;
|
||||
}
|
||||
return children;
|
||||
}
|
||||
Reference in New Issue
Block a user