This commit is contained in:
alma 2025-05-04 14:33:12 +02:00
parent bb3ad20c24
commit b7c16cab7d
3 changed files with 40 additions and 20 deletions

View File

@ -13,18 +13,17 @@ export async function GET(request: Request) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
} }
// Instead of making an HTTP request, directly call the handler function // For backward compatibility, just return the standard folders
// for the storage status endpoint // This ensures the sidebar always shows something
try { const standardFolders = ['Notes', 'Diary', 'Health', 'Contacts'];
const { GET: storageStatusHandler } = await import('@/app/api/storage/status/route');
const storageResponse = await storageStatusHandler(); console.log('NextCloud status adapter returning standard folders:', standardFolders);
return NextResponse.json({
status: 'ready',
folders: standardFolders
});
// Return the response
return storageResponse;
} catch (error) {
console.error('Error calling storage status handler:', error);
return NextResponse.json({ error: 'Failed to get storage status' }, { status: 500 });
}
} catch (error) { } catch (error) {
console.error('Error in NextCloud status adapter:', error); console.error('Error in NextCloud status adapter:', error);
return NextResponse.json({ error: 'Internal server error' }, { status: 500 }); return NextResponse.json({ error: 'Internal server error' }, { status: 500 });

View File

@ -72,6 +72,16 @@ export default function CarnetPage() {
// Cache for Nextcloud folders // Cache for Nextcloud folders
const foldersCache = useRef<{ folders: string[]; timestamp: number } | null>(null); const foldersCache = useRef<{ folders: string[]; timestamp: number } | null>(null);
// Clear folder cache on component mount to ensure fresh data
useEffect(() => {
try {
localStorage.removeItem('nextcloud_folders');
console.log('Cleared folder cache');
} catch (error) {
console.error('Error clearing folder cache:', error);
}
}, []);
useEffect(() => { useEffect(() => {
const fetchNextcloudFolders = async () => { const fetchNextcloudFolders = async () => {
// First check localStorage cache // First check localStorage cache

View File

@ -52,6 +52,11 @@ export default function Navigation({ nextcloudFolders, onFolderSelect }: Navigat
const [contactFiles, setContactFiles] = useState<ContactFile[]>([]); const [contactFiles, setContactFiles] = useState<ContactFile[]>([]);
const [isLoadingContacts, setIsLoadingContacts] = useState(false); const [isLoadingContacts, setIsLoadingContacts] = useState(false);
// Debug logging for folders
useEffect(() => {
console.log('Navigation folders received:', nextcloudFolders);
}, [nextcloudFolders]);
const getFolderIcon = (folder: string) => { const getFolderIcon = (folder: string) => {
switch (folder) { switch (folder) {
case 'Notes': case 'Notes':
@ -67,14 +72,20 @@ export default function Navigation({ nextcloudFolders, onFolderSelect }: Navigat
} }
}; };
// Make sure the sortedFolders logic can handle both empty arrays and other issues // Make sure we always have the standard folders available
const sortedFolders = nextcloudFolders && nextcloudFolders.length > 0 const defaultFolders = ['Notes', 'Diary', 'Health', 'Contacts'];
? [...nextcloudFolders].sort((a, b) => {
// Combine API-provided folders with defaults to ensure we always have folders to show
const allFolders = nextcloudFolders && nextcloudFolders.length > 0
? [...new Set([...nextcloudFolders])] // Remove duplicates
: defaultFolders;
// Sort folders according to the specified order
const sortedFolders = allFolders.sort((a, b) => {
const orderA = (FOLDER_CONFIG[a as FolderType]?.order) || 999; const orderA = (FOLDER_CONFIG[a as FolderType]?.order) || 999;
const orderB = (FOLDER_CONFIG[b as FolderType]?.order) || 999; const orderB = (FOLDER_CONFIG[b as FolderType]?.order) || 999;
return orderA - orderB; return orderA - orderB;
}) });
: ['Notes', 'Diary', 'Health', 'Contacts']; // Default folders if none returned from API
const fetchContactFiles = async () => { const fetchContactFiles = async () => {
try { try {