feat(phase-b): school/timetable wizards, graph nav panel, UI updates
New components: - CCGraphNavPanel: Supabase-driven navigation tree (school/timetable/calendar/classes sections), role-aware setup buttons, lazy child loading, academic/generic calendar toggle - SchoolCalendarWizard: 3-step admin-only school setup (details → term dates → daily periods) - TeacherTimetableWizard: period grid with existing slot pre-loading, edit-mode title Updated: - CCNodeSnapshotPanel: saves via Supabase storage path + accessToken - BasePanel: nav panel tab wired to CCGraphNavPanel - CCFilesPanelEnhanced: auth context fixes - CCDocumentIntelligence suite: accessToken threading, Supabase storage integration Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import { Box, CircularProgress, MenuItem, Select, Typography } from '@mui/material';
|
||||
import { SelectChangeEvent } from '@mui/material/Select';
|
||||
import { supabase } from '../../../supabaseClient';
|
||||
import { useAuth } from '../../../contexts/AuthContext';
|
||||
|
||||
type Manifest = {
|
||||
bucket: string;
|
||||
@@ -41,6 +41,7 @@ export const CCBundleViewer: React.FC<{
|
||||
currentPage?: number;
|
||||
combinedBundles?: Array<{ id: string }>;
|
||||
}> = ({ fileId, bundleId, currentPage, combinedBundles }) => {
|
||||
const { accessToken } = useAuth();
|
||||
const [manifest, setManifest] = useState<Manifest | null>(null);
|
||||
const [combinedManifests, setCombinedManifests] = useState<Manifest[] | null>(null);
|
||||
const [mode, setMode] = useState<Mode>('markdown_full');
|
||||
@@ -53,9 +54,9 @@ export const CCBundleViewer: React.FC<{
|
||||
const API_BASE_FALLBACK = 'http://127.0.0.1:8080';
|
||||
|
||||
const proxyUrl = useCallback(async (bucket: string, relPath: string) => {
|
||||
const token = (await supabase.auth.getSession()).data.session?.access_token || '';
|
||||
const token = accessToken || '';
|
||||
return `${API_BASE}/database/files/proxy_signed?bucket=${encodeURIComponent(bucket)}&path=${encodeURIComponent(relPath)}&token=${encodeURIComponent(token)}`;
|
||||
}, [API_BASE]);
|
||||
}, [API_BASE, accessToken]);
|
||||
|
||||
const replaceAllSafe = useCallback((s: string, search: string, replacement: string) => {
|
||||
if (!s || typeof s !== 'string') return s || '';
|
||||
@@ -222,7 +223,7 @@ export const CCBundleViewer: React.FC<{
|
||||
setManifest(null);
|
||||
if (combinedBundles && combinedBundles.length > 0) {
|
||||
try {
|
||||
const token = (await supabase.auth.getSession()).data.session?.access_token || '';
|
||||
const token = accessToken || '';
|
||||
const ms: Manifest[] = [];
|
||||
for (const b of combinedBundles) {
|
||||
const res = await fetch(`${API_BASE}/database/files/${encodeURIComponent(fileId)}/artefacts/${encodeURIComponent(b.id)}/manifest`, { headers: { Authorization: `Bearer ${token}` } });
|
||||
@@ -239,7 +240,7 @@ export const CCBundleViewer: React.FC<{
|
||||
}
|
||||
if (!bundleId) return;
|
||||
try {
|
||||
const token = (await supabase.auth.getSession()).data.session?.access_token || '';
|
||||
const token = accessToken || '';
|
||||
const res = await fetch(`${API_BASE}/database/files/${encodeURIComponent(fileId)}/artefacts/${encodeURIComponent(bundleId)}/manifest`, { headers: { Authorization: `Bearer ${token}` } });
|
||||
if (!res.ok) throw new Error(await res.text());
|
||||
const rawManifest: Manifest = await res.json();
|
||||
@@ -266,7 +267,7 @@ export const CCBundleViewer: React.FC<{
|
||||
let textParts: string[] = [];
|
||||
let jsonParts: string[] = [];
|
||||
for (const m of combinedManifests) {
|
||||
const token = (await supabase.auth.getSession()).data.session?.access_token || '';
|
||||
const token = accessToken || '';
|
||||
let rel: string | undefined;
|
||||
if (mode === 'markdown_full') rel = m.markdown_full || m.html_full || m.text_full || m.json_full;
|
||||
else if (mode === 'html_full') rel = m.html_full || m.markdown_full || m.text_full || m.json_full;
|
||||
@@ -348,7 +349,7 @@ export const CCBundleViewer: React.FC<{
|
||||
relPath = rec?.path;
|
||||
}
|
||||
if (!relPath) { setContent(''); setLoading(false); return; }
|
||||
const token = (await supabase.auth.getSession()).data.session?.access_token || '';
|
||||
const token = accessToken || '';
|
||||
const url = await proxyUrl(bucket, relPath);
|
||||
let res = await fetch(url, { headers: { Authorization: `Bearer ${token}` } });
|
||||
if (!res.ok) throw new Error(await res.text());
|
||||
|
||||
@@ -2,7 +2,7 @@ import React, { useEffect, useMemo, useState } from 'react';
|
||||
import { Box, CircularProgress, IconButton } from '@mui/material';
|
||||
import ArrowBackIosNewIcon from '@mui/icons-material/ArrowBackIosNew';
|
||||
import ArrowForwardIosIcon from '@mui/icons-material/ArrowForwardIos';
|
||||
import { supabase } from '../../../supabaseClient';
|
||||
import { useAuth } from '../../../contexts/AuthContext';
|
||||
|
||||
type Artefact = { id: string; type: string; rel_path: string; created_at: string };
|
||||
|
||||
@@ -43,6 +43,7 @@ export const CCDoclingViewer: React.FC<{
|
||||
hideToolbar?: boolean;
|
||||
sectionRange?: { start: number; end: number };
|
||||
}> = ({ fileId, currentPage, onPageChange, onExtractedText, onTotalPagesChange, hideToolbar, sectionRange }) => {
|
||||
const { accessToken } = useAuth();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [images, setImages] = useState<Array<{ src: string; width?: number; height?: number }>>([]);
|
||||
@@ -184,7 +185,7 @@ export const CCDoclingViewer: React.FC<{
|
||||
const API_BASE = import.meta.env.VITE_API_BASE || (location.port.startsWith('517') ? 'http://127.0.0.1:8080' : '/api');
|
||||
try {
|
||||
const mRes = await fetch(`${API_BASE}/database/files/${encodeURIComponent(fileId)}/page-images/manifest`, {
|
||||
headers: { 'Authorization': `Bearer ${(await supabase.auth.getSession()).data.session?.access_token || ''}` }
|
||||
headers: { 'Authorization': `Bearer ${accessToken || ''}` }
|
||||
});
|
||||
if (mRes.ok) {
|
||||
const m: PageImagesManifest = await mRes.json();
|
||||
@@ -199,7 +200,7 @@ export const CCDoclingViewer: React.FC<{
|
||||
|
||||
// Legacy: Load artefacts for file to find docling JSON artefacts
|
||||
const artefactsRes = await fetch(`${import.meta.env.VITE_API_BASE || (location.port.startsWith('517') ? 'http://127.0.0.1:8080' : '/api')}/database/files/${encodeURIComponent(fileId)}/artefacts`, {
|
||||
headers: { 'Authorization': `Bearer ${(await supabase.auth.getSession()).data.session?.access_token || ''}` }
|
||||
headers: { 'Authorization': `Bearer ${accessToken || ''}` }
|
||||
});
|
||||
if (!artefactsRes.ok) throw new Error(await artefactsRes.text());
|
||||
const artefacts: Artefact[] = await artefactsRes.json();
|
||||
@@ -216,7 +217,7 @@ export const CCDoclingViewer: React.FC<{
|
||||
|
||||
// Download artefact JSON via backend (service-role) to avoid RLS issues
|
||||
const jsonRes = await fetch(`${API_BASE}/database/files/${encodeURIComponent(fileId)}/artefacts/${encodeURIComponent(target.id)}/json`, {
|
||||
headers: { 'Authorization': `Bearer ${(await supabase.auth.getSession()).data.session?.access_token || ''}` }
|
||||
headers: { 'Authorization': `Bearer ${accessToken || ''}` }
|
||||
});
|
||||
if (!jsonRes.ok) throw new Error(await jsonRes.text());
|
||||
const doc: DoclingJson = await jsonRes.json();
|
||||
@@ -267,7 +268,7 @@ export const CCDoclingViewer: React.FC<{
|
||||
setPageObjectUrl(cached);
|
||||
return;
|
||||
}
|
||||
const token = (await supabase.auth.getSession()).data.session?.access_token || '';
|
||||
const token = accessToken || '';
|
||||
let resp = await fetch(pageProxyUrl, { headers: { Authorization: `Bearer ${token}` } });
|
||||
if (!resp.ok && manifest) {
|
||||
// Fallback to thumbnail if the full image is not accessible yet
|
||||
@@ -369,6 +370,7 @@ export const CCDoclingViewer: React.FC<{
|
||||
export default CCDoclingViewer;
|
||||
|
||||
const ImageByProxy: React.FC<{ url: string; alt: string }> = ({ url, alt }) => {
|
||||
const { accessToken } = useAuth();
|
||||
const [blobUrl, setBlobUrl] = useState<string | undefined>(undefined);
|
||||
const [loading, setLoading] = useState<boolean>(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
@@ -376,7 +378,7 @@ const ImageByProxy: React.FC<{ url: string; alt: string }> = ({ url, alt }) => {
|
||||
let revoked: string | null = null;
|
||||
const load = async () => {
|
||||
try {
|
||||
const token = (await supabase.auth.getSession()).data.session?.access_token || '';
|
||||
const token = accessToken || '';
|
||||
const resp = await fetch(url, { headers: { Authorization: `Bearer ${token}` } });
|
||||
if (!resp.ok) throw new Error(`HTTP ${resp.status}`);
|
||||
const blob = await resp.blob();
|
||||
|
||||
@@ -6,7 +6,7 @@ import { SelectChangeEvent } from '@mui/material/Select';
|
||||
import { CCDoclingViewer } from './CCDoclingViewer.tsx';
|
||||
import CCEnhancedFilePanel from './CCEnhancedFilePanel.tsx';
|
||||
import CCBundleViewer from './CCBundleViewer.tsx';
|
||||
import { supabase } from '../../../supabaseClient';
|
||||
import { useAuth } from '../../../contexts/AuthContext';
|
||||
|
||||
type CanonicalDoclingConfig = {
|
||||
pipeline: 'standard' | 'vlm' | 'asr';
|
||||
@@ -46,6 +46,7 @@ export const CCDocumentIntelligence: React.FC = () => {
|
||||
const { fileId } = useParams<{ fileId: string }>();
|
||||
|
||||
const validFileId = useMemo(() => fileId || '', [fileId]);
|
||||
const { accessToken } = useAuth();
|
||||
const [page, setPage] = useState<number>(1);
|
||||
const [outlineOptions, setOutlineOptions] = useState<Array<{ id: string; title: string; start_page: number; end_page: number }>>([]);
|
||||
const [profile, setProfile] = useState<Profile>('default');
|
||||
@@ -148,7 +149,7 @@ export const CCDocumentIntelligence: React.FC = () => {
|
||||
const loadBundles = async () => {
|
||||
if (!validFileId) return;
|
||||
const API_BASE = import.meta.env.VITE_API_BASE || (location.port.startsWith('517') ? 'http://127.0.0.1:8080' : '/api');
|
||||
const token = (await supabase.auth.getSession()).data.session?.access_token || '';
|
||||
const token = accessToken || '';
|
||||
const res = await fetch(`${API_BASE}/database/files/${encodeURIComponent(validFileId)}/artefacts`, { headers: { Authorization: `Bearer ${token}` } });
|
||||
if (!res.ok) return;
|
||||
const arts: Artefact[] = await res.json();
|
||||
@@ -225,14 +226,14 @@ export const CCDocumentIntelligence: React.FC = () => {
|
||||
const API_BASE = import.meta.env.VITE_API_BASE || (location.port.startsWith('517') ? 'http://127.0.0.1:8080' : '/api');
|
||||
try {
|
||||
const artsRes = await fetch(`${API_BASE}/database/files/${encodeURIComponent(validFileId)}/artefacts`, {
|
||||
headers: { 'Authorization': `Bearer ${(await supabase.auth.getSession()).data.session?.access_token || ''}` }
|
||||
headers: { 'Authorization': `Bearer ${accessToken || ''}` }
|
||||
});
|
||||
if (!artsRes.ok) return;
|
||||
const arts: Array<{ id: string; type: string; rel_path?: string }> = await artsRes.json();
|
||||
const outlineArt = arts.find(a => a.type === 'document_outline_hierarchy');
|
||||
if (!outlineArt) return;
|
||||
const jsonRes = await fetch(`${API_BASE}/database/files/${encodeURIComponent(validFileId)}/artefacts/${encodeURIComponent(outlineArt.id)}/json`, {
|
||||
headers: { 'Authorization': `Bearer ${(await supabase.auth.getSession()).data.session?.access_token || ''}` }
|
||||
headers: { 'Authorization': `Bearer ${accessToken || ''}` }
|
||||
});
|
||||
if (!jsonRes.ok) return;
|
||||
const doc = await jsonRes.json();
|
||||
@@ -242,7 +243,7 @@ export const CCDocumentIntelligence: React.FC = () => {
|
||||
const splitArt = arts.find(a => a.type === 'split_map_json');
|
||||
if (splitArt) {
|
||||
const smRes = await fetch(`${API_BASE}/database/files/${encodeURIComponent(validFileId)}/artefacts/${encodeURIComponent(splitArt.id)}/json`, {
|
||||
headers: { 'Authorization': `Bearer ${(await supabase.auth.getSession()).data.session?.access_token || ''}` }
|
||||
headers: { 'Authorization': `Bearer ${accessToken || ''}` }
|
||||
});
|
||||
if (smRes.ok) {
|
||||
const sm = await smRes.json();
|
||||
@@ -486,7 +487,7 @@ export const CCDocumentIntelligence: React.FC = () => {
|
||||
try {
|
||||
setBusy(true);
|
||||
const API_BASE = import.meta.env.VITE_API_BASE || (location.port.startsWith('517') ? 'http://127.0.0.1:8080' : '/api');
|
||||
const token = (await supabase.auth.getSession()).data.session?.access_token || '';
|
||||
const token = accessToken || '';
|
||||
const body: CanonicalDoclingRequest = {
|
||||
use_split_map: selectedSectionId === 'full' ? autoSplit : false,
|
||||
config: {
|
||||
|
||||
@@ -11,7 +11,8 @@ import Schedule from '@mui/icons-material/Schedule';
|
||||
import Visibility from '@mui/icons-material/Visibility';
|
||||
import Psychology from '@mui/icons-material/Psychology';
|
||||
import Overview from '@mui/icons-material/Home';
|
||||
import { supabase } from '../../../supabaseClient';
|
||||
import CalendarViewMonth from '@mui/icons-material/CalendarViewMonth';
|
||||
import { useAuth } from '../../../contexts/AuthContext';
|
||||
|
||||
// Types
|
||||
type PageImagesManifest = {
|
||||
@@ -66,6 +67,7 @@ export const CCEnhancedFilePanel: React.FC<CCEnhancedFilePanelProps> = ({
|
||||
fileId, selectedPage, onSelectPage, currentSection
|
||||
}) => {
|
||||
// State
|
||||
const { accessToken } = useAuth();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [manifest, setManifest] = useState<PageImagesManifest | null>(null);
|
||||
@@ -94,7 +96,7 @@ export const CCEnhancedFilePanel: React.FC<CCEnhancedFilePanelProps> = ({
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const token = (await supabase.auth.getSession()).data.session?.access_token || '';
|
||||
const token = accessToken || '';
|
||||
|
||||
// Load page images manifest
|
||||
const manifestRes = await fetch(`${API_BASE}/database/files/${encodeURIComponent(fileId)}/page-images/manifest`, {
|
||||
@@ -198,7 +200,7 @@ export const CCEnhancedFilePanel: React.FC<CCEnhancedFilePanelProps> = ({
|
||||
|
||||
try {
|
||||
const url = `${API_BASE}/database/files/proxy?bucket=${encodeURIComponent(manifest.bucket || '')}&path=${encodeURIComponent(pageInfo.thumbnail_path)}`;
|
||||
const token = (await supabase.auth.getSession()).data.session?.access_token || '';
|
||||
const token = accessToken || '';
|
||||
const response = await fetch(url, { headers: { Authorization: `Bearer ${token}` } });
|
||||
|
||||
if (!response.ok) return undefined;
|
||||
|
||||
@@ -5,7 +5,7 @@ import ChevronRightIcon from '@mui/icons-material/ChevronRight';
|
||||
import ArrowBackIosNewIcon from '@mui/icons-material/ArrowBackIosNew';
|
||||
import ArrowForwardIosIcon from '@mui/icons-material/ArrowForwardIos';
|
||||
import AdminPanelSettingsIcon from '@mui/icons-material/AdminPanelSettings';
|
||||
import { supabase } from '../../../supabaseClient';
|
||||
import { useAuth } from '../../../contexts/AuthContext';
|
||||
|
||||
type PageImagesManifest = {
|
||||
version: number;
|
||||
@@ -54,6 +54,7 @@ export const CCFileDetailPanel: React.FC<{
|
||||
selectedPage: number;
|
||||
onSelectPage: (p: number) => void;
|
||||
}> = ({ fileId, selectedPage, onSelectPage }) => {
|
||||
const { accessToken } = useAuth();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [manifest, setManifest] = useState<PageImagesManifest | null>(null);
|
||||
@@ -73,7 +74,7 @@ export const CCFileDetailPanel: React.FC<{
|
||||
setError(null);
|
||||
try {
|
||||
const mRes = await fetch(`${API_BASE}/database/files/${encodeURIComponent(fileId)}/page-images/manifest`, {
|
||||
headers: { 'Authorization': `Bearer ${(await supabase.auth.getSession()).data.session?.access_token || ''}` }
|
||||
headers: { 'Authorization': `Bearer ${accessToken || ''}` }
|
||||
});
|
||||
if (!mRes.ok) throw new Error(await mRes.text());
|
||||
const m: PageImagesManifest = await mRes.json();
|
||||
@@ -82,14 +83,14 @@ export const CCFileDetailPanel: React.FC<{
|
||||
// Try to load outline structure artefact (for grouping only)
|
||||
try {
|
||||
const artsRes = await fetch(`${API_BASE}/database/files/${encodeURIComponent(fileId)}/artefacts`, {
|
||||
headers: { 'Authorization': `Bearer ${(await supabase.auth.getSession()).data.session?.access_token || ''}` }
|
||||
headers: { 'Authorization': `Bearer ${accessToken || ''}` }
|
||||
});
|
||||
if (artsRes.ok) {
|
||||
const arts: Array<{ id: string; type: string }> = await artsRes.json();
|
||||
const outlineArt = arts.find(a => a.type === 'document_outline_hierarchy');
|
||||
if (outlineArt) {
|
||||
const jsonRes = await fetch(`${API_BASE}/database/files/${encodeURIComponent(fileId)}/artefacts/${encodeURIComponent(outlineArt.id)}/json`, {
|
||||
headers: { 'Authorization': `Bearer ${(await supabase.auth.getSession()).data.session?.access_token || ''}` }
|
||||
headers: { 'Authorization': `Bearer ${accessToken || ''}` }
|
||||
});
|
||||
if (jsonRes.ok) {
|
||||
const outJson = await jsonRes.json();
|
||||
@@ -118,7 +119,7 @@ export const CCFileDetailPanel: React.FC<{
|
||||
const pg = manifest.page_images[idx];
|
||||
if (!pg) return undefined;
|
||||
const url = `${API_BASE}/database/files/proxy?bucket=${encodeURIComponent(manifest.bucket || '')}&path=${encodeURIComponent(pg.thumbnail_path)}`;
|
||||
const token = (await supabase.auth.getSession()).data.session?.access_token || '';
|
||||
const token = accessToken || '';
|
||||
const resp = await fetch(url, { headers: { Authorization: `Bearer ${token}` } });
|
||||
if (!resp.ok) return undefined;
|
||||
const blob = await resp.blob();
|
||||
@@ -150,7 +151,7 @@ export const CCFileDetailPanel: React.FC<{
|
||||
<IconButton size="small" onClick={async () => {
|
||||
try {
|
||||
setShowAdmin(true);
|
||||
const token = (await supabase.auth.getSession()).data.session?.access_token || '';
|
||||
const token = accessToken || '';
|
||||
const res = await fetch(`${API_BASE}/queue/queue/tasks/by-file/${encodeURIComponent(fileId)}`, { headers: { Authorization: `Bearer ${token}` } });
|
||||
const data = await res.json();
|
||||
setAdminData(data);
|
||||
|
||||
Reference in New Issue
Block a user